Home >Backend Development >PHP Tutorial >Problems with const variables and connectors

Problems with const variables and connectors

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:52:271642browse

When a variable defined by the const keyword is concatenated with a string and assigned to another const variable,

<code>报syntax error, unexpected '.', expecting ',' or ';'
</code>

The code is as follows

<code>const a = '你好';
const b = a.'certs/';//直接报错</code>

Can you please help me

Reply content:

When a variable defined by the const keyword is concatenated with a string and assigned to another const variable,

<code>报syntax error, unexpected '.', expecting ',' or ';'
</code>

The code is as follows

<code>const a = '你好';
const b = a.'certs/';//直接报错</code>

Can you please help me

Nothing to help, the grammar doesn’t allow you to write like this.
Const definitions cannot use operators, variables and the like.
Besides what a is, at least it should be const b = self::a . 'certs/', although it is still illegal.

You lack context. You can only use it in a class. For external PHP constants, use define
PHP constants

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