private $prop = 'test';
protected $_getters = [];
public function __construct() {
$this->_getters = ['prop'];
}
public function &__get($fieldName)
{
if (method_exists($this, "__get_$fieldName")) {
$return = $this->{"__get_$fieldName[1]"}();
} elseif (in_array($fieldName, $this->_getters)) {
$return = $this->$fieldName;
}
return $return;
}
}
$a = new Test();
// should show a code completion suggestion here, even though the property is private
echo $a->prop;
Handle magic get methods as shown: