/** * @param string $sIncName * @return mixed */ public function __get($sIncName) { try { $oProperty = new \ReflectionProperty($this, $sIncName); if (!$oProperty->isPublic()) { // try for a getter method $sGetterName = 'get' . ucfirst($sIncName); $oGetter = new \ReflectionMethod($this, $sGetterName); $this->_current = $sIncName; // ?? I wonder if setting the offset to the current read position is the right way return $oGetter->invoke($this, $sIncName); } else { $this->_current = $sIncName; // ?? I wonder if setting the offset to the current read position is the right way return $oProperty->getValue($this); } } catch (\ReflectionException $e) { // reflection issue return parent::__get($sIncName); } }
public function test__get() { $null = new Base(); $this->assertInstanceOf(Base::class, $null->__get('test')); $this->assertInstanceOf(Base::class, $null->test); }