PHP function call in class property

后端 未结 3 600
孤独总比滥情好
孤独总比滥情好 2020-12-02 02:18

Why can\'t I do this in PHP? Where Database is a singleton class and getInstance() returns a PDO object.



        
3条回答
  •  臣服心动
    2020-12-02 02:53

    You can't execute code to produce the value of a static variable as, by definition, static variables are affected at compile time, see :

    • http://en.wikipedia.org/wiki/Static_memory_allocation
    • http://en.wikipedia.org/wiki/Static_variable

    Getting the run-time value of a variable, or calling a function (run-time too) can't be done at compile-time to they cannot be affected to static variables.

提交回复
热议问题