PHP: Object assignment to static property, is it illegal?

后端 未结 2 825
伪装坚强ぢ
伪装坚强ぢ 2021-01-18 03:16

Is it illegal to assign some object to static property?

I am getting HTTP 500 error in below code.

require_once(\'class.linkedlist.php\');

class Sin         


        
2条回答
  •  天涯浪人
    2021-01-18 03:35

    you should take care, that you don't override the static property on each instantiation of a object, therefore do:

    class SinglyLinkedlistTester {
        private static $ll;
    
        public function __construct() {
            if (!self::$ll) self::$ll = new Linklist();
        }
    }
    

提交回复
热议问题