diff options
Diffstat (limited to 'Zend/tests')
74 files changed, 1945 insertions, 68 deletions
diff --git a/Zend/tests/add_006.phpt b/Zend/tests/add_006.phpt index d56df2f329..fe1c0830e2 100644 --- a/Zend/tests/add_006.phpt +++ b/Zend/tests/add_006.phpt @@ -38,11 +38,19 @@ var_dump($c); echo "Done\n"; ?> --EXPECTF-- + +Warning: A non-numeric value encountered in %s on line %d int(75636) + +Notice: A non well formed numeric value encountered in %s on line %d int(951858) int(48550510) float(75661.68) + +Warning: A non-numeric value encountered in %s on line %d int(75636) + +Notice: A non well formed numeric value encountered in %s on line %d int(951858) int(48550510) float(75661.68) diff --git a/Zend/tests/add_007.phpt b/Zend/tests/add_007.phpt index 66f5405706..089b24ae0b 100644 --- a/Zend/tests/add_007.phpt +++ b/Zend/tests/add_007.phpt @@ -19,8 +19,13 @@ var_dump($c); echo "Done\n"; ?> --EXPECTF-- + +Warning: A non-numeric value encountered in %s on line %d + Exception: Unsupported operand types +Warning: A non-numeric value encountered in %s on line %d + Fatal error: Uncaught Error: Unsupported operand types in %s:%d Stack trace: #0 {main} diff --git a/Zend/tests/anon/013.phpt b/Zend/tests/anon/013.phpt new file mode 100644 index 0000000000..72ba3d61b7 --- /dev/null +++ b/Zend/tests/anon/013.phpt @@ -0,0 +1,15 @@ +--TEST-- +closure binding to anonymous class +--FILE-- +<?php +$class = new class {}; +$foo = function() { + return $this; +}; + +$closure = Closure::bind($foo, $class, $class); +var_dump($closure()); +?> +--EXPECTF-- +object(class@anonymous)#1 (0) { +} diff --git a/Zend/tests/anon/014.phpt b/Zend/tests/anon/014.phpt new file mode 100644 index 0000000000..cacac47857 --- /dev/null +++ b/Zend/tests/anon/014.phpt @@ -0,0 +1,16 @@ +--TEST-- +anonymous class trait binding +--FILE-- +<?php +trait TaskTrait { + function run() { + return 'Running...'; + } +} +$class = new class() { + use TaskTrait; +}; +var_dump($class->run()); +?> +--EXPECTF-- +string(10) "Running..." diff --git a/Zend/tests/bug29883.phpt b/Zend/tests/bug29883.phpt index c92f147ff7..b6ad99aeaf 100644 --- a/Zend/tests/bug29883.phpt +++ b/Zend/tests/bug29883.phpt @@ -3,7 +3,7 @@ Bug #29883 (isset gives invalid values on strings) --FILE-- <?php $x = "bug"; -var_dump(isset($x[-1])); +var_dump(isset($x[-10])); var_dump(isset($x["1"])); echo $x["1"]."\n"; ?> diff --git a/Zend/tests/bug31098.phpt b/Zend/tests/bug31098.phpt index 23cec9bbf4..31823a1aa5 100644 --- a/Zend/tests/bug31098.phpt +++ b/Zend/tests/bug31098.phpt @@ -18,7 +18,7 @@ var_dump(isset($a['b'])); $simpleString = "Bogus String Text"; echo isset($simpleString->wrong)?"bug\n":"ok\n"; echo isset($simpleString["wrong"])?"bug\n":"ok\n"; -echo isset($simpleString[-1])?"bug\n":"ok\n"; +echo isset($simpleString[-20])?"bug\n":"ok\n"; echo isset($simpleString[0])?"ok\n":"bug\n"; echo isset($simpleString["0"])?"ok\n":"bug\n"; echo isset($simpleString["16"])?"ok\n":"bug\n"; diff --git a/Zend/tests/bug41813.phpt b/Zend/tests/bug41813.phpt index 0bb693075a..9a609d09c8 100644 --- a/Zend/tests/bug41813.phpt +++ b/Zend/tests/bug41813.phpt @@ -9,7 +9,7 @@ $foo[0]->bar = "xyz"; echo "Done\n"; ?> --EXPECTF-- -Fatal error: Uncaught Error: Cannot use string offset as an array in %s:%d +Fatal error: Uncaught Error: Cannot use string offset as an object in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/bug49866.phpt b/Zend/tests/bug49866.phpt index 3d96a59cd5..0b7c224c01 100644 --- a/Zend/tests/bug49866.phpt +++ b/Zend/tests/bug49866.phpt @@ -7,7 +7,7 @@ $b = &$a[1]; $b = "f"; echo $a; --EXPECTF-- -Fatal error: Uncaught Error: Cannot create references to/from string offsets nor overloaded objects in %sbug49866.php:3 +Fatal error: Uncaught Error: Cannot create references to/from string offsets in %sbug49866.php:3 Stack trace: #0 {main} thrown in %sbug49866.php on line 3 diff --git a/Zend/tests/bug52879.phpt b/Zend/tests/bug52879.phpt index 0193be4b45..6c3232f32d 100644 --- a/Zend/tests/bug52879.phpt +++ b/Zend/tests/bug52879.phpt @@ -8,7 +8,7 @@ class MyClass { $this->myRef = $value; } } -$myGlobal=new MyClass($myGlobal); +$myGlobal=new MyClass(); $myGlobal->myRef=&$myGlobal; $myGlobal->myNonExistentProperty="ok\n"; echo $myGlobal; diff --git a/Zend/tests/bug62814.phpt b/Zend/tests/bug62814.phpt new file mode 100644 index 0000000000..6646aa283f --- /dev/null +++ b/Zend/tests/bug62814.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #62814: It is possible to stiffen child class members visibility +--FILE-- +<?php + +class A { + private function test() { } +} + +class B extends A { + protected function test() { } +} + +class C extends B { + private function test() { } +} + +?> +--EXPECTF-- +Fatal error: Access level to C::test() must be protected (as in class B) or weaker in %s on line %d diff --git a/Zend/tests/bug68652.phpt b/Zend/tests/bug68652.phpt index e86312ba63..8e54af2e34 100644 --- a/Zend/tests/bug68652.phpt +++ b/Zend/tests/bug68652.phpt @@ -28,6 +28,7 @@ class Bar { } public function __destruct() { + if (!isset(self::$instance)) return; Foo::getInstance(); } } diff --git a/Zend/tests/bug69989_2.phpt b/Zend/tests/bug69989_2.phpt new file mode 100644 index 0000000000..a6f320da3b --- /dev/null +++ b/Zend/tests/bug69989_2.phpt @@ -0,0 +1,42 @@ +--TEST-- +Collection of some cycles on unfinished generators +--FILE-- +<?php + +// CV +function gen1() { + $gen = yield; + yield; +} + +$gen = gen1(); +$gen->send($gen); + +// This +class Test { + public $gen; + public function gen2() { + yield; + } +} + +$test = new Test; +$test->gen = $test->gen2(); + +// Closure object +$gen3 = (function() use (&$gen3) { + yield; +})(); + +// Yield from array +function gen4() { + yield from [yield]; +} + +$gen = gen4(); +$gen->send($gen); + +?> +===DONE=== +--EXPECT-- +===DONE=== diff --git a/Zend/tests/bug69989_3.phpt b/Zend/tests/bug69989_3.phpt new file mode 100644 index 0000000000..260819197b --- /dev/null +++ b/Zend/tests/bug69989_3.phpt @@ -0,0 +1,44 @@ +--TEST-- +Generator cycle collection edge cases +--FILE-- +<?php + +// Extra args +function gen1() { + yield; +} +$obj = new stdClass; +$obj->gen = gen1($obj); + +// Symtable +function gen2() { + $varName = 'a'; + $$varName = yield; + yield; +} +$gen = gen2(); +$gen->send($gen); + +// Symtable indirect +function gen3() { + $varName = 'a'; + $$varName = 42; + $var = yield; + yield; +} +$gen = gen3(); +$gen->send($gen); + +// Yield from root +function gen4() { + yield from yield; +} +$gen = gen4(); +$gen2 = gen4($gen); +$gen2->send([1, 2, 3]); +$gen->send($gen2); + +?> +===DONE=== +--EXPECT-- +===DONE=== diff --git a/Zend/tests/bug70089.phpt b/Zend/tests/bug70089.phpt index c61db00c9e..e1884d9dac 100644 --- a/Zend/tests/bug70089.phpt +++ b/Zend/tests/bug70089.phpt @@ -34,4 +34,4 @@ try { string(36) "Cannot use string offset as an array" string(27) "Cannot unset string offsets" string(41) "Only variables can be passed by reference" -string(64) "Cannot increment/decrement overloaded objects nor string offsets" +string(41) "Cannot increment/decrement string offsets" diff --git a/Zend/tests/bug70918.phpt b/Zend/tests/bug70918.phpt new file mode 100644 index 0000000000..81e2192d8a --- /dev/null +++ b/Zend/tests/bug70918.phpt @@ -0,0 +1,47 @@ +--TEST-- +Bug #70918 (Segfault using static outside of class scope) +--FILE-- +<?php +try { + static::x; +} catch (Error $e) { + var_dump($e->getMessage()); +} + +try { + parent::x; +} catch (Error $e) { + var_dump($e->getMessage()); +} + +try { + self::x; +} catch (Error $e) { + var_dump($e->getMessage()); +} + +try { + new static; +} catch (Error $e) { + var_dump($e->getMessage()); +} + +try { + static::x(); +} catch (Error $e) { + var_dump($e->getMessage()); +} + +try { + static::$i; +} catch (Error $e) { + var_dump($e->getMessage()); +} +?> +--EXPECT-- +string(52) "Cannot access static:: when no class scope is active" +string(52) "Cannot access parent:: when no class scope is active" +string(50) "Cannot access self:: when no class scope is active" +string(52) "Cannot access static:: when no class scope is active" +string(52) "Cannot access static:: when no class scope is active" +string(52) "Cannot access static:: when no class scope is active" diff --git a/Zend/tests/bug71196.phpt b/Zend/tests/bug71196.phpt new file mode 100644 index 0000000000..ca25f9f4fc --- /dev/null +++ b/Zend/tests/bug71196.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #71196 (Memory leak with out-of-order live ranges) +--FILE-- +<?php +try { + $a = "1"; + [1, (y().$a.$a) . ($a.$a)]; +} catch (Error $e) { + var_dump($e->getMessage()); +} +?> +--EXPECT-- +string(30) "Call to undefined function y()" diff --git a/Zend/tests/bug71572.phpt b/Zend/tests/bug71572.phpt new file mode 100644 index 0000000000..4a823ec72f --- /dev/null +++ b/Zend/tests/bug71572.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #71572: String offset assignment from an empty string inserts null byte +--FILE-- +<?php + +$str = "abc"; +var_dump($str{0} = ""); +var_dump($str{1} = ""); +var_dump($str{3} = ""); +var_dump($str{10} = ""); +var_dump($str); +?> +==DONE== +--EXPECTF-- +Warning: Cannot assign an empty string to a string offset in %s on line %d +NULL + +Warning: Cannot assign an empty string to a string offset in %s on line %d +NULL + +Warning: Cannot assign an empty string to a string offset in %s on line %d +NULL + +Warning: Cannot assign an empty string to a string offset in %s on line %d +NULL +string(3) "abc" +==DONE==
\ No newline at end of file diff --git a/Zend/tests/closure_use_auto_global.phpt b/Zend/tests/closure_use_auto_global.phpt new file mode 100644 index 0000000000..9ab0897e12 --- /dev/null +++ b/Zend/tests/closure_use_auto_global.phpt @@ -0,0 +1,16 @@ +--TEST-- +Cannot use() auto-global +--FILE-- +<?php + +function test() { + $fn = function() use($GLOBALS) { + var_dump($GLOBALS); + }; + $fn(); +} +test(); + +?> +--EXPECTF-- +Fatal error: Cannot use auto-global as lexical variable in %s on line %d diff --git a/Zend/tests/closure_use_parameter_name.phpt b/Zend/tests/closure_use_parameter_name.phpt new file mode 100644 index 0000000000..7ecc6d8dd1 --- /dev/null +++ b/Zend/tests/closure_use_parameter_name.phpt @@ -0,0 +1,14 @@ +--TEST-- +Can't use name of lexical variable for parameter +--FILE-- +<?php + +$a = 1; +$fn = function ($a) use ($a) { + var_dump($a); +}; +$fn(2); + +?> +--EXPECTF-- +Fatal error: Cannot use lexical variable $a as a parameter name in %s on line %d diff --git a/Zend/tests/closure_use_variable_twice.phpt b/Zend/tests/closure_use_variable_twice.phpt new file mode 100644 index 0000000000..06c2645809 --- /dev/null +++ b/Zend/tests/closure_use_variable_twice.phpt @@ -0,0 +1,15 @@ +--TEST-- +Closure cannot use one variable twice +--FILE-- +<?php + +$a = 1; +$fn = function() use ($a, &$a) { + $a = 2; +}; +$fn(); +var_dump($a); + +?> +--EXPECTF-- +Fatal error: Cannot use variable $a twice in %s on line %d diff --git a/Zend/tests/constant_expressions_dynamic.phpt b/Zend/tests/constant_expressions_dynamic.phpt index d4e06ee258..b0ba3a5b19 100644 --- a/Zend/tests/constant_expressions_dynamic.phpt +++ b/Zend/tests/constant_expressions_dynamic.phpt @@ -42,7 +42,9 @@ var_dump( ); ?> ---EXPECT-- +--EXPECTF-- + +Warning: A non-numeric value encountered in %s on line %d int(3) string(4) "1foo" bool(false) diff --git a/Zend/tests/empty_str_offset.phpt b/Zend/tests/empty_str_offset.phpt index 486c052dc4..49e175dd21 100644 --- a/Zend/tests/empty_str_offset.phpt +++ b/Zend/tests/empty_str_offset.phpt @@ -8,6 +8,8 @@ print "- empty ---\n"; $str = "test0123"; var_dump(empty($str[-1])); +var_dump(empty($str[-10])); +var_dump(empty($str[-4])); // 0 var_dump(empty($str[0])); var_dump(empty($str[1])); var_dump(empty($str[4])); // 0 @@ -17,6 +19,8 @@ var_dump(empty($str[10000])); // non-numeric offsets print "- string ---\n"; var_dump(empty($str['-1'])); +var_dump(empty($str['-10'])); +var_dump(empty($str['-4'])); // 0 var_dump(empty($str['0'])); var_dump(empty($str['1'])); var_dump(empty($str['4'])); // 0 @@ -31,6 +35,8 @@ print "- null ---\n"; var_dump(empty($str[null])); print "- double ---\n"; var_dump(empty($str[-1.1])); +var_dump(empty($str[-10.5])); +var_dump(empty($str[-4.1])); var_dump(empty($str[-0.8])); var_dump(empty($str[-0.1])); var_dump(empty($str[0.2])); @@ -50,6 +56,8 @@ print "done\n"; ?> --EXPECTF-- - empty --- +bool(false) +bool(true) bool(true) bool(false) bool(false) @@ -58,6 +66,8 @@ bool(false) bool(true) bool(true) - string --- +bool(false) +bool(true) bool(true) bool(false) bool(false) @@ -72,6 +82,8 @@ bool(true) - null --- bool(false) - double --- +bool(false) +bool(true) bool(true) bool(false) bool(false) diff --git a/Zend/tests/foreach_list_keyed.phpt b/Zend/tests/foreach_list_keyed.phpt new file mode 100644 index 0000000000..f5fab4e342 --- /dev/null +++ b/Zend/tests/foreach_list_keyed.phpt @@ -0,0 +1,36 @@ +--TEST-- +foreach with list syntax, keyed +--FILE-- +<?php + +$points = [ + ["x" => 1, "y" => 2], + ["x" => 2, "y" => 1] +]; + +foreach ($points as list("x" => $x, "y" => $y)) { + var_dump($x, $y); +} + +echo PHP_EOL; + +$invertedPoints = [ + "x" => [1, 2], + "y" => [2, 1] +]; + +foreach ($invertedPoints as list(0 => $row1, 1 => $row2)) { + var_dump($row1, $row2); +} + +?> +--EXPECT-- +int(1) +int(2) +int(2) +int(1) + +int(1) +int(2) +int(2) +int(1) diff --git a/Zend/tests/func_get_args.phpt b/Zend/tests/func_get_args.phpt new file mode 100644 index 0000000000..eea8ae4354 --- /dev/null +++ b/Zend/tests/func_get_args.phpt @@ -0,0 +1,10 @@ +--TEST-- +Testing func_get_args() +--FILE-- +<?php + +func_get_args(); + +?> +--EXPECTF-- +Warning: func_get_args(): Called from the global scope - no function context in %s on line 3 diff --git a/Zend/tests/global_with_side_effect_name.phpt b/Zend/tests/global_with_side_effect_name.phpt new file mode 100644 index 0000000000..a1ee240c48 --- /dev/null +++ b/Zend/tests/global_with_side_effect_name.phpt @@ -0,0 +1,22 @@ +--TEST-- +Global variable import using a name with side effects +--FILE-- +<?php + +function sf($arg) { + echo "called\n"; + return $arg; +} + +function test() { + global ${sf("a")}; + var_dump($a); +} + +$a = 42; +test(); + +?> +--EXPECT-- +called +int(42) diff --git a/Zend/tests/int_conversion_exponents.phpt b/Zend/tests/int_conversion_exponents.phpt new file mode 100644 index 0000000000..d924cb7b81 --- /dev/null +++ b/Zend/tests/int_conversion_exponents.phpt @@ -0,0 +1,52 @@ +--TEST-- +Integer conversion from scientific notation +--FILE-- +<?php + +var_dump((int)"1.2345e9"); +var_dump((int)"-1.2345e9"); +var_dump(intval("1.2345e9")); +var_dump(intval("-1.2345e9")); +var_dump("1.2345e9" % PHP_INT_MAX); +var_dump("-1.2345e9" % PHP_INT_MIN); +var_dump("1.2345e9" | 0); +var_dump("-1.2345e9" | 0); + +echo PHP_EOL; + +var_dump((int)" 1.2345e9 abc"); +var_dump((int)" -1.2345e9 abc"); +var_dump(intval(" 1.2345e9 abc")); +var_dump(intval(" -1.2345e9 abc")); +var_dump(" 1.2345e9 abc" % PHP_INT_MAX); +var_dump(" -1.2345e9 abc" % PHP_INT_MIN); +var_dump(" 1.2345e9 abc" | 0); +var_dump(" -1.2345e9 abc" | 0); + +?> +--EXPECTF-- +int(1234500000) +int(-1234500000) +int(1234500000) +int(-1234500000) +int(1234500000) +int(-1234500000) +int(1234500000) +int(-1234500000) + +int(1234500000) +int(-1234500000) +int(1234500000) +int(-1234500000) + +Notice: A non well formed numeric value encountered in %s on line %d +int(1234500000) + +Notice: A non well formed numeric value encountered in %s on line %d +int(-1234500000) + +Notice: A non well formed numeric value encountered in %s on line %d +int(1234500000) + +Notice: A non well formed numeric value encountered in %s on line %d +int(-1234500000) diff --git a/Zend/tests/isset_str_offset.phpt b/Zend/tests/isset_str_offset.phpt index 7a9164a381..d693f80a52 100644 --- a/Zend/tests/isset_str_offset.phpt +++ b/Zend/tests/isset_str_offset.phpt @@ -8,6 +8,7 @@ print "- isset ---\n"; $str = "test0123"; var_dump(isset($str[-1])); +var_dump(isset($str[-10])); var_dump(isset($str[0])); var_dump(isset($str[1])); var_dump(isset($str[4])); // 0 @@ -17,6 +18,7 @@ var_dump(isset($str[10000])); // non-numeric offsets print "- string ---\n"; var_dump(isset($str['-1'])); +var_dump(isset($str['-10'])); var_dump(isset($str['0'])); var_dump(isset($str['1'])); var_dump(isset($str['4'])); // 0 @@ -31,6 +33,7 @@ print "- null ---\n"; var_dump(isset($str[null])); print "- double ---\n"; var_dump(isset($str[-1.1])); +var_dump(isset($str[-10.5])); var_dump(isset($str[-0.8])); var_dump(isset($str[-0.1])); var_dump(isset($str[0.2])); @@ -50,6 +53,7 @@ print "done\n"; ?> --EXPECTF-- - isset --- +bool(true) bool(false) bool(true) bool(true) @@ -58,6 +62,7 @@ bool(true) bool(false) bool(false) - string --- +bool(true) bool(false) bool(true) bool(true) @@ -72,6 +77,7 @@ bool(false) - null --- bool(true) - double --- +bool(true) bool(false) bool(true) bool(true) diff --git a/Zend/tests/jump16.phpt b/Zend/tests/jump16.phpt new file mode 100644 index 0000000000..cc820c4a6c --- /dev/null +++ b/Zend/tests/jump16.phpt @@ -0,0 +1,27 @@ +--TEST-- +jump 16: goto into try/catch +--FILE-- +<?php +goto a; +try { + echo "1"; +a: + echo "2"; + throw new Exception(); +} catch (Exception $e) { + echo "3"; +} +echo "4"; +goto b; +try { + echo "5"; + throw new Exception(); +} catch (Exception $e) { + echo "6"; +b: + echo "7"; +} +echo "8\n"; +?> +--EXPECT-- +23478 diff --git a/Zend/tests/jump17.phpt b/Zend/tests/jump17.phpt new file mode 100644 index 0000000000..92d3be511b --- /dev/null +++ b/Zend/tests/jump17.phpt @@ -0,0 +1,22 @@ +--TEST-- +jump 17: goto into try/catch with finally +--FILE-- +<?php +goto b; +try { + echo "1"; +a: + echo "2"; + throw new Exception(); +} catch (Exception $e) { + echo "3"; +b: + echo "4"; +} finally { + echo "5"; +c: + echo "6"; +} +echo "7\n"; +--EXPECT-- +4567 diff --git a/Zend/tests/list_keyed.phpt b/Zend/tests/list_keyed.phpt new file mode 100644 index 0000000000..b549ed9bf5 --- /dev/null +++ b/Zend/tests/list_keyed.phpt @@ -0,0 +1,71 @@ +--TEST-- +list() with keys +--FILE-- +<?php + +$antonyms = [ + "good" => "bad", + "happy" => "sad", +]; + +list("good" => $good_antonym, "happy" => $happy_antonym) = $antonyms; +var_dump($good_antonym, $happy_antonym); + +echo PHP_EOL; + +$powersOfTwo = [ + 1 => 2, + 2 => 4, + 3 => 8 +]; + +list(1 => $two_1, 2 => $two_2, 3 => $two_3) = $powersOfTwo; +var_dump($two_1, $two_2, $two_3); + +echo PHP_EOL; + +$contrivedMixedKeyTypesExample = [ + 7 => "the best PHP version", + "elePHPant" => "the cutest mascot" +]; + +list(7 => $seven, "elePHPant" => $elePHPant) = $contrivedMixedKeyTypesExample; +var_dump($seven, $elePHPant); + +echo PHP_EOL; + +$allTogetherNow = [ + "antonyms" => $antonyms, + "powersOfTwo" => $powersOfTwo, + "contrivedMixedKeyTypesExample" => $contrivedMixedKeyTypesExample +]; + +list( + "antonyms" => list("good" => $good_antonym, "happy" => $happy_antonym), + "powersOfTwo" => list(1 => $two_1, 2 => $two_2, 3 => $two_3), + "contrivedMixedKeyTypesExample" => list(7 => $seven, "elePHPant" => $elePHPant) +) = $allTogetherNow; + +var_dump($good_antonym, $happy_antonym); +var_dump($two_1, $two_2, $two_3); +var_dump($seven, $elePHPant); + +?> +--EXPECT-- +string(3) "bad" +string(3) "sad" + +int(2) +int(4) +int(8) + +string(20) "the best PHP version" +string(17) "the cutest mascot" + +string(3) "bad" +string(3) "sad" +int(2) +int(4) +int(8) +string(20) "the best PHP version" +string(17) "the cutest mascot" diff --git a/Zend/tests/list_keyed_ArrayAccess.phpt b/Zend/tests/list_keyed_ArrayAccess.phpt new file mode 100644 index 0000000000..1bb2013036 --- /dev/null +++ b/Zend/tests/list_keyed_ArrayAccess.phpt @@ -0,0 +1,54 @@ +--TEST-- +list() with keys and ArrayAccess +--FILE-- +<?php + +$antonymObject = new ArrayObject; +$antonymObject["good"] = "bad"; +$antonymObject["happy"] = "sad"; + +list("good" => $good, "happy" => $happy) = $antonymObject; +var_dump($good, $happy); + +echo PHP_EOL; + +$stdClassCollection = new SplObjectStorage; +$foo = new StdClass; +$stdClassCollection[$foo] = "foo"; +$bar = new StdClass; +$stdClassCollection[$bar] = "bar"; + +list($foo => $fooStr, $bar => $barStr) = $stdClassCollection; +var_dump($fooStr, $barStr); + +echo PHP_EOL; + +class IndexPrinter implements ArrayAccess +{ + public function offsetGet($offset) { + echo "GET "; + var_dump($offset); + } + public function offsetSet($offset, $value) { + } + public function offsetExists($offset) { + } + public function offsetUnset($offset) { + } +} + +$op = new IndexPrinter; +list(123 => $x) = $op; +// PHP shouldn't convert this to an integer offset, because it's ArrayAccess +list("123" => $x) = $op; + +?> +--EXPECT-- +string(3) "bad" +string(3) "sad" + +string(3) "foo" +string(3) "bar" + +GET int(123) +GET string(3) "123" diff --git a/Zend/tests/list_keyed_conversions.phpt b/Zend/tests/list_keyed_conversions.phpt new file mode 100644 index 0000000000..e2cf91a27d --- /dev/null +++ b/Zend/tests/list_keyed_conversions.phpt @@ -0,0 +1,32 @@ +--TEST-- +list() with non-integer-or-string keys +--FILE-- +<?php + +$results = [ + 0 => 0, + 1 => 1, + "" => "" +]; + +list(NULL => $NULL, 1.5 => $float, FALSE => $FALSE, TRUE => $TRUE) = $results; +var_dump($NULL, $float, $FALSE, $TRUE); + +echo PHP_EOL; + +list("0" => $zeroString, "1" => $oneString) = $results; +var_dump($zeroString, $oneString); + +list(STDIN => $resource) = []; + +?> +--EXPECTF-- +string(0) "" +int(1) +int(0) +int(1) + +int(0) +int(1) + +Notice: Resource ID#%d used as offset, casting to integer (%d) in %s on line %d diff --git a/Zend/tests/list_keyed_evaluation_order.inc b/Zend/tests/list_keyed_evaluation_order.inc new file mode 100644 index 0000000000..490a6d84fe --- /dev/null +++ b/Zend/tests/list_keyed_evaluation_order.inc @@ -0,0 +1,60 @@ +<?php declare(strict_types=1); + +// Observer objects for the Zend/tests/list_keyed_evaluation_order.* tests + +class Stringable +{ + private $name; + public function __construct(string $name) { + $this->name = $name; + } + + public function __toString(): string { + echo "$this->name evaluated.", PHP_EOL; + return $this->name; + } +} + +class Indexable implements ArrayAccess +{ + private $array; + public function __construct(array $array) { + $this->array = $array; + } + + public function offsetExists($offset): bool { + echo "Existence of offset $offset checked for.", PHP_EOL; + return isset($this->array[$offset]); + } + + public function offsetUnset($offset): void { + unset($this->array[$offset]); + echo "Offset $offset removed.", PHP_EOL; + } + + public function offsetGet($offset) { + echo "Offset $offset retrieved.", PHP_EOL; + return $this->array[$offset]; + } + + public function offsetSet($offset, $value): void { + $this->array[$offset] = $value; + echo "Offset $offset set to $value.", PHP_EOL; + } +} + +class IndexableRetrievable +{ + private $label; + private $indexable; + + public function __construct(string $label, Indexable $indexable) { + $this->label = $label; + $this->indexable = $indexable; + } + + public function getIndexable(): Indexable { + echo "Indexable $this->label retrieved.", PHP_EOL; + return $this->indexable; + } +} diff --git a/Zend/tests/list_keyed_evaluation_order.phpt b/Zend/tests/list_keyed_evaluation_order.phpt new file mode 100644 index 0000000000..0f0652b6a9 --- /dev/null +++ b/Zend/tests/list_keyed_evaluation_order.phpt @@ -0,0 +1,35 @@ +--TEST-- +list() with keys, evaluation order +--FILE-- +<?php + +require_once "list_keyed_evaluation_order.inc"; + +$a = new Stringable("A"); +$c = new Stringable("C"); + +$e = new IndexableRetrievable("E", new Indexable(["A" => "value for offset A", "C" => "value for offset C"])); + +$store = new Indexable([]); + +// list($a => $b, $c => $d) = $e; +// Should be evaluated in the order: +// 1. Evaluate $e +// 2. Evaluate $a +// 3. Evaluate $e[$a] +// 4. Assign $b from $e[$a] +// 5. Evaluate $c +// 6. Evaluate $e[$c] +// 7. Assign $c from $e[$a] + +list((string)$a => $store["B"], (string)$c => $store["D"]) = $e->getIndexable(); + +?> +--EXPECT-- +Indexable E retrieved. +A evaluated. +Offset A retrieved. +Offset B set to value for offset A. +C evaluated. +Offset C retrieved. +Offset D set to value for offset C. diff --git a/Zend/tests/list_keyed_evaluation_order_2.phpt b/Zend/tests/list_keyed_evaluation_order_2.phpt new file mode 100644 index 0000000000..ddfba68c46 --- /dev/null +++ b/Zend/tests/list_keyed_evaluation_order_2.phpt @@ -0,0 +1,77 @@ +--TEST-- +list() with keys, evaluation order #2 +--FILE-- +<?php + +// All the following should print 'a' then 'b' + +list($a, $b) = ['a', 'b']; +var_dump($a); +var_dump($b); + +list(0 => $a, 1 => $b) = ['a', 'b']; +var_dump($a); +var_dump($b); + +list(1 => $b, 0 => $a) = ['a', 'b']; +var_dump($a); +var_dump($b); + +$arr = []; +list($arr[], $arr[]) = ['a', 'b']; +var_dump($arr[0]); +var_dump($arr[1]); + +$arr = []; +list(0 => $arr[], 1 => $arr[]) = ['a', 'b']; +var_dump($arr[0]); +var_dump($arr[1]); + +$arr = []; +list(1 => $arr[], 0 => $arr[]) = ['b', 'a']; +var_dump($arr[0]); +var_dump($arr[1]); + +$arr = []; +list(list(1 => $arr[], 0 => $arr[])) = [['b', 'a']]; +var_dump($arr[0]); +var_dump($arr[1]); + +$arr = []; +list('key1' => $arr[], 'key2' => $arr[]) = ['key2' => 'b', 'key1' => 'a']; +var_dump($arr[0]); +var_dump($arr[1]); + +// This should print 'foo' +$a = 0; +list($a => $a) = ['foo', 'bar']; +var_dump($a); + +// This should print 'bar' then 'foo' +$a = 0; +$b = 1; +list($b => $a, $a => $c) = ['bar' => 'foo', 1 => 'bar']; +var_dump($a); +var_dump($c); + +?> +--EXPECT-- +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(1) "a" +string(1) "b" +string(3) "foo" +string(3) "bar" +string(3) "foo" diff --git a/Zend/tests/list_keyed_evaluation_order_3.phpt b/Zend/tests/list_keyed_evaluation_order_3.phpt new file mode 100644 index 0000000000..7850834c3b --- /dev/null +++ b/Zend/tests/list_keyed_evaluation_order_3.phpt @@ -0,0 +1,24 @@ +--TEST-- +list() with keys, evaluation order #3 +--FILE-- +<?php + +$i = 0; +$a = [ + 0 => [ + 'b' => 'bar', + 'a' => 'foo', + ], + 1 => 'a', + 3 => 'b', +]; +list($a[$i++] => $a[$i++], $a[$i++] => $a[$i++]) = $a[$i++]; +var_dump($i); // should be 5 +var_dump($a[2]); // should be 'foo' +var_dump($a[4]); // should be 'bar' + +?> +--EXPECT-- +int(5) +string(3) "foo" +string(3) "bar" diff --git a/Zend/tests/list_keyed_evaluation_order_nested.phpt b/Zend/tests/list_keyed_evaluation_order_nested.phpt new file mode 100644 index 0000000000..8a7725d4ea --- /dev/null +++ b/Zend/tests/list_keyed_evaluation_order_nested.phpt @@ -0,0 +1,77 @@ +--TEST-- +list() with keys, evaluation order: nested +--FILE-- +<?php + +require_once "list_keyed_evaluation_order.inc"; + +$a = new Stringable("A"); +$c = new Stringable("C"); +$f = new Stringable("F"); +$g = new Stringable("G"); +$i = new Stringable("I"); + +$k = new IndexableRetrievable("K", new Indexable([ + "A" => "offset value for A", + "C" => new Indexable([ + 0 => "offset value for 0", + 1 => "offset value for 1" + ]), + "F" => new Indexable([ + "G" => "offset value for G", + "I" => "offset value for I" + ]) +])); + +$store = new Indexable([]); + +// list($a => $b, $c => list($d, $e), $f => list($g => $h, $i => $j)) = $k; +// Should be evaluated in the order: +// 1. Evaluate $k +// 2. Evaluate $a +// 3. Evaluate $k[$a] +// 4. Assign $b from $k[$a] +// 5. Evaluate $c +// 6. Evaluate $k[$c] +// 7. Evaluate $k[$c][0] +// 8. Assign $d from $k[$c][0] +// 9. Evaluate $k[$c][1] +// 10. Assign $e from $k[$c][1] +// 11. Evaluate $f +// 12. Evaluate $k[$f] +// 13. Evaluate $g +// 14. Evaluate $k[$f][$g] +// 15. Assign $h from $k[$f][$g] +// 16. Evaluate $i +// 17. Evaluate $k[$f][$i] +// 18. Assign $j from $k[$f][$i] + +list( + (string)$a => $store["B"], + (string)$c => list($store["D"], $store["E"]), + (string)$f => list( + (string)$g => $store["H"], + (string)$i => $store["J"] + ) +) = $k->getIndexable(); + +?> +--EXPECT-- +Indexable K retrieved. +A evaluated. +Offset A retrieved. +Offset B set to offset value for A. +C evaluated. +Offset C retrieved. +Offset 0 retrieved. +Offset D set to offset value for 0. +Offset 1 retrieved. +Offset E set to offset value for 1. +F evaluated. +Offset F retrieved. +G evaluated. +Offset G retrieved. +Offset H set to offset value for G. +I evaluated. +Offset I retrieved. +Offset J set to offset value for I. diff --git a/Zend/tests/list_keyed_non_literals.phpt b/Zend/tests/list_keyed_non_literals.phpt new file mode 100644 index 0000000000..80f22eda22 --- /dev/null +++ b/Zend/tests/list_keyed_non_literals.phpt @@ -0,0 +1,30 @@ +--TEST-- +list() with constant keys +--FILE-- +<?php + +$arr = [ + 1 => "one", + 2 => "two", + 3 => "three" +]; + +const COMPILE_TIME_RESOLVABLE = 1; + +define('PROBABLY_NOT_COMPILE_TIME_RESOLVABLE', file_get_contents("data:text/plain,2")); + +$probablyNotCompileTimeResolvable3 = cos(0) * 3; + +list( + COMPILE_TIME_RESOLVABLE => $one, + PROBABLY_NOT_COMPILE_TIME_RESOLVABLE => $two, + $probablyNotCompileTimeResolvable3 => $three +) = $arr; + +var_dump($one, $two, $three); + +?> +--EXPECTF-- +string(3) "one" +string(3) "two" +string(5) "three" diff --git a/Zend/tests/list_keyed_trailing_comma.phpt b/Zend/tests/list_keyed_trailing_comma.phpt new file mode 100644 index 0000000000..e0af0aed21 --- /dev/null +++ b/Zend/tests/list_keyed_trailing_comma.phpt @@ -0,0 +1,38 @@ +--TEST-- +list() with keys and a trailing comma +--FILE-- +<?php + +$antonyms = [ + "good" => "bad", + "happy" => "sad", +]; + +list( + "good" => $good, + "happy" => $happy +) = $antonyms; + +var_dump($good, $happy); + +echo PHP_EOL; + +$antonyms = [ + "good" => "bad", + "happy" => "sad", +]; + +list( + "good" => $good, + "happy" => $happy, +) = $antonyms; + +var_dump($good, $happy); + +?> +--EXPECT-- +string(3) "bad" +string(3) "sad" + +string(3) "bad" +string(3) "sad" diff --git a/Zend/tests/list_keyed_undefined.phpt b/Zend/tests/list_keyed_undefined.phpt new file mode 100644 index 0000000000..a18e3b4d20 --- /dev/null +++ b/Zend/tests/list_keyed_undefined.phpt @@ -0,0 +1,22 @@ +--TEST-- +list() with undefined keys +--FILE-- +<?php + +$contrivedMixedKeyTypesExample = [ + 7 => "the best PHP version", + "elePHPant" => "the cutest mascot" +]; + +list(5 => $five, "duke" => $duke) = $contrivedMixedKeyTypesExample; + +var_dump($five, $duke); + +?> +--EXPECTF-- + +Notice: Undefined offset: 5 in %s on line %d + +Notice: Undefined index: duke in %s on line %d +NULL +NULL diff --git a/Zend/tests/list_mixed_keyed_unkeyed.phpt b/Zend/tests/list_mixed_keyed_unkeyed.phpt new file mode 100644 index 0000000000..5562479fc3 --- /dev/null +++ b/Zend/tests/list_mixed_keyed_unkeyed.phpt @@ -0,0 +1,16 @@ +--TEST-- +list() with both keyed and unkeyed elements +--FILE-- +<?php + +$contrivedKeyedAndUnkeyedArrayExample = [ + 0, + 1 => 1, + "foo" => "bar" +]; + +list($zero, 1 => $one, "foo" => $foo) = $contrivedKeyedAndUnkeyedArrayExample; + +?> +--EXPECTF-- +Parse error: syntax error, unexpected %s in %s on line %d diff --git a/Zend/tests/list_mixed_nested_keyed_unkeyed.phpt b/Zend/tests/list_mixed_nested_keyed_unkeyed.phpt new file mode 100644 index 0000000000..3087775b76 --- /dev/null +++ b/Zend/tests/list_mixed_nested_keyed_unkeyed.phpt @@ -0,0 +1,34 @@ +--TEST-- +list() with nested unkeyed and keyed list() +--FILE-- +<?php + +$points = [ + ["x" => 1, "y" => 2], + ["x" => 2, "y" => 1] +]; + +list(list("x" => $x1, "y" => $y1), list("x" => $x2, "y" => $y2)) = $points; +var_dump($x1, $y1, $x2, $y2); + +echo PHP_EOL; + +$invertedPoints = [ + "x" => [1, 2], + "y" => [2, 1] +]; + +list("x" => list($x1, $x2), "y" => list($y1, $y2)) = $invertedPoints; +var_dump($x1, $y1, $x2, $y2); + +?> +--EXPECT-- +int(1) +int(2) +int(2) +int(1) + +int(1) +int(2) +int(2) +int(1) diff --git a/Zend/tests/new_args_without_ctor.phpt b/Zend/tests/new_args_without_ctor.phpt new file mode 100644 index 0000000000..91456890d2 --- /dev/null +++ b/Zend/tests/new_args_without_ctor.phpt @@ -0,0 +1,10 @@ +--TEST-- +Argument of new on class without constructor are evaluated +--FILE-- +<?php + +new stdClass(print 'a', print 'b'); + +?> +--EXPECT-- +ab diff --git a/Zend/tests/numeric_string_errors.phpt b/Zend/tests/numeric_string_errors.phpt new file mode 100644 index 0000000000..e98c58dda7 --- /dev/null +++ b/Zend/tests/numeric_string_errors.phpt @@ -0,0 +1,195 @@ +--TEST-- +Invalid numeric string E_WARNINGs and E_NOTICEs +--FILE-- +<?php + +var_dump("2 Lorem" + "3 ipsum"); +var_dump("dolor" + "sit"); +echo "---", PHP_EOL; +var_dump("5 amet," - "7 consectetur"); +var_dump("adipiscing" - "elit,"); +echo "---", PHP_EOL; +var_dump("11 sed" * "13 do"); +var_dump("eiusmod" * "tempor"); +echo "---", PHP_EOL; +var_dump("17 incididunt" / "19 ut"); +var_dump("labore" / "et"); +echo "---", PHP_EOL; +var_dump("23 dolore" ** "29 magna"); +var_dump("aliqua." ** "Ut"); +echo "---", PHP_EOL; +var_dump("31 enim" % "37 ad"); +try { + var_dump("minim" % "veniam,"); +} catch (DivisionByZeroError $e) { +} +echo "---", PHP_EOL; +var_dump("41 minim" << "43 veniam,"); +var_dump("quis" << "nostrud"); +echo "---", PHP_EOL; +var_dump("47 exercitation" >> "53 ullamco"); +var_dump("laboris" >> "nisi"); +echo "---", PHP_EOL; +var_dump("59 ut" | 61); +var_dump(67 | "71 aliquip"); +var_dump("ex" | 73); +var_dump(79 | "ea"); +echo "---", PHP_EOL; +var_dump("83 commodo" & 89); +var_dump(97 & "101 consequat."); +var_dump("Duis" & 103); +var_dump(107 & "aute"); +echo "---", PHP_EOL; +var_dump("109 irure" ^ 113); +var_dump(127 ^ "131 dolor"); +var_dump("in" ^ 137); +var_dump(139 ^ "reprehenderit"); +echo "---", PHP_EOL; +var_dump(+"149 in"); +var_dump(+"voluptate"); +echo "---", PHP_EOL; +var_dump(-"151 velit"); +var_dump(-"esse"); +?> +--EXPECTF-- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(5) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(-2) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(143) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +float(0.89473684210526) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d + +Warning: Division by zero in %s on line %d +float(NAN) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +float(3.0910586430935E+39) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(1) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(31) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(%d) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(0) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(63) + +Notice: A non well formed numeric value encountered in %s on line %d +int(71) + +Warning: A non-numeric value encountered in %s on line %d +int(73) + +Warning: A non-numeric value encountered in %s on line %d +int(79) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(81) + +Notice: A non well formed numeric value encountered in %s on line %d +int(97) + +Warning: A non-numeric value encountered in %s on line %d +int(0) + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(28) + +Notice: A non well formed numeric value encountered in %s on line %d +int(252) + +Warning: A non-numeric value encountered in %s on line %d +int(137) + +Warning: A non-numeric value encountered in %s on line %d +int(139) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(149) + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(-151) + +Warning: A non-numeric value encountered in %s on line %d +int(0) diff --git a/Zend/tests/numeric_string_errors_assign.phpt b/Zend/tests/numeric_string_errors_assign.phpt new file mode 100644 index 0000000000..8d882aadcc --- /dev/null +++ b/Zend/tests/numeric_string_errors_assign.phpt @@ -0,0 +1,236 @@ +--TEST-- +Invalid numeric string E_WARNINGs and E_NOTICEs, combined assignment operations +--FILE-- +<?php + +// prevents CT eval +function foxcache($val) { + return [$val][0]; +} + +$a = foxcache("2 Lorem"); +$a += "3 ipsum"; +var_dump($a); +$a = foxcache("dolor"); +$a += "sit"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("5 amet,"); +$a -= "7 consectetur"; +var_dump($a); +$a = foxcache("adipiscing"); +$a -= "elit,"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("11 sed"); +$a *= "13 do"; +var_dump($a); +$a = foxcache("eiusmod"); +$a *= "tempor"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("17 incididunt"); +$a /= "19 ut"; +var_dump($a); +$a = foxcache("labore"); +$a /= "et"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("23 dolore"); +$a **= "29 magna"; +var_dump($a); +$a = foxcache("aliqua."); +$a **= "Ut"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("31 enim"); +$a %= "37 ad"; +var_dump($a); +try { + $a = foxcache("minim"); + $a %= "veniam,"; + var_dump($a); +} catch (DivisionByZeroError $e) { +} +echo "---", PHP_EOL; +$a = foxcache("41 minim"); +$a <<= "43 veniam,"; +var_dump($a); +$a = foxcache("quis"); +$a <<= "nostrud"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("47 exercitation"); +$a >>= "53 ullamco"; +var_dump($a); +$a = foxcache("laboris"); +$a >>= "nisi"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("59 ut"); +$a |= 61; +var_dump($a); +$a = foxcache(67); +$a |= "71 aliquip"; +var_dump($a); +$a = foxcache("ex"); +$a |= 73; +var_dump($a); +$a = foxcache(79); +$a |= "ea"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("83 commodo"); +$a &= 89; +var_dump($a); +$a = foxcache(97); +$a &= "101 consequat."; +var_dump($a); +$a = foxcache("Duis"); +$a &= 103; +var_dump($a); +$a = foxcache(107); +$a &= "aute"; +var_dump($a); +echo "---", PHP_EOL; +$a = foxcache("109 irure"); +$a ^= 113; +var_dump($a); +$a = foxcache(127); +$a ^= "131 dolor"; +var_dump($a); +$a = foxcache("in"); +$a ^= 137; +var_dump($a); +$a = foxcache(139); +$a ^= "reprehenderit"; +var_dump($a); +?> +--EXPECTF-- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(5) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(-2) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(143) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +float(0.89473684210526) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d + +Warning: Division by zero in %s on line %d +float(NAN) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +float(3.0910586430935E+39) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(1) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(31) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(%d) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d + +Notice: A non well formed numeric value encountered in %s on line %d +int(0) + +Warning: A non-numeric value encountered in %s on line %d + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(63) + +Notice: A non well formed numeric value encountered in %s on line %d +int(71) + +Warning: A non-numeric value encountered in %s on line %d +int(73) + +Warning: A non-numeric value encountered in %s on line %d +int(79) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(81) + +Notice: A non well formed numeric value encountered in %s on line %d +int(97) + +Warning: A non-numeric value encountered in %s on line %d +int(0) + +Warning: A non-numeric value encountered in %s on line %d +int(0) +--- + +Notice: A non well formed numeric value encountered in %s on line %d +int(28) + +Notice: A non well formed numeric value encountered in %s on line %d +int(252) + +Warning: A non-numeric value encountered in %s on line %d +int(137) + +Warning: A non-numeric value encountered in %s on line %d +int(139) diff --git a/Zend/tests/overloaded_func_001.phpt b/Zend/tests/overloaded_func_001.phpt new file mode 100644 index 0000000000..2702772a46 --- /dev/null +++ b/Zend/tests/overloaded_func_001.phpt @@ -0,0 +1,15 @@ +--TEST-- +Overloaded function 001 +--SKIPIF-- +<?php +if (!PHP_DEBUG) die("skip only run in debug version"); +?> +--FILE-- +<?php +var_dump(_ZendTestClass::test()); +?> +--EXPECTF-- +Fatal error: Uncaught Error: Cannot call overloaded function for non-object in %soverloaded_func_001.php:%d +Stack trace: +#0 {main} + thrown in %soverloaded_func_001.php on line %d diff --git a/Zend/tests/overloaded_func_002.phpt b/Zend/tests/overloaded_func_002.phpt new file mode 100644 index 0000000000..6c16965919 --- /dev/null +++ b/Zend/tests/overloaded_func_002.phpt @@ -0,0 +1,13 @@ +--TEST-- +Overloaded function 002 +--SKIPIF-- +<?php +if (!PHP_DEBUG) die("skip only run in debug version"); +?> +--FILE-- +<?php +$a = new _ZendTestClass(); +var_dump($a->{trim(" test")}()); +?> +--EXPECT-- +string(4) "test" diff --git a/Zend/tests/return_types/void_allowed.phpt b/Zend/tests/return_types/void_allowed.phpt new file mode 100644 index 0000000000..8f07c7392e --- /dev/null +++ b/Zend/tests/return_types/void_allowed.phpt @@ -0,0 +1,20 @@ +--TEST-- +void return type: acceptable cases +--FILE-- +<?php + +function foo(): void { + // okay +} + +foo(); + +function bar(): void { + return; // okay +} + +bar(); + +echo "OK!", PHP_EOL; +--EXPECT-- +OK! diff --git a/Zend/tests/return_types/void_disallowed1.phpt b/Zend/tests/return_types/void_disallowed1.phpt new file mode 100644 index 0000000000..b20f129a58 --- /dev/null +++ b/Zend/tests/return_types/void_disallowed1.phpt @@ -0,0 +1,12 @@ +--TEST-- +void return type: unacceptable cases: explicit NULL return +--FILE-- +<?php + +function foo(): void { + return NULL; // not permitted in a void function +} + +// Note the lack of function call: function validated at compile-time +--EXPECTF-- +Fatal error: A void function must not return a value in %s on line %d diff --git a/Zend/tests/return_types/void_disallowed2.phpt b/Zend/tests/return_types/void_disallowed2.phpt new file mode 100644 index 0000000000..7bbc3ac24f --- /dev/null +++ b/Zend/tests/return_types/void_disallowed2.phpt @@ -0,0 +1,12 @@ +--TEST-- +void return type: unacceptable cases: explicit return of some other value +--FILE-- +<?php + +function foo(): void { + return -1; // not permitted in a void function +} + +// Note the lack of function call: function validated at compile-time +--EXPECTF-- +Fatal error: A void function must not return a value in %s on line %d diff --git a/Zend/tests/return_types/void_parameter.phpt b/Zend/tests/return_types/void_parameter.phpt new file mode 100644 index 0000000000..4c6e918406 --- /dev/null +++ b/Zend/tests/return_types/void_parameter.phpt @@ -0,0 +1,8 @@ +--TEST-- +void return type: not valid as a parameter type +--FILE-- +<?php + +function foobar(void $a) {} +--EXPECTF-- +Fatal error: void cannot be used as a parameter type in %s on line %d diff --git a/Zend/tests/self_and.phpt b/Zend/tests/self_and.phpt index cdcde77992..44db877e92 100644 --- a/Zend/tests/self_and.phpt +++ b/Zend/tests/self_and.phpt @@ -20,6 +20,10 @@ echo "Done\n"; ?> --EXPECTF-- int(18) + +Warning: A non-numeric value encountered in %s on line %d int(0) + +Notice: A non well formed numeric value encountered in %s on line %d int(33) Done diff --git a/Zend/tests/self_instanceof_outside_class.phpt b/Zend/tests/self_instanceof_outside_class.phpt new file mode 100644 index 0000000000..4caef37883 --- /dev/null +++ b/Zend/tests/self_instanceof_outside_class.phpt @@ -0,0 +1,17 @@ +--TEST-- +instanceof self outside a class +--FILE-- +<?php + +$fn = function() { + try { + new stdClass instanceof self; + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } +}; +$fn(); + +?> +--EXPECT-- +Cannot access self:: when no class scope is active diff --git a/Zend/tests/self_method_or_prop_outside_class.phpt b/Zend/tests/self_method_or_prop_outside_class.phpt new file mode 100644 index 0000000000..e4a499def8 --- /dev/null +++ b/Zend/tests/self_method_or_prop_outside_class.phpt @@ -0,0 +1,36 @@ +--TEST-- +Accessing self:: properties or methods outside a class +--FILE-- +<?php + +$fn = function() { + $str = "foo"; + try { + self::${$str . "bar"}; + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } + try { + unset(self::${$str . "bar"}); + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } + try { + isset(self::${$str . "bar"}); + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } + try { + self::{$str . "bar"}(); + } catch (Error $e) { + echo $e->getMessage(), "\n"; + } +}; +$fn(); + +?> +--EXPECT-- +Cannot access self:: when no class scope is active +Cannot access self:: when no class scope is active +Cannot access self:: when no class scope is active +Cannot access self:: when no class scope is active diff --git a/Zend/tests/self_mod.phpt b/Zend/tests/self_mod.phpt index 19e45d88fc..0b10987aeb 100644 --- a/Zend/tests/self_mod.phpt +++ b/Zend/tests/self_mod.phpt @@ -20,6 +20,10 @@ echo "Done\n"; ?> --EXPECTF-- int(13) + +Warning: A non-numeric value encountered in %s on line %d int(0) + +Notice: A non well formed numeric value encountered in %s on line %d int(3) Done diff --git a/Zend/tests/self_or.phpt b/Zend/tests/self_or.phpt index ae667bff16..8ace518bde 100644 --- a/Zend/tests/self_or.phpt +++ b/Zend/tests/self_or.phpt @@ -20,6 +20,10 @@ echo "Done\n"; ?> --EXPECTF-- int(127) + +Warning: A non-numeric value encountered in %s on line %d int(11) + +Notice: A non well formed numeric value encountered in %s on line %d int(45345) Done diff --git a/Zend/tests/self_xor.phpt b/Zend/tests/self_xor.phpt index a7e43f539d..c097930d6d 100644 --- a/Zend/tests/self_xor.phpt +++ b/Zend/tests/self_xor.phpt @@ -20,6 +20,10 @@ echo "Done\n"; ?> --EXPECTF-- int(109) + +Warning: A non-numeric value encountered in %s on line %d int(11) + +Notice: A non well formed numeric value encountered in %s on line %d int(45312) Done diff --git a/Zend/tests/shift_001.phpt b/Zend/tests/shift_001.phpt index aeb399452d..7546f1a6d8 100644 --- a/Zend/tests/shift_001.phpt +++ b/Zend/tests/shift_001.phpt @@ -20,6 +20,10 @@ echo "Done\n"; ?> --EXPECTF-- int(492) + +Warning: A non-numeric value encountered in %s on line %d int(0) + +Notice: A non well formed numeric value encountered in %s on line %d int(362760) Done diff --git a/Zend/tests/shift_002.phpt b/Zend/tests/shift_002.phpt index 4d8421a566..6288152585 100644 --- a/Zend/tests/shift_002.phpt +++ b/Zend/tests/shift_002.phpt @@ -20,6 +20,10 @@ echo "Done\n"; ?> --EXPECTF-- int(30) + +Warning: A non-numeric value encountered in %s on line %d int(0) + +Notice: A non well formed numeric value encountered in %s on line %d int(5668) Done diff --git a/Zend/tests/str_offset_001.phpt b/Zend/tests/str_offset_001.phpt index 8a6b91b49a..3317674857 100644 --- a/Zend/tests/str_offset_001.phpt +++ b/Zend/tests/str_offset_001.phpt @@ -1,51 +1,46 @@ ---TEST--
-string offset 001
---FILE--
-<?php
-function foo($x) {
- var_dump($x);
-}
-
-$str = "abc";
-var_dump($str[-1]);
-var_dump($str[0]);
-var_dump($str[1]);
-var_dump($str[2]);
-var_dump($str[3]);
-var_dump($str[1][0]);
-var_dump($str[2][1]);
-
-foo($str[-1]);
-foo($str[0]);
-foo($str[1]);
-foo($str[2]);
-foo($str[3]);
-foo($str[1][0]);
-foo($str[2][1]);
-?>
---EXPECTF--
-Notice: Uninitialized string offset: -1 in %sstr_offset_001.php on line %d
-string(0) ""
-string(1) "a"
-string(1) "b"
-string(1) "c"
-
-Notice: Uninitialized string offset: 3 in %sstr_offset_001.php on line %d
-string(0) ""
-string(1) "b"
-
-Notice: Uninitialized string offset: 1 in %sstr_offset_001.php on line %d
-string(0) ""
-
-Notice: Uninitialized string offset: -1 in %sstr_offset_001.php on line %d
-string(0) ""
-string(1) "a"
-string(1) "b"
-string(1) "c"
-
-Notice: Uninitialized string offset: 3 in %sstr_offset_001.php on line %d
-string(0) ""
-string(1) "b"
-
-Notice: Uninitialized string offset: 1 in %sstr_offset_001.php on line %d
-string(0) ""
+--TEST-- +string offset 001 +--FILE-- +<?php +// Test positive or null string offsets + +function foo($x) { + var_dump($x); +} + +$str = "abc"; +var_dump($str[0]); +var_dump($str[1]); +var_dump($str[2]); +var_dump($str[3]); +var_dump($str[1][0]); +var_dump($str[2][1]); + +foo($str[0]); +foo($str[1]); +foo($str[2]); +foo($str[3]); +foo($str[1][0]); +foo($str[2][1]); +?> +--EXPECTF-- +string(1) "a" +string(1) "b" +string(1) "c" + +Notice: Uninitialized string offset: 3 in %sstr_offset_001.php on line %d +string(0) "" +string(1) "b" + +Notice: Uninitialized string offset: 1 in %sstr_offset_001.php on line %d +string(0) "" +string(1) "a" +string(1) "b" +string(1) "c" + +Notice: Uninitialized string offset: 3 in %sstr_offset_001.php on line %d +string(0) "" +string(1) "b" + +Notice: Uninitialized string offset: 1 in %sstr_offset_001.php on line %d +string(0) "" diff --git a/Zend/tests/str_offset_003.phpt b/Zend/tests/str_offset_003.phpt new file mode 100644 index 0000000000..e357ac0c01 --- /dev/null +++ b/Zend/tests/str_offset_003.phpt @@ -0,0 +1,37 @@ +--TEST-- +string offset 003 +--FILE-- +<?php +// Test negative string offsets + +function foo($x) { + var_dump($x); +} + +$str = "abcdef"; +var_dump($str[-10]); +var_dump($str[-3]); +var_dump($str[2][-2]); +var_dump($str[2][-1]); + +foo($str[-10]); +foo($str[-3]); +foo($str[2][-2]); +foo($str[2][-1]); +?> +--EXPECTF-- +Notice: Uninitialized string offset: -10 in %sstr_offset_003.php on line %d +string(0) "" +string(1) "d" + +Notice: Uninitialized string offset: -2 in %sstr_offset_003.php on line %d +string(0) "" +string(1) "c" + +Notice: Uninitialized string offset: -10 in %sstr_offset_003.php on line %d +string(0) "" +string(1) "d" + +Notice: Uninitialized string offset: -2 in %sstr_offset_003.php on line %d +string(0) "" +string(1) "c" diff --git a/Zend/tests/str_offset_004.phpt b/Zend/tests/str_offset_004.phpt new file mode 100644 index 0000000000..c8ce607535 --- /dev/null +++ b/Zend/tests/str_offset_004.phpt @@ -0,0 +1,49 @@ +--TEST-- +string offset 004 +--FILE-- +<?php +// Test assignments using (positive and negative) string offsets + +$str = "abcdefghijklmno"; +$i = 3; +$j = -4; + +$str{2} = 'C'; +var_dump($str); + +$str{$i} = 'Z'; +var_dump($str); + +$str{-5} = 'P'; +var_dump($str); + +$str{$j} = 'Q'; +var_dump($str); + +$str{-20} = 'Y'; +var_dump($str); + +$str{-strlen($str)} = strtoupper($str{0}); /* An exotic ucfirst() ;) */ +var_dump($str); + +$str{20} = 'N'; +var_dump($str); + +$str{-2} = 'UFO'; +var_dump($str); + +$str{-$i} = $str{$j*2}; +var_dump($str); +?> +--EXPECTF-- +string(15) "abCdefghijklmno" +string(15) "abCZefghijklmno" +string(15) "abCZefghijPlmno" +string(15) "abCZefghijPQmno" + +Warning: Illegal string offset: -20 in %sstr_offset_004.php on line %d +string(15) "abCZefghijPQmno" +string(15) "AbCZefghijPQmno" +string(21) "AbCZefghijPQmno N" +string(21) "AbCZefghijPQmno UN" +string(21) "AbCZefghijPQmno nUN" diff --git a/Zend/tests/temporary_cleaning_001.phpt b/Zend/tests/temporary_cleaning_001.phpt index 40340bc3da..f2ccbb35b8 100644 --- a/Zend/tests/temporary_cleaning_001.phpt +++ b/Zend/tests/temporary_cleaning_001.phpt @@ -1,7 +1,5 @@ --TEST-- Temporary leak on exception ---XFAIL-- -See Bug #62210 and attempt to fix it in "tmp_livelibess" branch --FILE-- <?php diff --git a/Zend/tests/temporary_cleaning_003.phpt b/Zend/tests/temporary_cleaning_003.phpt index 0f7d9450eb..acff8c85f0 100644 --- a/Zend/tests/temporary_cleaning_003.phpt +++ b/Zend/tests/temporary_cleaning_003.phpt @@ -1,7 +1,5 @@ --TEST-- Fundamental memory leak test on temporaries ---XFAIL-- -See Bug #62210 and attempt to fix it in "tmp_livelibess" branch --FILE-- <?php diff --git a/Zend/tests/temporary_cleaning_004.phpt b/Zend/tests/temporary_cleaning_004.phpt index e2b093654f..b8a02516b0 100644 --- a/Zend/tests/temporary_cleaning_004.phpt +++ b/Zend/tests/temporary_cleaning_004.phpt @@ -1,7 +1,5 @@ --TEST-- Temporary leak with switch ---XFAIL-- -See Bug #62210 and attempt to fix it in "tmp_livelibess" branch --FILE-- <?php diff --git a/Zend/tests/temporary_cleaning_005.phpt b/Zend/tests/temporary_cleaning_005.phpt index f671c32543..e8c7febe0b 100644 --- a/Zend/tests/temporary_cleaning_005.phpt +++ b/Zend/tests/temporary_cleaning_005.phpt @@ -1,7 +1,5 @@ --TEST-- Temporary leak with foreach ---XFAIL-- -See Bug #62210 and attempt to fix it in "tmp_livelibess" branch --FILE-- <?php diff --git a/Zend/tests/temporary_cleaning_006.phpt b/Zend/tests/temporary_cleaning_006.phpt index 435e7b12dd..a7936d3915 100644 --- a/Zend/tests/temporary_cleaning_006.phpt +++ b/Zend/tests/temporary_cleaning_006.phpt @@ -1,7 +1,5 @@ --TEST-- Exception after separation during indirect write to fcall result ---XFAIL-- -See Bug #62210 and attempt to fix it in "tmp_livelibess" branch --FILE-- <?php diff --git a/Zend/tests/temporary_cleaning_008.phpt b/Zend/tests/temporary_cleaning_008.phpt new file mode 100644 index 0000000000..fabd3b4b38 --- /dev/null +++ b/Zend/tests/temporary_cleaning_008.phpt @@ -0,0 +1,15 @@ +--TEST-- +Optimization of constant switch expression +--FILE-- +<?php +try { + switch ("1" . (int)2) { + case 12: + throw new Exception(); + } +} catch (Exception $e) { + echo "exception\n"; +} +?> +--EXPECT-- +exception diff --git a/Zend/tests/temporary_cleaning_009.phpt b/Zend/tests/temporary_cleaning_009.phpt new file mode 100644 index 0000000000..32a84a6ffd --- /dev/null +++ b/Zend/tests/temporary_cleaning_009.phpt @@ -0,0 +1,27 @@ +--TEST-- +Live range & free on return +--FILE-- +<?php +class bar { + public $foo = 1; + public $bar = 1; + + function __destruct() { + throw $this->foo; + } +} +foreach (new bar as &$foo) { + try { + $foo = new Exception; + return; // frees the loop variable + } catch (Exception $e) { + echo "exception\n"; + } +} +echo "end\n"; +?> +--EXPECTF-- +Fatal error: Uncaught Exception in %stemporary_cleaning_009.php:12 +Stack trace: +#0 {main} + thrown in %stemporary_cleaning_009.php on line 12 diff --git a/Zend/tests/temporary_cleaning_010.phpt b/Zend/tests/temporary_cleaning_010.phpt new file mode 100644 index 0000000000..96eab121b8 --- /dev/null +++ b/Zend/tests/temporary_cleaning_010.phpt @@ -0,0 +1,23 @@ +--TEST-- +Live range & throw from finally +--XFAIL-- +See Bug #62210 and attempt to fix it in "tmp_livelibess" branch +--FILE-- +<?php +function test() { + try { + $a = [1, 2, 3]; + return $a + []; + } finally { + throw new Exception; + } +} + +try { + test(); +} catch (Exception $e) { + echo "exception\n"; +} +?> +--EXPECT-- +exception diff --git a/Zend/tests/temporary_cleaning_011.phpt b/Zend/tests/temporary_cleaning_011.phpt new file mode 100644 index 0000000000..e4a6af3ab9 --- /dev/null +++ b/Zend/tests/temporary_cleaning_011.phpt @@ -0,0 +1,20 @@ +--TEST-- +Live range & lists +--FILE-- +<?php +class A { + function __destruct() { + throw new Exception(); + } +} +$b = new A(); +$x = 0; +$c = [[$x,$x]]; +try { + list($a, $b) = $c[0]; +} catch (Exception $e) { + echo "exception\n"; +} +?> +--EXPECT-- +exception diff --git a/Zend/tests/temporary_cleaning_012.phpt b/Zend/tests/temporary_cleaning_012.phpt new file mode 100644 index 0000000000..fdbea6d41d --- /dev/null +++ b/Zend/tests/temporary_cleaning_012.phpt @@ -0,0 +1,20 @@ +--TEST-- +Live range of ZEND_NEW must be assigned to correct variable +--FILE-- +<?php + +class Foo { + public static function test() { + self::$property = new self; + } +} + +try { + Foo::test(); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Access to undeclared static property: Foo::$property diff --git a/Zend/tests/try/try_finally_021.phpt b/Zend/tests/try/try_finally_021.phpt new file mode 100644 index 0000000000..ed162f40d0 --- /dev/null +++ b/Zend/tests/try/try_finally_021.phpt @@ -0,0 +1,20 @@ +--TEST-- +Live range & return from finally +--FILE-- +<?php +$array = [1]; +foreach ([0] as $_) { + foreach ($array as $v) { + try { + echo "ok\n"; + return; + } finally { + echo "ok\n"; + return; + } + } +} +?> +--EXPECT-- +ok +ok diff --git a/Zend/tests/try/try_finally_022.phpt b/Zend/tests/try/try_finally_022.phpt new file mode 100644 index 0000000000..51f6a26419 --- /dev/null +++ b/Zend/tests/try/try_finally_022.phpt @@ -0,0 +1,41 @@ +--TEST-- +Try finally (exception in "return" statement) +--FILE-- +<?php +class A { + public $x = 1; + public $y = 2; + function __destruct() { + throw new Exception(); + } +} +try{ + $a = 0; + switch ($a) { + case 0: + } + switch ($a) { + case 0: + } + switch ($a) { + case 0: + } + foreach([new stdClass()] as $x) { + foreach(new A() as $a) { + foreach([new stdClass()] as $y) { + try { + if (0) { echo "0" . (int)5; } + return $a; + } catch (Exception $e) { + echo "exception1\n"; + } + } + } + } +} catch (Exception $e) { + echo "exception2\n"; +} +?> +--EXPECT-- +exception2 + |
