Php: can't assign a property value in declaration

后端 未结 2 1427
你的背包
你的背包 2020-12-12 01:33

I do not understand the rationale behind the different treatment of variable assignment between global context and class context:

$var1 = \"a\" . \"b\"; # PH         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-12 01:43

    Quoting from the PHP docs (my emphasis)

    This declaration may include an initialization, but this initialization must be a constant value -- that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

    Instead, define values in the constructor if they're dependent on any evaluation.

提交回复
热议问题