diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 2f4ac5d1..532ff99e 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -598,6 +598,8 @@ class Translator extends \PhpAot\Core\Translator switch ($type) { case 'Expr_Isset': return $this->parseIsset($expr); + case 'Expr_Empty': + return $this->parseEmpty($expr); case 'Expr_Assign': return $this->parseAssign($expr); case 'Expr_AssignRef': @@ -2218,6 +2220,11 @@ class Translator extends \PhpAot\Core\Translator } } + private function parseEmpty(mixed $expr): string + { + return 'php::empty(' . $this->parseExpr($expr->expr) . ')'; + } + private function parseCastArray(mixed $expr): string { return $this->convertArrayExpr($this->parseIdentifier($expr->expr)); diff --git a/tests/core/lang/empty_variation.phpt b/tests/core/lang/empty_variation.phpt new file mode 100644 index 00000000..78b72d1a --- /dev/null +++ b/tests/core/lang/empty_variation.phpt @@ -0,0 +1,14 @@ +--TEST-- +empty() on array elements +--FILE-- + '0', 'empty' => '0'); +var_dump(empty($a['empty'])); +var_dump(empty($a[0])); +$b='0'; +var_dump(empty($b)); +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/tests/core/lang/foreachLoop.004.phpt b/tests/core/lang/foreachLoop.004.phpt new file mode 100644 index 00000000..21283c9c --- /dev/null +++ b/tests/core/lang/foreachLoop.004.phpt @@ -0,0 +1,76 @@ +--TEST-- +Foreach loop tests - using an array element as the $value +--FILE-- +$v[0]) { + var_dump($k, $v); +} +var_dump($a); +var_dump($k, $v); +?> +--EXPECT-- +array(1) { + [0]=> + string(1) "a" +} +array(1) { + [0]=> + string(1) "b" +} +array(1) { + [0]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(1) { + [0]=> + string(1) "c" +} + +int(0) +array(1) { + [0]=> + string(1) "a" +} +int(1) +array(1) { + [0]=> + string(1) "b" +} +int(2) +array(1) { + [0]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +int(2) +array(1) { + [0]=> + string(1) "c" +} diff --git a/tests/core/lang/string_decimals_001.phpt b/tests/core/lang/string_decimals_001.phpt new file mode 100644 index 00000000..0eec0ed2 --- /dev/null +++ b/tests/core/lang/string_decimals_001.phpt @@ -0,0 +1,44 @@ +--TEST-- +String conversion with multiple decimal points +--FILE-- + Testing $str:\n"; + var_dump((int)$str); + var_dump((float)$str); + var_dump($str > 0); +} + +function main() { + test("..9"); + test(".9."); + test("9.."); + test("9.9."); + test("9.9.9"); +} +?> +--EXPECT-- +--> Testing ..9: +int(0) +float(0) +bool(false) + +--> Testing .9.: +int(0) +float(0.9) +bool(false) + +--> Testing 9..: +int(9) +float(9) +bool(true) + +--> Testing 9.9.: +int(9) +float(9.9) +bool(true) + +--> Testing 9.9.9: +int(9) +float(9.9) +bool(true) diff --git a/tests/core/lang/throw_variation_001.phpt b/tests/core/lang/throw_variation_001.phpt new file mode 100644 index 00000000..abe65839 --- /dev/null +++ b/tests/core/lang/throw_variation_001.phpt @@ -0,0 +1,13 @@ +--TEST-- +Catching an exception thrown from an included file +--FILE-- + +--EXPECT-- +caught exception diff --git a/tests/core/lang/zend_throw_exception_001.phpt b/tests/core/lang/zend_throw_exception_001.phpt new file mode 100644 index 00000000..bfe4dd64 --- /dev/null +++ b/tests/core/lang/zend_throw_exception_001.phpt @@ -0,0 +1,13 @@ +--TEST-- +zend_throw_exception with NULL message +--FILE-- + +--EXPECT-- +Done