Skip to content

Commit 32f5f30

Browse files
committed
#2330 - Improve support of mixed type in arrays
1 parent 4f76415 commit 32f5f30

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Library/Backends/ZendEngine2/Backend.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
use Zephir\GlobalConstant;
2222
use Zephir\Variable;
2323

24+
use function in_array;
25+
2426
/**
25-
* Zephir\Backends\ZendEngine2\Backend.
26-
*
2727
* NOTE: ZendEngine2 backend is no longer supported
2828
* and this class will be removed in the future.
2929
*/
@@ -300,7 +300,7 @@ public function addArrayEntry(Variable $variable, $key, $value, CompilationConte
300300
$var = $context->symbolTable->getVariableForRead($key->getCode(), $context);
301301
$typeKey = $var->getType();
302302
}
303-
if (\in_array($typeKey, ['int', 'uint', 'long', 'ulong'])) {
303+
if (in_array($typeKey, ['int', 'uint', 'long', 'ulong'])) {
304304
$keyType = 'index';
305305
}
306306
}
@@ -455,7 +455,7 @@ public function arrayFetch(Variable $var, Variable $src, $index, $flags, $arrayA
455455
$arrayAccess['right']
456456
);
457457
}
458-
if ($isVariable && \in_array($index->getType(), ['variable', 'string', 'mixed'])) {
458+
if ($isVariable && in_array($index->getType(), ['variable', 'string', 'mixed'])) {
459459
$output = 'zephir_array_fetch('.$this->getVariableCodePointer($var).', '.$this->getVariableCode($src).', '.$this->getVariableCode($index).', '.$flags.', "'.Compiler::getShortUserPath($arrayAccess['file']).'", '.$arrayAccess['line'].');';
460460
} else {
461461
if ($isVariable) {
@@ -500,20 +500,21 @@ public function arrayIssetFetch(Variable $target, Variable $var, $resolvedExpr,
500500
$code = $this->getVariableCodePointer($target).', '.$this->getVariableCode($var);
501501

502502
if (!($resolvedExpr instanceof Variable)) {
503-
if ('string' == $resolvedExpr->getType()) {
503+
if ('string' === $resolvedExpr->getType()) {
504504
return new CompiledExpression('bool', 'zephir_array_isset_string_fetch('.$code.', SS("'.$resolvedExpr->getCode().'"), '.$flags.')', $expression);
505-
} elseif (\in_array($resolvedExpr->getType(), ['int', 'uint', 'long'])) {
505+
} elseif (in_array($resolvedExpr->getType(), ['int', 'uint', 'long'])) {
506506
return new CompiledExpression('bool', 'zephir_array_isset_long_fetch('.$code.', '.$resolvedExpr->getCode().', '.$flags.')', $expression);
507507
} else {
508508
$resolvedExpr = $context->symbolTable->getVariableForRead($resolvedExpr->getCode(), $context);
509509
}
510510
}
511511

512-
if ('int' == $resolvedExpr->getType() || 'long' == $resolvedExpr->getType()) {
512+
if (in_array($resolvedExpr->getType(), ['int', 'long'])) {
513513
return new CompiledExpression('bool', 'zephir_array_isset_long_fetch('.$code.', '.$this->getVariableCode($resolvedExpr).', '.$flags.')', $expression);
514-
} elseif ('variable' == $resolvedExpr->getType() || 'string' == $resolvedExpr->getType()) {
514+
} elseif (in_array($resolvedExpr->getType(), ['variable', 'mixed', 'string'])) {
515515
return new CompiledExpression('bool', 'zephir_array_isset_fetch('.$code.', '.$this->getVariableCode($resolvedExpr).', '.$flags.')', $expression);
516516
}
517+
517518
throw new CompilerException('arrayIssetFetch ['.$resolvedExpr->getType().']', $expression);
518519
}
519520

0 commit comments

Comments
 (0)