Zephir\Variable::hasDifferentDynamicType PHP Method

hasDifferentDynamicType() public method

Check if the variable has at least one dynamic type to the ones passed in the list
public hasDifferentDynamicType ( array | string $types ) : boolean
$types array | string
return boolean
    public function hasDifferentDynamicType($types)
    {
        $number = 0;
        foreach ($types as $type) {
            if (isset($this->dynamicTypes[$type])) {
                $number++;
            }
        }
        return $number == 0;
    }

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::hasDifferentDynamicType