Static Function Variables and Concatenation in PHP

前端 未结 3 1363
无人及你
无人及你 2020-12-20 11:32

Consider the following:

$var = \'foo\' . \'bar\'; # Not a member of a class, free-standing or in a function.

As soon as I mark $var

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 12:02

    The manual states, in Variables scope:

    Trying to assign values to these [static] variables which are the result of expressions will cause a parse error.

    There is also mention of it in Static keyword:

    Like any other PHP static variable, static properties may only be initialized using a literal or constant; expressions are not allowed.

    Although it should be noted that a property, static or not, cannot be initialized using an expression neither.

提交回复
热议问题