当前位置: 首页>>代码示例>>PHP>>正文


PHP Expression::isExpectingReturn方法代码示例

本文整理汇总了PHP中Zephir\Expression::isExpectingReturn方法的典型用法代码示例。如果您正苦于以下问题:PHP Expression::isExpectingReturn方法的具体用法?PHP Expression::isExpectingReturn怎么用?PHP Expression::isExpectingReturn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zephir\Expression的用法示例。


在下文中一共展示了Expression::isExpectingReturn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: compile

 /**
  * Compiles a method call
  *
  * @param Expression $expr
  * @param CompilationContext $compilationContext
  */
 public function compile(Expression $expr, CompilationContext $compilationContext)
 {
     $expression = $expr->getExpression();
     $exprVariable = new Expression($expression['variable']);
     $exprVariable->setReadOnly(true);
     $exprCompiledVariable = $exprVariable->compile($compilationContext);
     $builtInType = false;
     switch ($exprCompiledVariable->getType()) {
         case 'variable':
             $variableVariable = $compilationContext->symbolTable->getVariableForRead($exprCompiledVariable->getCode(), $compilationContext, $expression);
             switch ($variableVariable->getType()) {
                 case 'variable':
                     $caller = $variableVariable;
                     break;
                 default:
                     /* Check if there is a built-in type optimizer available */
                     $builtInTypeClass = 'Zephir\\Types\\' . ucfirst($variableVariable->getType()) . 'Type';
                     if (class_exists($builtInTypeClass)) {
                         /**
                          * @var $builtInType \Zephir\Types\AbstractType
                          */
                         $builtInType = new $builtInTypeClass();
                         $caller = $exprCompiledVariable;
                     } else {
                         throw new CompilerException("Methods cannot be called on variable type: " . $variableVariable->getType(), $expression);
                     }
             }
             break;
         default:
             /* Check if there is a built-in type optimizer available */
             $builtInTypeClass = 'Zephir\\Types\\' . ucfirst($exprCompiledVariable->getType()) . 'Type';
             if (class_exists($builtInTypeClass)) {
                 $builtInType = new $builtInTypeClass();
                 $caller = $exprCompiledVariable;
             } else {
                 throw new CompilerException("Cannot use expression: " . $exprCompiledVariable->getType() . " as method caller", $expression['variable']);
             }
     }
     $codePrinter = $compilationContext->codePrinter;
     $type = $expression['call-type'];
     /**
      * In normal method calls and dynamic string method calls we just use the name given by the user
      */
     if ($type == self::CALL_NORMAL || $type == self::CALL_DYNAMIC_STRING) {
         $methodName = strtolower($expression['name']);
     } else {
         $variableMethod = $compilationContext->symbolTable->getVariableForRead($expression['name'], $compilationContext, $expression);
         if (is_object($builtInType)) {
             throw new CompilerException("Dynamic method invocation for type: " . $variableMethod->getType() . " is not supported", $expression);
         }
         if ($variableMethod->isNotVariableAndString()) {
             throw new CompilerException("Cannot use variable type: " . $variableMethod->getType() . " as dynamic method name", $expression);
         }
     }
     $symbolVariable = null;
     /**
      * Create temporary variable if needed
      */
     $mustInit = false;
     $isExpecting = $expr->isExpectingReturn();
     if ($isExpecting) {
         $symbolVariable = $expr->getExpectingVariable();
         if (is_object($symbolVariable)) {
             $readDetector = new ReadDetector($expression);
             if ($caller == $symbolVariable || $readDetector->detect($symbolVariable->getName(), $expression)) {
                 $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
             } else {
                 $mustInit = true;
             }
         } else {
             $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
         }
     }
     /**
      * Method calls only return zvals so we need to validate the target variable is also a zval
      */
     if (!$builtInType) {
         if ($isExpecting) {
             if (!$symbolVariable->isVariable()) {
                 throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
             }
             /**
              * At this point, we don't know the exact dynamic type returned by the method call
              */
             $symbolVariable->setDynamicTypes('undefined');
         }
     } else {
         return $builtInType->invokeMethod($methodName, $caller, $compilationContext, $this, $expression);
     }
     $check = true;
     if (isset($expression['check'])) {
         $check = $expression['check'];
     }
     /**
//.........这里部分代码省略.........
开发者ID:edin,项目名称:zephir,代码行数:101,代码来源:MethodCall.php

示例2: compile

 /**
  * Compiles a static method call
  *
  * @param array $expr
  * @param CompilationContext $compilationContext
  */
 public function compile(Expression $expr, CompilationContext $compilationContext)
 {
     $expression = $expr->getExpression();
     $methodName = strtolower($expression['name']);
     if (isset($expression['dynamic'])) {
         $dynamicMethod = $expression['dynamic'];
     } else {
         $dynamicMethod = false;
     }
     $symbolVariable = null;
     /**
      * Create temporary variable if needed
      */
     $mustInit = false;
     $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->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
             } else {
                 $mustInit = true;
             }
         } else {
             $symbolVariable = $compilationContext->symbolTable->getTempVariableForObserveOrNullify('variable', $compilationContext, $expression);
         }
     }
     /**
      * Method calls only return zvals so we need to validate the target variable is also a zval
      */
     if ($isExpecting) {
         /**
          * At this point, we don't know the exact dynamic type returned by the static method call
          */
         $symbolVariable->setDynamicTypes('undefined');
         if ($symbolVariable->getType() != 'variable') {
             throw new CompilerException("Returned values by functions can only be assigned to variant variables", $expression);
         }
     }
     /**
      * Include fcall header
      */
     $compilationContext->headersManager->add('kernel/fcall');
     $compiler = $compilationContext->compiler;
     $dynamicClass = $expression['dynamic-class'];
     if (!$dynamicClass) {
         $className = $expression['class'];
         $classDefinition = false;
         if ($className != 'self' && $className != 'parent') {
             if (is_string($className)) {
                 $className = $compilationContext->getFullName($className);
                 if ($compiler->isClass($className)) {
                     $classDefinition = $compiler->getClassDefinition($className);
                 } else {
                     if ($compiler->isInternalClass($className)) {
                         $classDefinition = $compiler->getInternalClassDefinition($className);
                     } else {
                         throw new CompilerException("Class name: " . $className . " does not exist", $expression);
                     }
                 }
             } else {
                 foreach ($className as $singleClass) {
                     $className = $compilationContext->getFullName($singleClass);
                     if ($compiler->isClass($singleClass)) {
                         $classDefinition = $compiler->getClassDefinition($singleClass);
                     } else {
                         throw new CompilerException("Class name: " . $className . " does not exist", $expression);
                     }
                 }
             }
         } else {
             if ($className == 'self') {
                 $classDefinition = $compilationContext->classDefinition;
             } else {
                 if ($className == 'parent') {
                     $classDefinition = $compilationContext->classDefinition;
                     $extendsClass = $classDefinition->getExtendsClass();
                     if (!$extendsClass) {
                         throw new CompilerException('Cannot call method "' . $methodName . '" on parent because class ' . $classDefinition->getCompleteName() . ' does not extend any class', $expression);
                     }
                     $currentClassDefinition = $classDefinition;
                     $classDefinition = $classDefinition->getExtendsClassDefinition();
                 }
             }
         }
     }
     /**
      * Check if the class implements the method
      */
     if (!$dynamicMethod && !$dynamicClass) {
         if (!$classDefinition->hasMethod($methodName)) {
             throw new CompilerException("Class '" . $classDefinition->getCompleteName() . "' does not implement static method: '" . $expression['name'] . "'", $expression);
         } else {
//.........这里部分代码省略.........
开发者ID:NumbDai,项目名称:zephir,代码行数:101,代码来源:StaticCall.php


注:本文中的Zephir\Expression::isExpectingReturn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。