PHP 7.2中的未定义常量错误 [英] Undefined constant error in php 7.2

查看:349
本文介绍了PHP 7.2中的未定义常量错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在php v7.2中有这些错误,但是在使用php v7.1时看不到任何E_WARNING.

I have theses errors in php v7.2 but don't see any E_WARNING when using php v7.1.

如何解决以下错误?

第39行上的

/web13/web/boutique/includes/Sites/Shop/NavigationHistory.php [2018年1月12日22:44:20美国/多伦多] PHP警告:在/var/www/clients/client1中使用未定义的常量MODULE_HEADER_SELECT_TEMPLATE_STATUS-假定为'MODULE_HEADER_SELECT_TEMPLATE_STATUS'(这将在以后的PHP版本中引发错误). /web13/web/boutique/includes/Sites/Shop/Template.php,第356行

/web13/web/boutique/includes/Sites/Shop/NavigationHistory.php on line 39 [12-Jan-2018 22:44:20 America/Toronto] PHP Warning: Use of undefined constant MODULE_HEADER_SELECT_TEMPLATE_STATUS - assumed 'MODULE_HEADER_SELECT_TEMPLATE_STATUS' (this will throw an Error in a future version of PHP) in /var/www/clients/client1/web13/web/boutique/includes/Sites/Shop/Template.php on line 356

推荐答案

这是常见的警告,只要PHP检测到未定义的

This is a common warning that occurs whenever PHP has detected the usage of an undefined constant.

以下是在PHP中定义常量的示例:

Here is an example of constant being defined in PHP:

define('PI', 3.14);

以下是一些可能导致此问题的情况的列表:

Below is a list of some cases that might cause the issue:

  • 忘记在变量名的开头使用$符号.

$name = "Aniket";
echo name; // forgot to add $ before name

上面的代码将引发:注意:使用未定义的常量名称-假定为名称" .因为变量名称"前面没有美元符号,所以PHP假定我正在尝试引用一个名为名称"的常量变量.

The above code will throw: Notice: Use of undefined constant name – assumed ‘name’. Because there is no dollar sign in front of the variable "name", PHP assumes that I was trying to reference a constant variable called "name".

忘记在字符串两边加上引号.

echo $_POST[email];

在上面的示例中,我未能在$_POST变量email周围加上引号.该代码将引发:注意:使用未定义的常量名称-假定为电子邮件" .

In the example above, I failed to place quotes around the $_POST variable "email". This code will throw: Notice: Use of undefined constant name – assumed ’email’.

要解决此问题,我显然必须执行以下操作:

To fix this, I’d obviously have to do the following:

echo $_POST["email"];

根据 PHP 7.2.x中已弃用的功能,您不应使用未定义的功能常量,因为:

According to Deprecated features in PHP 7.2.x you should not use undefined constants because:

不存在的全局常量不带引号的字符串被视为其自身的字符串.

Unquoted strings that are non-existent global constants are taken to be strings of themselves.

此行为曾经发出 E_NOTICE ,但现在会发出 E_WARNING .在PHP的下一个主要版本中,将引发Error异常.

This behaviour used to emit an E_NOTICE, but will now emit an E_WARNING. In the next major version of PHP, an Error exception will be thrown instead.

只有在使用常量值之前声明常量值,您才能阻止此值.

You can prevent this E_WARNING only if you declare the constant value before using it.

在上述问题中,未定义MODULE_HEADER_SELECT_TEMPLATE_STATUS.

In the above question, MODULE_HEADER_SELECT_TEMPLATE_STATUS is not defined.

这篇关于PHP 7.2中的未定义常量错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆