我用php-fpm和cron任务运行php在nginx后面到php二进制文件(/ usr/bin/php).
我发现了一个不一致 - 当我通过php二进制文件和通过fpm运行它时,相同的脚本会输出不同的结果.
注意这仅适用于PHP7.在另一台服务器上,我用5.6测试了它,结果是一样的.
这是我发现的.以下脚本:
<?php
class Test {
public function test(){
$arr = (object) [
'children' => []
];
$arr->children[] = 1;
return $arr;
}
}
$o = new Test();
$o->test();
print_r( $o->test() );
Run Code Online (Sandbox Code Playgroud)
保存到test.php
.当我通过浏览器(php-fpm)运行它时,会产生:
stdClass Object
(
[children] => Array
(
[0] => 1
)
)
Run Code Online (Sandbox Code Playgroud)
但是当我从CLI执行它时,结果是不同的:
[root@server1 web]# php -f test.php
stdClass Object
(
[children] => Array
(
[0] => 1
[1] => 1
)
)
Run Code Online (Sandbox Code Playgroud)
没有(对象)强制转换就不会发生这种情况.另外,如果我要实例$arr
与new stdClass()
它不会发生.
好像$arr = (object)
是由php7的引擎保存在内存中.
也许这是一个配置问题.有没有人遇到它或可以解释?
谢谢.
归档时间: |
|
查看次数: |
2851 次 |
最近记录: |