Php 按引用传递调用时间不会生成E_不推荐的错误
我遇到了一个Php 按引用传递调用时间不会生成E_不推荐的错误,php,Php,我遇到了一个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;' 我正试
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;'
我正试图触发一个PHP Deprecated:Call time pass by reference已被弃用foo(&$bar)
消息,但由于某些原因,我的本地安装没有引发它
我已经将它传递给了其他几个运行不同版本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 1
foobar.
5.3.5-1ubuntu7.2
mike@server:~$php-d error_reporting=-1-d display_errors=1-r'函数foo(&$bar){return$bar->title.“;}$bar=new stdClass()$bar->title=“foobar”;打印foo(&$bar)。PHP_EOL。PHP_版本。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"; 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'函数foo(&$bar){return$bar->title.“;}$bar=new stdClass()$bar->title=“foobar”;打印foo(&$bar)。PHP_EOL。PHP_版本。PHP_EOL;'
福巴。
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
mike@local:~$php-d error\u reporting=-1-d display\u errors=1-r'eregi(“test”,“test”);'
已弃用:第1行的命令行代码中已弃用函数eregi()
通过引用传递到函数已经有相当一段时间被弃用了(我相信是在引入PHP5之后?),这就是为什么您会收到警告的原因。只需调用foo($bar)
即可通过引用传递参数,因为您已经在函数定义中说明了这一点
您得到的结果不同这一事实意味着php.ini文件中存在不同的错误,或者错误报告编号已关闭(我相信它在不同版本之间会发生变化)。您的设置是否在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-reference
allow_call_time_pass_reference = Off
; 此指令允许您启用和禁用PHP将发出的警告
; 如果在函数调用时通过引用传递值。通过传递值
; 函数调用时引用是一个不推荐使用的功能,将被删除
; 在不久的将来从PHP开始。通过测试的可接受方法
; 函数引用的值是通过在函数中声明引用来实现的
; 定义,而不是在通话时间。此指令不会禁用此功能,而是
; 仅确定PHP是否会就此向您发出警告。这些警告
; 应仅在开发环境中启用。
; 默认值:打开(抑制警告)
; 开发值:关闭(发出警告)
; 生产值:关闭(发出警告)
; http://www.php.net/manual/en/ini.core.php#ini.allow-呼叫时间传递参考
允许调用时间传递参考=关闭
特别注意:
; Default Value: On (Suppress warnings)
; 默认值:打开(抑制警告)
我知道错误的含义和修复方法。我需要知道,在我明确设置了错误报告的情况下,为什么没有提出这个问题。“php.ini文件中要么有一个不同的文件”,这就是我要问的。什么样的php设置会影响这一点?-1:您还没有回答这个问题。我怀疑你也没读过!我的第二段直接回答了所提出的问题,尽管不是以结论性的方式。我看不出我怎么没有读到这个问题。(提示)错误报告(-1)
启用所有错误级别进行报告。@Gordon很高兴知道!这将在将来有所帮助。注意:我尝试更新我的命令以使用error_reporting=-1,但得到了相同的结果;var_dump(ini_get(“错误报告”),PHP_版本);'代码>在我的机器上给?@salathe字符串(2)“-1”字符串(16)“5.3.5-1ubuntu7.2”
。但在其他人身上,它抛出了不推荐的msg。而且,你的例子比我的要干净得多。介意我更新我的问题来使用它吗?宾果。一旦我在上面的测试中添加了allow\u call\u time\u pass\u reference=0
,我就开始收到错误。不确定该设置是如何进入我的php.ini的。再次感谢!
; Default Value: On (Suppress warnings)