Execute a method when an instance variable is referenced in a PHP class?
Is it possible to run a function when referring to a variable in a php class rather than simply returning its value, similar to javascript's ability for a variable to hold a method?

    class LazyClassTest()
    {
    
        protected $_lazyInitializedVar;
    
        public function __construct()
        {
            /* // How can this call and return runWhenReferrenced() when
               // someone refers to it outside of the class:
               $class = new LazyClass();
               $class->lazy;
               // Such that $class->lazy calls $this->runWhenReferrenced each
               // time it is referred to via $class->lazy?
             */
            $this->lazy = $this->runWhenReferrenced();
        }
    
        protected function runWhenReferrenced()
        {
            if (!$this->_lazyInitializedVar) {
                $this->_lazyInitializedVar = 'someValue';
            }
    
            return $this->_lazyInitializedVar
        }
    
    }
Execute a method when an instance variable is referenced in a PHP class?
===

Is it possible to run a function when referring to a variable in a php class rather than simply returning its value, similar to javascript's ability for a variable to hold a method?

    class LazyClassTest()
    {
    
        protected $_lazyInitializedVar;
    
        public function __construct()
        {
            /* // How can this call and return runWhenReferrenced() when
               // someone refers to it outside of the class:
               $class = new LazyClass();
               $class->lazy;
               // Such that $class->lazy calls $this->runWhenReferrenced each
               // time it is referred to via $class->lazy?
             */
            $this->lazy = $this->runWhenReferrenced();
        }
    
        protected function runWhenReferrenced()
        {
            if (!$this->_lazyInitializedVar) {
                $this->_lazyInitializedVar = 'someValue';
            }
    
            return $this->_lazyInitializedVar
        }
    
    }