Zephir\Backends\ZendEngine3\Backend::getTypeofCondition PHP Method

getTypeofCondition() public method

Checks the type of a variable using the ZendEngine constants
public getTypeofCondition ( Variable $variableVariable, string $operator, string $value, Zephir\CompilationContext $context ) : string
$variableVariable Zephir\Variable
$operator string
$value string
$context Zephir\CompilationContext
return string
    public function getTypeofCondition(Variable $variableVariable, $operator, $value, CompilationContext $context)
    {
        $variableName = $this->getVariableCode($variableVariable);
        switch ($value) {
            case 'array':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_ARRAY';
                break;
            case 'object':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_OBJECT';
                break;
            case 'null':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_NULL';
                break;
            case 'string':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_STRING';
                break;
            case 'int':
            case 'long':
            case 'integer':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_LONG';
                break;
            case 'double':
            case 'float':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_DOUBLE';
                break;
            case 'boolean':
            case 'bool':
                $condition = '((Z_TYPE_P(' . $variableName . ') == IS_TRUE || Z_TYPE_P(' . $variableName . ') == IS_FALSE) ' . $operator . ' 1)';
                break;
            case 'resource':
                $condition = 'Z_TYPE_P(' . $variableName . ') ' . $operator . ' IS_RESOURCE';
                break;
            case 'callable':
                $condition = 'zephir_is_callable(' . $variableName . ' TSRMLS_CC) ' . $operator . ' 1';
                break;
            default:
                throw new CompilerException('Unknown type: "' . $value . '" in typeof comparison', $expr['right']);
        }
        return $condition;
    }