PHP function call in class property

后端 未结 3 592
孤独总比滥情好
孤独总比滥情好 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:52

    RTM ;)

    See the last sentence of the first paragraph in the PHP documentation for properties http://www.php.net/manual/en/language.oop5.properties.php

    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.

提交回复
热议问题