【问题标题】:What is the difference betwen Variable in PHP4 and PHP5?PHP4 和 PHP5 中的变量有什么区别?
【发布时间】:2010-03-21 12:18:36
【问题描述】:

关于这个问题我唯一知道的是......

在 PHP 5 中,当使用的变量未分配任何值时,将显示警告。

这两个不同版本之间还有其他区别吗?

【问题讨论】:

标签: php php4


【解决方案1】:

PHP 4 和 5 中的变量没有一般的区别。

您可能指的是“E_NOTICE”错误报告级别。打开该级别时,如果使用了尚未分配的变量,PHP 会报错。 PHP 4 中已经存在该级别:

// Report all errors except E_NOTICE
// This is the default value set in php.ini

error_reporting(E_ALL ^ E_NOTICE);

echo $hello_world;  // Will output nothing, but also not output a notice

error_reporting(E_ALL);

echo $hello_word;   // Will output "Notice: Undefined variable"

可以通过“error_reporting”php.ini 设置或在脚本运行期间使用error_reporting() 函数来影响PHP 的错误报告。

至于其他差异,还有很多。查看 Gordon 关于从 PHP 4 迁移到 5 的链接。

【讨论】:

    【解决方案2】:

    实际上,没有真正的区别。使用未定义变量时显示的错误是 PHP 设置的差异,而不是 PHP 版本。

    【讨论】:

      【解决方案3】:

      php4 和 php5 中的变量没有区别。您可以使用以下命令停止错误报告:

      error_reporting('E_ALL ^ E_NOTICE'); 
      

      【讨论】:

        猜你喜欢
        • 2012-02-12
        • 1970-01-01
        • 2015-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-06-13
        • 1970-01-01
        • 2018-04-23
        相关资源
        最近更新 更多