PHP5. Two ways of declaring an array as a class member

后端 未结 4 1397
猫巷女王i
猫巷女王i 2021-02-07 00:43

When declaring an array as a class member, which way should it be done?

class Test1 {
    private $paths = array();

    public function __construct() {
                 


        
4条回答
  •  梦毁少年i
    2021-02-07 01:18

    I'd suggest doing this when declaring a class variable. A constructor can be overriden in extending classes, which might result in E_NOTICEs or even E_WARNINGs if any of your functions depend on this variable being an array (even an empty one)

提交回复
热议问题