Zephir\Variable::hasAnyDynamicType PHP Method

hasAnyDynamicType() public method

Checks if the variable has any of the passed dynamic
public hasAnyDynamicType ( mixed $types ) : boolean
$types mixed
return boolean
    public function hasAnyDynamicType($types)
    {
        if (is_string($types)) {
            return isset($this->dynamicTypes[$types]);
        } else {
            foreach ($types as $type) {
                if (isset($this->dynamicTypes[$type])) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Beispiel #1
0
 /**
  * Compiles obj->x++
  *
  * @param string $variable
  * @param string $property
  * @param ZephirVariable $symbolVariable
  * @param CompilationContext $compilationContext
  * @param array $statement
  */
 public function assign($variable, $property, ZephirVariable $symbolVariable, CompilationContext $compilationContext, $statement)
 {
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     /**
      * Arrays must be stored in the HEAP
      */
     if ($symbolVariable->isLocalOnly()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is local only", $statement);
     }
     if (!$symbolVariable->isInitialized()) {
         throw new CompilerException("Cannot mutate variable '" . $variable . "' because it is not initialized", $statement);
     }
     /**
      * Only dynamic variables can be used as arrays
      */
     if ($symbolVariable->getType() != 'variable') {
         throw new CompilerException("Cannot use variable type: '" . $symbolVariable->getType() . "' as array", $statement);
     }
     if ($symbolVariable->hasAnyDynamicType('unknown')) {
         throw new CompilerException("Cannot use non-initialized variable as an object", $statement);
     }
     /**
      * Trying to use a non-object dynamic variable as object
      */
     if ($symbolVariable->hasDifferentDynamicType(array('undefined', 'object', 'null'))) {
         $compilationContext->logger->warning('Possible attempt to increment non-object dynamic variable', 'non-object-update', $statement);
     }
     $compilationContext->headersManager->add('kernel/object');
     $compilationContext->codePrinter->output('RETURN_ON_FAILURE(zephir_property_incr(' . $symbolVariable->getName() . ', SL("' . $property . '") TSRMLS_CC));');
 }
All Usage Examples Of Zephir\Variable::hasAnyDynamicType