PHPSA\Compiler\Expression\PropertyFetch::compile PHP Method

compile() protected method

classname->property
protected compile ( PhpParser\Node\Expr\PropertyFetch $expr, Context $context ) : CompiledExpression
$expr PhpParser\Node\Expr\PropertyFetch
$context PHPSA\Context
return PHPSA\CompiledExpression
    protected function compile($expr, Context $context)
    {
        $compiler = $context->getExpressionCompiler();
        $propertNameCE = $compiler->compile($expr->name);
        $scopeExpression = $compiler->compile($expr->var);
        if ($scopeExpression->isObject()) {
            $scopeExpressionValue = $scopeExpression->getValue();
            if ($scopeExpressionValue instanceof ClassDefinition) {
                $propertyName = $propertNameCE->isString() ? $propertNameCE->getValue() : false;
                if ($propertyName) {
                    if ($scopeExpressionValue->hasProperty($propertyName, true)) {
                        $property = $scopeExpressionValue->getProperty($propertyName, true);
                        return $compiler->compile($property);
                    } else {
                        $context->notice('language_error', sprintf('Property %s does not exist in %s scope', $propertyName, $scopeExpressionValue->getName()), $expr);
                    }
                }
            }
            return new CompiledExpression();
        } elseif ($scopeExpression->canBeObject()) {
            return new CompiledExpression();
        }
        $context->notice('language_error', "It's not possible to fetch a property on a non-object", $expr, Check::CHECK_BETA);
        return new CompiledExpression();
    }
PropertyFetch