Zephir\Call::processExpectedReturn PHP Метод

processExpectedReturn() публичный Метод

Processes the symbol variable that will be used to return the result of the symbol call
public processExpectedReturn ( zephir\CompilationContext $compilationContext )
$compilationContext zephir\CompilationContext
    public function processExpectedReturn(CompilationContext $compilationContext)
    {
        $expr = $this->_expression;
        $expression = $expr->getExpression();
        /**
         * Create temporary variable if needed
         */
        $mustInit = false;
        $symbolVariable = null;
        $isExpecting = $expr->isExpectingReturn();
        if ($isExpecting) {
            $symbolVariable = $expr->getExpectingVariable();
            if (is_object($symbolVariable)) {
                $readDetector = new ReadDetector($expression);
                if ($readDetector->detect($symbolVariable->getName(), $expression)) {
                    $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
                } else {
                    $mustInit = true;
                }
            } else {
                $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression);
            }
        }
        $this->_mustInit = $mustInit;
        $this->_symbolVariable = $symbolVariable;
        $this->_isExpecting = $isExpecting;
    }

Usage Example

Пример #1
0
 /**
  *
  * @param array $expression
  * @param Call $call
  * @param CompilationContext $context
  */
 public function optimize(array $expression, Call $call, CompilationContext $context)
 {
     $call->processExpectedReturn($context);
     $args = $this->getParams($expression);
     $func = strtolower($args[0]);
     $call->processExpectedReturn($context);
     $symbolVariable = $call->getSymbolVariable();
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
     }
     if ($call->mustInitSymbolVariable()) {
         $symbolVariable->initVariant($context);
     }
     $args = $call->getReadOnlyResolvedParams($expression['parameters'], $context, $expression);
     switch ($func) {
         case 'connect':
             $other_arguments = $args[1] . ',' . $args[2];
             break;
         default:
             $args_len = count($args);
             $other_arguments = "";
             for ($i = 1; $i < $args_len; $i++) {
                 $other_arguments .= $args[$i] . ',';
             }
             $other_arguments = substr($other_arguments, 0, count($other_arguments) - 2);
             break;
     }
     $cmd = 'redis_' . $func . '(' . $symbolVariable->getName() . ',' . $other_arguments . ');';
     $context->codePrinter->output($cmd);
     return new CompiledExpression('variable', $symbolVariable->getRealName(), $expression);
 }
All Usage Examples Of Zephir\Call::processExpectedReturn