Home >Backend Development >PHP Tutorial >PHP如何用const以一个常量定义另一个常量

PHP如何用const以一个常量定义另一个常量

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 20:41:431107browse

如下所示

const X = 'x';
const XX = X.'x';

第二行有语法错误,正确的格式应该是什么样呢。

回复内容:

如下所示

const X = 'x';
const XX = X.'x';

第二行有语法错误,正确的格式应该是什么样呢。

升级PHP5.6

http://cn2.php.net/manual/zh/migration56.new-features.php#migration56.new-features.const-scalar-exprs

常量的值;仅允许标量和 null 。标量的类型是 integer , float , string 或者 boolean 。
也能够定义常量值的类型为 resource ,但并不推荐这么做,可能会导致未知状况的发生。

解决方案:

<code>const X1 = 'x1';
const X2 = 'x2';

echo X1.X2;
</code>

当然你也可以选择升级,正如 @mcfog 所说~

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn