php 7.2 一些注意事项.

2018-01-20 20:18:41
<?php$b = array();each($b);// Deprecated:  The each() function is deprecated. This message will be suppressed on further calls

复制代码

each 函数 在php7.2已经设定为过时, 

<?phpcount('');// Warning:  count(): Parameter must be an array or an object that implements Countable

count 函数在php7.2将严格执行类型区分.  不正确的类型传入, 会引发一段警告. 

复制代码

<?php$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');echo "New anonymous function: $newfunc\n";echo $newfunc(2, M_E) . "\n";// outputs
// New anonymous function: lambda_1
// ln(2) + ln(2.718281828459) = 1.6931471805599

// Warning This function has been DEPRECATED as of PHP 7.2.0. Relying on this function is highly discouraged.

复制代码

create_function 函数在php7.2已经设定为过时.

 

-----------------------------------------------------------------------------------------------------------

解决方法: 

复制代码

function fun_adm_each(&$array){   $res = array();   $key = key($array);   if($key !== null){       next($array); 
       $res[1] = $res['value'] = $array[$key];       $res[0] = $res['key'] = $key;
   }else{       $res = false;
   }   return $res;
}

复制代码

替代each.

 

复制代码

function fun_adm_count($array_or_countable,$mode = COUNT_NORMAL){    if(is_array($array_or_countable) || is_object($array_or_countable)){        return count($array_or_countable, $mode);
    }else{        return 0;
    }
}

复制代码

替代count.

 

<?php    $fun = function ($str ){echo $str}    $fun('Yuan');

替代create_function. 

 

END

 


  • 2019-09-17 17:21:58

    Headless CMS 详细介绍

    什么是 Headless CMS? 为什么 Headless CMS 带有真正的革命性?因为它严格的将内容和格式分离,使我们回归到内容管理的本源。这种变化必然会带来一些不确定性。因此,在开始您的第一个 CMS 项目之前,了解 Headless CMS 概念至关重要。因为它和传统的 CMS 有着本质的区别。

  • 2019-09-19 09:07:46

    @Autowired用法详解

    在使用@Autowired时,首先在容器中查询对应类型的bean     如果查询结果刚好为一个,就将该bean装配给@Autowired指定的数据     如果查询的结果不止一个,那么@Autowired会根据名称来查找。     如果查询的结果为空,那么会抛出异常。解决方法时,使用required=false

  • 2019-09-19 11:36:58

    注解@Mapper、@MapperScan

    定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类

  • 2019-09-19 11:46:45

    @EnableConfigurationProperties注解详解,源码

    用springboot开发的过程中,我们会用到@ConfigurationProperties注解,主要是用来把properties或者yml配置文件转化为bean来使用的,而@EnableConfigurationProperties注解的作用是@ConfigurationProperties注解生效。 如果只配置@ConfigurationProperties注解,在IOC容器中是获取不到properties配置文件转化的bean的,当然在@ConfigurationProperties加入注解的类上加@Component也可以使交于springboot管理。

  • 2019-09-19 14:10:03

    Android UI布局优化之ViewStub介绍

    ViewStub的inflate只能被调用一次,第二次调用会抛出异常,setVisibility可以被调用多次,但不建议这么做(文章中说原因)