diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 11156f9c..ea585906 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -2064,7 +2064,10 @@ class CompilerBase extends \PhpAot\Core\Translator $code = 'for (auto iter = ' . $iteratorVar . '.begin(); iter != ' . $iteratorVar . '.end(); ++iter) {' . PHP_EOL; $this->indentLevel++; if ($node->keyVar) { - $code .= self::TYPE_VAR . ' ' . $this->getIndent() . ' ' . $keyVar . ' = iter.key();' . PHP_EOL; + if (!$this->hasVar($keyVar)) { + $this->addLocalVar($keyVar, self::TYPE_VAR); + } + $code .= $this->getIndent() . ' ' . $keyVar . ' = iter.key();' . PHP_EOL; } if ($node->valueVar->getType() == self::EXPR_ARRAY_DIM_FETCH) { @@ -2076,7 +2079,10 @@ class CompilerBase extends \PhpAot\Core\Translator $code .= $this->getIndent() . "$array.offsetSet($dim, iter.value());"; } else { $valueVar = $this->parseIdentifier($node->valueVar); - $code .= self::TYPE_VAR . ' ' . $this->getIndent() . ' ' . $valueVar . ' = iter.value();' . PHP_EOL; + if (!$this->hasVar($valueVar)) { + $this->addLocalVar($valueVar, self::TYPE_VAR); + } + $code .= $this->getIndent() . ' ' . $valueVar . ' = iter.value();' . PHP_EOL; } $body = $this->parseStmts($node->stmts); @@ -2356,6 +2362,11 @@ class CompilerBase extends \PhpAot\Core\Translator return $var . ' = &' . $this->parseIdentifier($expr->expr); } elseif ($expr->expr->getType() === self::EXPR_ARRAY_DIM_FETCH) { return $var . ' = ' . $this->parseIdentifier($expr->expr); + } elseif ($this->isPropertyFetch($expr->expr)) { + $var = $this->parseIdentifier($expr->var); + $object = $this->convertToObject($expr->expr->var); + $prop = $this->identifierToStr($expr->expr->name); + return $var . ' = ' . $object . '.getPropertyReference(' . $prop . ')'; } } abort($expr); diff --git a/tests/zend/in-de-crement/decrement_001_64bit.phpt b/tests/zend/in-de-crement/decrement_001_64bit.phpt new file mode 100644 index 00000000..a94f843c --- /dev/null +++ b/tests/zend/in-de-crement/decrement_001_64bit.phpt @@ -0,0 +1,25 @@ +--TEST-- +Decrementing min int values 64bit +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +float(-9.223372036854776E+18) +float(-9.223372036854776E+18) +Done diff --git a/tests/zend/in-de-crement/incdec_bool_exception.phpt b/tests/zend/in-de-crement/incdec_bool_exception.phpt new file mode 100644 index 00000000..8f1db31c --- /dev/null +++ b/tests/zend/in-de-crement/incdec_bool_exception.phpt @@ -0,0 +1,28 @@ +--TEST-- +Inc/dec on bool: warning converted to exception +--FILE-- +getMessage(), PHP_EOL; + } + try { + $value--; + } catch (\Exception $e) { + echo $e->getMessage(), PHP_EOL; + } +} +?> +--EXPECT-- +Warning: Increment on type bool has no effect, this will change in the next major version of PHP in Unknown(0) : eval() on line 1 + +Warning: Increment on type bool has no effect, this will change in the next major version of PHP in Unknown(0) : eval() on line 1 + +Warning: Increment on type bool has no effect, this will change in the next major version of PHP in Unknown(0) : eval() on line 1 + +Warning: Increment on type bool has no effect, this will change in the next major version of PHP in Unknown(0) : eval() on line 1 + diff --git a/tests/zend/in-de-crement/incdec_ref_property.phpt b/tests/zend/in-de-crement/incdec_ref_property.phpt new file mode 100644 index 00000000..a73b2912 --- /dev/null +++ b/tests/zend/in-de-crement/incdec_ref_property.phpt @@ -0,0 +1,27 @@ +--TEST-- +Incrementing and decrementing a referenced property +--FILE-- +prop = 1; +$ref =& $obj->prop; +var_dump(++$obj->prop); +var_dump($obj->prop); +var_dump($obj->prop++); +var_dump($obj->prop); +var_dump(--$obj->prop); +var_dump($obj->prop); +var_dump($obj->prop--); +var_dump($obj->prop); + +?> +--EXPECT-- +int(2) +int(2) +int(2) +int(3) +int(2) +int(2) +int(2) +int(1) diff --git a/tests/zend/in-de-crement/increment_001_64bit.phpt b/tests/zend/in-de-crement/increment_001_64bit.phpt new file mode 100644 index 00000000..333bbcd4 --- /dev/null +++ b/tests/zend/in-de-crement/increment_001_64bit.phpt @@ -0,0 +1,24 @@ +--TEST-- +Incrementing max int values 64bit +--SKIPIF-- + +--INI-- +precision=14 +--FILE-- + +--EXPECT-- +float(9.223372036854776E+18) +float(9.223372036854776E+18) +Done diff --git a/tests/zend/in-de-crement/post_inc_without_use.phpt b/tests/zend/in-de-crement/post_inc_without_use.phpt new file mode 100644 index 00000000..39a7e94a --- /dev/null +++ b/tests/zend/in-de-crement/post_inc_without_use.phpt @@ -0,0 +1,12 @@ +--TEST-- +POST_INC without use during DFA optimization +--FILE-- + +--EXPECT--