【发布时间】:2011-12-11 01:50:21
【问题描述】:
我遇到了E_DEPRECATED 消息的一致性问题。
我有以下sn-p的代码可以在命令行运行来演示。
php -d error_reporting=-1 -d display_errors=1 -r 'function foo(&$bar) {return $bar->title . ".";} $bar = new stdClass(); $bar->title = "foobar";打印 foo(&$bar) 。 PHP_EOL 。 PHP_VERSION 。 PHP_EOL;'可读版本:
// error reporting set to E_ALL via command-line
function foo(&$bar) {
return $bar->title . ".";
}
$bar = new stdClass();
$bar->title = "foobar";
print foo(&$bar) . PHP_EOL . PHP_VERSION . PHP_EOL;
// ^ this should raise E_DEPRECATED
我正在尝试使用此 sn-p foo(&$bar) 触发 PHP Deprecated: Call-time pass-by-reference has been deprecated 消息,但由于某种原因,它没有在我的本地安装中引发。
我已经将它传递给其他几个运行各种版本的 php、不同的操作系统等的环境,并得到了不同的结果:
预期:
mike@server:~$ php -d error_reporting=-1 -d display_errors=1 -r 'function foo(&$bar) {return $bar->title . ".";} $bar = new stdClass(); $bar->title = "foobar";打印 foo(&$bar) 。 PHP_EOL 。 PHP_VERSION 。 PHP_EOL;' 不推荐使用 PHP:第 1 行的命令行代码中不推荐使用调用时传递引用 富吧。 5.3.5-1ubuntu7.2在我的环境中:
mike@local:~$ php -d error_reporting=-1 -d display_errors=1 -r 'function foo(&$bar) {return $bar->title . ".";} $bar = new stdClass(); $bar->title = "foobar";打印 foo(&$bar) 。 PHP_EOL 。 PHP_VERSION 。 PHP_EOL;' 富吧。 5.3.5-1ubuntu7.2这可能是什么原因造成的?
更新:
我执行了以下操作来验证我的环境中是否仍在抛出已弃用的错误:
mike@local:~$ php -d error_reporting=-1 -d display_errors=1 -r 'eregi("test", "test");' 已弃用:函数 eregi() 在第 1 行的命令行代码中已弃用【问题讨论】:
-
(tip)
error_reporting(-1)启用所有错误级别的报告。 -
@Gordon 很高兴知道!这对将来会有帮助。注意:我尝试更新我的命令以使用 error_reporting=-1 但得到了相同的结果。
-
php -d error_reporting=-1 -d display_errors=1 -r 'function f(&$b) {} f(&$c); var_dump(ini_get("error_reporting"), PHP_VERSION);'提供了什么? -
@salathe
string(2) "-1" string(16) "5.3.5-1ubuntu7.2"在我的机器上。但在其他人身上,它会抛出 Deprecated msg。另外,您的示例比我的示例要干净得多。介意我更新我的问题以使用它吗?
标签: php