Zephir\FunctionCall::markReferences PHP Method

markReferences() protected method

Once the function processes the parameters we should mark specific parameters to be passed by reference
protected markReferences ( string $funcName, array $parameters, zephir\CompilationContext $compilationContext, array &$references, array $expression ) : boolean
$funcName string
$parameters array
$compilationContext zephir\CompilationContext
$references array
$expression array
return boolean
    protected function markReferences($funcName, $parameters, CompilationContext $compilationContext, &$references, $expression)
    {
        if ($this->isBuiltInFunction($funcName)) {
            return false;
        }
        $reflector = $this->getReflector($funcName);
        if ($reflector) {
            $numberParameters = count($parameters);
            if ($numberParameters > 0) {
                $n = 1;
                $funcParameters = $reflector->getParameters();
                $isZendEngine3 = $compilationContext->backend->isZE3();
                foreach ($funcParameters as $parameter) {
                    if ($numberParameters >= $n) {
                        if ($parameter->isPassedByReference()) {
                            /* TODO hack, fix this better */
                            if ($isZendEngine3 && $parameters[$n - 1][0] == '&') {
                                $parameters[$n - 1] = substr($parameters[$n - 1], 1);
                            }
                            if (!preg_match('/^[a-zA-Z0-9$\\_]+$/', $parameters[$n - 1])) {
                                $compilationContext->logger->warning("Cannot mark complex expression as reference", "invalid-reference", $expression);
                                continue;
                            }
                            $variable = $compilationContext->symbolTable->getVariable($parameters[$n - 1]);
                            if ($variable) {
                                $variable->setDynamicTypes('undefined');
                                $referenceSymbol = $compilationContext->backend->getVariableCode($variable);
                                $compilationContext->codePrinter->output('ZEPHIR_MAKE_REF(' . $referenceSymbol . ');');
                                $references[] = $parameters[$n - 1];
                            }
                        }
                    }
                    $n++;
                }
            }
        }
    }