php 5.2升级php7,[轻知识] Laravel 5.2 升级到 php7.2

[轻知识] Laravel 5.2 升级到 php7.2

升级到 php7.2

Laravel 5.2. 本地开发环境 php7.1, 线上 php7.0. 要把 php7.0 升级到 php7.2.

目前遇到的问题就是 each,count 这两个.

each 废弃

count 只能 countable type 的变量

以下是遇到一些小问题. 做个记录.

1. ModulesServiceProvider.PHP (这个是我自己的文件) The each() function is deprecated. This message will be suppressed on further callswhile(list(,$module)=each($modules)){

// Load the routes for each of the modules

if(file_exists(__DIR__.'/'.$module.'/routes.php')){

include __DIR__.'/'.$module.'/routes.php';

}

// Load the views

if(is_dir(__DIR__.'/'.$module.'/Views')){

$this->loadViewsFrom(__DIR__.'/'.$module.'/Views',$module);

}

}

PHP 7.2 废弃了 each .while(...each..) 改成 foreah 即可

修改为foreach($modulesas$module){

// Load the routes for each of the modules

if(file_exists(__DIR__.'/'.$module.'/routes.php')){

include __DIR__.'/'.$module.'/routes.php';

}

// Load the views

if(is_dir(__DIR__.'/'.$module.'/Views')){

$this->loadViewsFrom(__DIR__.'/'.$module.'/Views',$module);

}

}

2.ErrorExceptioninBuilder.PHP line772:

count():Parametermust be an arrayoranobjectthatimplementsCountable

问题定位到了. in Builder.PHP line 772

at HandleExceptions->handleError('2', 'count(): Parameter must be an array or an object that implements Countable', 'F:\iProject\afp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php', '772', array('query' => object(Builder), 'boolean' => 'and'))

问题源publicfunctionaddNestedWhereQuery($query,$boolean='and')

{

if(count($query->wheres)){

$type='Nested';

$this->wheres[]=compact('type','query','boolean');

$this->addBinding($query->getBindings(),'where');

}

return$this;

}

我打印

ab7653affab982b574eb7acc55df2e04.gif

修改为if($query->wheres!=NULL&&count($query->wheres)){

$type='Nested';

$this->wheres[]=compact('type','query','boolean');

$this->addBinding($query->getBindings(),'where');

}

但是这样就动了框架了. 我以为新框架会对这段做改变. 我之后下载了 Laravel 5.7 的框架. 这段代码没变.

3. 当我开始测脚本的时候$ APP_ENV="test"php72 artisanCategoryCron

count():Parametermust be an arrayoranobjectthatimplementsCountab

定位. 在处理异常的地方打印行数与文件int(67)

string(68)"F:\iProject\afp\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php"

找到代码publicfunctionrelease(EasyHandle$easy)

{

$resource=$easy->handle;

unset($easy->handle);

if(count($this->handles)>=$this->maxHandles){

curl_close($resource);

跟上面一样.$this->handles 为 null 所以才报错了. 兼容方式跟问题 2 一样.

参考:

*《PHP 7.2 一些注意事项.,php7.2 注意事项》 http://www.bkjia.com/PHPjc/1235440.html

*《从 PHP 7.1.x 移植到 PHP 7.2.x》 http://php.net/manual/zh/migration72.php 可以看官网文档了解下, 新特性以及兼容等等

来源: http://www.jianshu.com/p/1fd2df264c2e

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值