HvyIndustries / crane

PHP Intellisense/code-completion for VS Code
https://hvy.io/crane
Other
240 stars 25 forks source link

Code completion support for magic property 'get' methods #387

Open nevadascout opened 6 years ago

nevadascout commented 6 years ago

Handle magic get methods as shown:

    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;