PHP ternary operator doesn't parse inside class property?

前端 未结 1 1574
长情又很酷
长情又很酷 2020-12-11 11:27

I\'m trying to figure out why a ternary operator inside of a class will not parse. I think an example is the clearest way to show this.

This works fine:



        
相关标签:
1条回答
  • 2020-12-11 12:17

    A class property must be a constant expression.

    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.

    http://www.php.net/manual/en/language.oop5.properties.php

    0 讨论(0)
提交回复
热议问题