gpt4 book ai didi

php - 调用时按引用传递不会生成 E_DEPRECATED 错误

转载 作者:行者123 更新时间:2023-12-02 05:19:13 26 4
gpt4 key购买 nike

我遇到了 E_DEPRECATED 消息的一致性问题。

我有以下代码片段可以在命令行上运行以进行演示。

php -d error_reporting=-1 -d display_errors=1 -r 'function foo(&$bar) {return $bar->title . ".";} $bar = new stdClass(); $bar->title = "foobar"; print foo(&$bar) . PHP_EOL . PHP_VERSION . PHP_EOL;'

Readable version:

// 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

我正在尝试使用此代码段 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"; print foo(&$bar) . PHP_EOL . PHP_VERSION . PHP_EOL;'PHP Deprecated:  Call-time pass-by-reference has been deprecated in Command line code on line 1foobar.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"; print foo(&$bar) . PHP_EOL . PHP_VERSION . PHP_EOL;'foobar.5.3.5-1ubuntu7.2

这可能是什么原因造成的?

更新:

我执行了以下操作以验证我的环境中是否仍会抛出已弃用的错误:

mike@local:~$ php -d error_reporting=-1 -d display_errors=1 -r 'eregi("test", "test");'Deprecated: Function eregi() is deprecated in Command line code on line 1

最佳答案

有机会,是你的allow_call_time_pass_reference在 php.ini 中启用设置?

; This directive allows you to enable and disable warnings which PHP will issue; if you pass a value by reference at function call time. Passing values by; reference at function call time is a deprecated feature which will be removed; from PHP at some point in the near future. The acceptable method for passing a; value by reference to a function is by declaring the reference in the functions; definition, not at call time. This directive does not disable this feature, it; only determines whether PHP will warn you about it or not. These warnings; should enabled in development environments only.; Default Value: On (Suppress warnings); Development Value: Off (Issue warnings); Production Value: Off (Issue warnings); http://www.php.net/manual/en/ini.core.php#ini.allow-call-time-pass-referenceallow_call_time_pass_reference = Off

特别注意:

; Default Value: On (Suppress warnings)

关于php - 调用时按引用传递不会生成 E_DEPRECATED 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7824277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com