diff options
Diffstat (limited to 'ext/standard/tests/array')
23 files changed, 396 insertions, 201 deletions
diff --git a/ext/standard/tests/array/array_column_numeric_string_key.phpt b/ext/standard/tests/array/array_column_numeric_string_key.phpt new file mode 100644 index 0000000000..aed3c35ea2 --- /dev/null +++ b/ext/standard/tests/array/array_column_numeric_string_key.phpt @@ -0,0 +1,23 @@ +--TEST-- +array_column() treats numeric string keys as usual +--FILE-- +<?php + +$array = [[42 => 'a'], [42 => 'b']]; +var_dump(array_column($array, 42)); +var_dump(array_column($array, "42")); + +?> +--EXPECT-- +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" +} +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" +} diff --git a/ext/standard/tests/array/array_column_property_visibility.phpt b/ext/standard/tests/array/array_column_property_visibility.phpt new file mode 100644 index 0000000000..4639a3c9c5 --- /dev/null +++ b/ext/standard/tests/array/array_column_property_visibility.phpt @@ -0,0 +1,27 @@ +--TEST-- +array_column() respects property visibility +--FILE-- +<?php + +class Test { + private $prop; + public function __construct($value) { + $this->prop = $value; + } + public function __isset($name) { + return true; + } + public function __get($name) { + return "__get($this->prop)"; + } +} + +$arr = [new Test("foobar")]; +var_dump(array_column($arr, "prop")); + +?> +--EXPECT-- +array(1) { + [0]=> + string(13) "__get(foobar)" +} diff --git a/ext/standard/tests/array/array_filter_variation10.phpt b/ext/standard/tests/array/array_filter_variation10.phpt index f0a6115f79..b23618794e 100644 --- a/ext/standard/tests/array/array_filter_variation10.phpt +++ b/ext/standard/tests/array/array_filter_variation10.phpt @@ -34,7 +34,11 @@ var_dump( array_filter($input, 'dump2', true) ); echo "*** Testing array_filter() : usage variations - 'callback' expecting second argument ***\n"; -var_dump( array_filter($small, 'dump', false) ); +try { + var_dump( array_filter($small, 'dump', false) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "*** Testing array_filter() with various use types ***\n"; @@ -70,13 +74,7 @@ array(3) { NULL } *** Testing array_filter() : usage variations - 'callback' expecting second argument *** - -Warning: Missing argument 2 for dump() in %s on line %d - -Notice: Undefined variable: key in %s on line %d - = 123 -array(0) { -} +Exception: Too few arguments to function dump(), 1 passed and exactly 2 expected *** Testing array_filter() with various use types *** array(2) { [1]=> @@ -91,13 +89,13 @@ array(2) { int(2) } -Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 44 +Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 48 -Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 44 +Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 48 -Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 44 +Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 48 -Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 44 +Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line 48 array(0) { } Done diff --git a/ext/standard/tests/array/array_map_error.phpt b/ext/standard/tests/array/array_map_error.phpt index 7c623ec4ea..56dd033521 100644 --- a/ext/standard/tests/array/array_map_error.phpt +++ b/ext/standard/tests/array/array_map_error.phpt @@ -18,14 +18,22 @@ echo "\n-- Testing array_map() function with one less than expected no. of argum function callback1() { return 1; } -var_dump( array_map('callback1') ); +try { + var_dump( array_map('callback1') ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n"; $arr1 = array(1, 2); function callback2($p, $q) { return $p * $q; } -var_dump( array_map('callback2', $arr1) ); +try { + var_dump( array_map('callback2', $arr1) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n"; $arr2 = array(3, 4); @@ -48,20 +56,7 @@ Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d%d NULL -- Testing array_map() function with less no. of arrays than callback function arguments -- - -Warning: Missing argument 2 for callback2() in %s on line %d%d - -Notice: Undefined variable: q in %s on line %d%d - -Warning: Missing argument 2 for callback2() in %s on line %d%d - -Notice: Undefined variable: q in %s on line %d%d -array(2) { - [0]=> - int(0) - [1]=> - int(0) -} +Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected -- Testing array_map() function with more no. of arrays than callback function arguments -- array(2) { diff --git a/ext/standard/tests/array/array_map_variation10.phpt b/ext/standard/tests/array/array_map_variation10.phpt index cc75436999..ecf9157620 100644 --- a/ext/standard/tests/array/array_map_variation10.phpt +++ b/ext/standard/tests/array/array_map_variation10.phpt @@ -20,7 +20,11 @@ echo "-- anonymous function with all parameters and body --\n"; var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1, $array2)); echo "-- anonymous function with two parameters and passing one array --\n"; -var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1)); +try { + var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1)); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "-- anonymous function with NULL parameter --\n"; var_dump( array_map( create_function(NULL, 'return NULL;'), $array1)); @@ -60,41 +64,7 @@ array(3) { } } -- anonymous function with two parameters and passing one array -- - -Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d - -Notice: Undefined variable: b in %s(20) : runtime-created function on line %d - -Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d - -Notice: Undefined variable: b in %s(20) : runtime-created function on line %d - -Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d - -Notice: Undefined variable: b in %s(20) : runtime-created function on line %d -array(3) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - NULL - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - NULL - } - [2]=> - array(2) { - [0]=> - int(3) - [1]=> - NULL - } -} +Exception: Too few arguments to function __lambda_func(), 1 passed and exactly 2 expected -- anonymous function with NULL parameter -- array(3) { [0]=> diff --git a/ext/standard/tests/array/array_map_variation9.phpt b/ext/standard/tests/array/array_map_variation9.phpt index f029beccd6..f33b717c6c 100644 --- a/ext/standard/tests/array/array_map_variation9.phpt +++ b/ext/standard/tests/array/array_map_variation9.phpt @@ -29,7 +29,11 @@ echo "-- checking binary safe array with one parameter callback function --\n"; var_dump( array_map('callback1', $arr1) ); echo "-- checking binary safe array with two parameter callback function --\n"; -var_dump( array_map(b"callback2", $arr1) ); +try { + var_dump( array_map(b"callback2", $arr1) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "Done"; ?> @@ -47,42 +51,5 @@ array(4) { string(5) "22.22" } -- checking binary safe array with two parameter callback function -- - -Warning: Missing argument 2 for callback2() in %s on line %d%d - -Notice: Undefined variable: b in %s on line %d%d - -Warning: Missing argument 2 for callback2() in %s on line %d%d - -Notice: Undefined variable: b in %s on line %d%d - -Warning: Missing argument 2 for callback2() in %s on line %d%d - -Notice: Undefined variable: b in %s on line %d%d - -Warning: Missing argument 2 for callback2() in %s on line %d%d - -Notice: Undefined variable: b in %s on line %d%d -array(4) { - [0]=> - array(1) { - ["hello"]=> - NULL - } - [1]=> - array(1) { - ["world"]=> - NULL - } - [2]=> - array(1) { - [1]=> - NULL - } - [3]=> - array(1) { - ["22.22"]=> - NULL - } -} +Exception: Too few arguments to function callback2(), 1 passed and exactly 2 expected Done diff --git a/ext/standard/tests/array/array_reduce_variation1.phpt b/ext/standard/tests/array/array_reduce_variation1.phpt index b02a82a7ca..adffeb53d4 100644 --- a/ext/standard/tests/array/array_reduce_variation1.phpt +++ b/ext/standard/tests/array/array_reduce_variation1.phpt @@ -25,7 +25,11 @@ echo "\n--- Testing with a callback with too few parameters ---\n"; var_dump(array_reduce($array, "oneArg", 2)); echo "\n--- Testing with a callback with too many parameters ---\n"; -var_dump(array_reduce($array, "threeArgs", 2)); +try { + var_dump(array_reduce($array, "threeArgs", 2)); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} ?> ===DONE=== @@ -36,9 +40,5 @@ var_dump(array_reduce($array, "threeArgs", 2)); int(2) --- Testing with a callback with too many parameters --- - -Warning: Missing argument 3 for threeArgs() in %sarray_reduce_variation1.php on line %d - -Notice: Undefined variable: x in %sarray_reduce_variation1.php on line %d -int(3) -===DONE===
\ No newline at end of file +Exception: Too few arguments to function threeArgs(), 2 passed and exactly 3 expected +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_assoc_variation5.phpt b/ext/standard/tests/array/array_udiff_assoc_variation5.phpt index 69380767bb..6b7f014467 100644 --- a/ext/standard/tests/array/array_udiff_assoc_variation5.phpt +++ b/ext/standard/tests/array/array_udiff_assoc_variation5.phpt @@ -24,7 +24,11 @@ echo "\n-- comparison function taking too many parameters --\n"; function too_many_parameters ($val1, $val2, $val3) { return 1; } -var_dump(array_udiff_assoc($arr1, $arr2, 'too_many_parameters')); +try { + var_dump(array_udiff_assoc($arr1, $arr2, 'too_many_parameters')); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- comparison function taking too few parameters --\n"; function too_few_parameters ($val1) { @@ -32,7 +36,6 @@ function too_few_parameters ($val1) { } var_dump(array_udiff_assoc($arr1, $arr2, 'too_few_parameters')); - ?> ===DONE=== --EXPECTF-- @@ -45,12 +48,7 @@ array(1) { } -- comparison function taking too many parameters -- - -Warning: Missing argument 3 for too_many_parameters() in %sarray_udiff_assoc_variation5.php on line %d -array(1) { - [0]=> - int(1) -} +Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected -- comparison function taking too few parameters -- array(1) { diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt index ec752a31bb..bf2c0f3d2d 100644 --- a/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt +++ b/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt @@ -23,7 +23,11 @@ echo "\n-- comparison function taking too many parameters --\n"; function too_many_parameters ($val1, $val2, $val3) { return 1; } -var_dump(array_udiff_uassoc($arr1, $arr2, 'too_many_parameters', 'too_many_parameters')); +try { + var_dump(array_udiff_uassoc($arr1, $arr2, 'too_many_parameters', 'too_many_parameters')); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- comparison function taking too few parameters --\n"; function too_few_parameters ($val1) { @@ -43,12 +47,7 @@ array(1) { } -- comparison function taking too many parameters -- - -Warning: Missing argument 3 for too_many_parameters() in %sarray_udiff_uassoc_variation6.php on line %d -array(1) { - [0]=> - int(1) -} +Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected -- comparison function taking too few parameters -- array(1) { diff --git a/ext/standard/tests/array/array_udiff_variation5.phpt b/ext/standard/tests/array/array_udiff_variation5.phpt index 49405d40be..ce6362fc08 100644 --- a/ext/standard/tests/array/array_udiff_variation5.phpt +++ b/ext/standard/tests/array/array_udiff_variation5.phpt @@ -24,7 +24,11 @@ echo "\n-- comparison function taking too many parameters --\n"; function too_many_parameters ($val1, $val2, $val3) { return 0; } -var_dump(array_udiff($arr1, $arr2, 'too_many_parameters')); +try { + var_dump(array_udiff($arr1, $arr2, 'too_many_parameters')); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- comparison function taking too few parameters --\n"; function too_few_parameters ($val1) { @@ -44,10 +48,7 @@ array(1) { } -- comparison function taking too many parameters -- - -Warning: Missing argument 3 for too_many_parameters() in %sarray_udiff_variation5.php on line %d -array(0) { -} +Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected -- comparison function taking too few parameters -- array(0) { diff --git a/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt b/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt index e2d7bd03a6..bebe5b52c9 100644 --- a/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt +++ b/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt @@ -23,7 +23,11 @@ echo "\n-- comparison function taking too many parameters --\n"; function too_many_parameters ($val1, $val2, $val3) { return 1; } -var_dump(array_uintersect_assoc($arr1, $arr2, 'too_many_parameters')); +try { + var_dump(array_uintersect_assoc($arr1, $arr2, 'too_many_parameters')); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- comparison function taking too few parameters --\n"; function too_few_parameters ($val1) { @@ -42,10 +46,7 @@ array(0) { } -- comparison function taking too many parameters -- - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_assoc_variation5.php on line %d -array(0) { -} +Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected -- comparison function taking too few parameters -- array(0) { diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt index 6ed86f8417..a5317c1c0d 100644 --- a/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt @@ -23,7 +23,11 @@ echo "\n-- comparison function taking too many parameters --\n"; function too_many_parameters ($val1, $val2, $val3) { return 1; } -var_dump(array_uintersect_uassoc($arr1, $arr2, 'too_many_parameters', 'too_many_parameters')); +try { + var_dump(array_uintersect_uassoc($arr1, $arr2, 'too_many_parameters', 'too_many_parameters')); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- comparison function taking too few parameters --\n"; function too_few_parameters ($val1) { @@ -41,14 +45,7 @@ array(0) { } -- comparison function taking too many parameters -- - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_uassoc_variation6.php on line %d - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_uassoc_variation6.php on line %d - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_uassoc_variation6.php on line %d -array(0) { -} +Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected -- comparison function taking too few parameters -- array(0) { diff --git a/ext/standard/tests/array/array_uintersect_variation5.phpt b/ext/standard/tests/array/array_uintersect_variation5.phpt index 75cf08e270..642ebc0077 100644 --- a/ext/standard/tests/array/array_uintersect_variation5.phpt +++ b/ext/standard/tests/array/array_uintersect_variation5.phpt @@ -23,7 +23,11 @@ echo "\n-- comparison function taking too many parameters --\n"; function too_many_parameters ($val1, $val2, $val3) { return 1; } -var_dump(array_uintersect($arr1, $arr2, 'too_many_parameters')); +try { + var_dump(array_uintersect($arr1, $arr2, 'too_many_parameters')); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "\n-- comparison function taking too few parameters --\n"; function too_few_parameters ($val1) { @@ -42,14 +46,7 @@ array(0) { } -- comparison function taking too many parameters -- - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_variation5.php on line %d - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_variation5.php on line %d - -Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_variation5.php on line %d -array(0) { -} +Exception: Too few arguments to function too_many_parameters(), 2 passed and exactly 3 expected -- comparison function taking too few parameters -- array(0) { diff --git a/ext/standard/tests/array/array_walk_error2.phpt b/ext/standard/tests/array/array_walk_error2.phpt index 63c5f51ee0..fd3cbf5037 100644 --- a/ext/standard/tests/array/array_walk_error2.phpt +++ b/ext/standard/tests/array/array_walk_error2.phpt @@ -22,36 +22,44 @@ function callback2($value, $key, $user_data1, $user_data2) { echo "*** Testing array_walk() : error conditions - callback parameters ***\n"; // expected: Missing argument Warning -var_dump( array_walk($input, "callback1") ); -var_dump( array_walk($input, "callback2", 4) ); +try { + var_dump( array_walk($input, "callback1") ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump( array_walk($input, "callback2", 4) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} // expected: Warning is suppressed -var_dump( @array_walk($input, "callback1") ); -var_dump( @array_walk($input, "callback2", 4) ); +try { + var_dump( @array_walk($input, "callback1") ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump( @array_walk($input, "callback2", 4) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "-- Testing array_walk() function with too many callback parameters --\n"; -var_dump( array_walk($input, "callback1", 20, 10) ); +try { + var_dump( array_walk($input, "callback1", 20, 10) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "Done"; ?> --EXPECTF-- *** Testing array_walk() : error conditions - callback parameters *** - -Warning: Missing argument 3 for callback1() in %s on line %d - -callback1() invoked -bool(true) - -Warning: Missing argument 4 for callback2() in %s on line %d - -callback2() invoked -bool(true) - -callback1() invoked -bool(true) - -callback2() invoked -bool(true) +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected -- Testing array_walk() function with too many callback parameters -- Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d diff --git a/ext/standard/tests/array/array_walk_recursive_error2.phpt b/ext/standard/tests/array/array_walk_recursive_error2.phpt index 8e0c8829e6..5a077c6886 100644 --- a/ext/standard/tests/array/array_walk_recursive_error2.phpt +++ b/ext/standard/tests/array/array_walk_recursive_error2.phpt @@ -22,36 +22,44 @@ function callback2($value, $key, $user_data1, $user_data2) { echo "*** Testing array_walk_recursive() : error conditions - callback parameters ***\n"; // expected: Missing argument Warning -var_dump( array_walk_recursive($input, "callback1") ); -var_dump( array_walk_recursive($input, "callback2", 4) ); +try { + var_dump( array_walk_recursive($input, "callback1") ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump( array_walk_recursive($input, "callback2", 4) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} // expected: Warning is suppressed -var_dump( @array_walk_recursive($input, "callback1") ); -var_dump( @array_walk_recursive($input, "callback2", 4) ); +try { + var_dump( @array_walk_recursive($input, "callback1") ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump( @array_walk_recursive($input, "callback2", 4) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "-- Testing array_walk_recursive() function with too many callback parameters --\n"; -var_dump( array_walk_recursive($input, "callback1", 20, 10) ); +try { + var_dump( array_walk_recursive($input, "callback1", 20, 10) ); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} echo "Done"; ?> --EXPECTF-- *** Testing array_walk_recursive() : error conditions - callback parameters *** - -Warning: Missing argument 3 for callback1() in %s on line %d - -callback1() invoked -bool(true) - -Warning: Missing argument 4 for callback2() in %s on line %d - -callback2() invoked -bool(true) - -callback1() invoked -bool(true) - -callback2() invoked -bool(true) +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected +Exception: Too few arguments to function callback1(), 2 passed and exactly 3 expected +Exception: Too few arguments to function callback2(), 3 passed and exactly 4 expected -- Testing array_walk_recursive() function with too many callback parameters -- Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d diff --git a/ext/standard/tests/array/bug71334.phpt b/ext/standard/tests/array/bug71334.phpt new file mode 100644 index 0000000000..7a37d0953a --- /dev/null +++ b/ext/standard/tests/array/bug71334.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #71334: Cannot access array keys while uksort() +--FILE-- +<?php + +class myClass +{ + private $a = [ + 'foo-test' => [1], + '-' => [2], + 'bar-test' => [3] + ]; + + private function _mySort($x, $y) + { + if (!isset($this->a[$x])) { + throw new Exception('Missing X: "' . $x . '"'); + } + + if (!isset($this->a[$y])) { + throw new Exception('Missing Y: "' . $y . '"'); + } + + return $x < $y; + } + + public function __construct() + { + uksort($this->a, [$this, '_mySort']); + } +} + +new myClass(); +echo "Done"; + +?> +--EXPECT-- +Done diff --git a/ext/standard/tests/array/bug71837.phpt b/ext/standard/tests/array/bug71837.phpt new file mode 100644 index 0000000000..686d144c3c --- /dev/null +++ b/ext/standard/tests/array/bug71837.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #71837 (Wrong arrays behaviour) +--FILE-- +<?php + +$p = array(array()); +array_push($p[0], array(100)); + +$c = array_merge($p, array()); +$c[0][0] = 200; + +print_r($p); + +?> +--EXPECT-- +Array +( + [0] => Array + ( + [0] => Array + ( + [0] => 100 + ) + + ) + +) diff --git a/ext/standard/tests/array/bug72031.phpt b/ext/standard/tests/array/bug72031.phpt new file mode 100644 index 0000000000..541fd3c4ec --- /dev/null +++ b/ext/standard/tests/array/bug72031.phpt @@ -0,0 +1,48 @@ +--TEST-- +Bug #72031: array_column() against an array of objects discards all values matching null +--FILE-- +<?php + +class myObj { + public $prop; + public function __construct($prop) { + $this->prop = $prop; + } +} + +$objects = [ + new myObj(-1), + new myObj(0), + new myObj(1), + new myObj(2), + new myObj(null), + new myObj(true), + new myObj(false), + new myObj('abc'), + new myObj(''), +]; + +var_dump(array_column($objects, 'prop')); + +?> +--EXPECT-- +array(9) { + [0]=> + int(-1) + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) + [4]=> + NULL + [5]=> + bool(true) + [6]=> + bool(false) + [7]=> + string(3) "abc" + [8]=> + string(0) "" +} diff --git a/ext/standard/tests/array/bug72116.phpt b/ext/standard/tests/array/bug72116.phpt new file mode 100644 index 0000000000..7951f69130 --- /dev/null +++ b/ext/standard/tests/array/bug72116.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #72116 (insertion after array_fill fails) +--FILE-- +<?php + +$x = array_fill(0, 1, '..'); +$x[] = 'a'; +var_dump($x); + +?> +--EXPECT-- +array(2) { + [0]=> + string(2) ".." + [1]=> + string(1) "a" +} + diff --git a/ext/standard/tests/array/bug72369.phpt b/ext/standard/tests/array/bug72369.phpt new file mode 100644 index 0000000000..63bb5625de --- /dev/null +++ b/ext/standard/tests/array/bug72369.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #72369 (array_merge() produces references in PHP7) +--FILE-- +<?php +$x = 'xxx'; +$d = ['test' => &$x]; +unset($x); +$a = ['test' => 'yyy']; +$a = array_merge($a, $d); +debug_zval_dump($a); +?> +--EXPECTF-- +array(1) refcount(%d){ + ["test"]=> + string(3) "xxx" refcount(%d) +} diff --git a/ext/standard/tests/array/range_bug72017.phpt b/ext/standard/tests/array/range_bug72017.phpt new file mode 100644 index 0000000000..b5a56d7f4e --- /dev/null +++ b/ext/standard/tests/array/range_bug72017.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #72017 (incorrect truncation due to floating point precision issue) +--FILE-- +<?php +var_dump(range(4.5, 4.2, 0.1)); +?> +--EXPECT-- +array(4) { + [0]=> + float(4.5) + [1]=> + float(4.4) + [2]=> + float(4.3) + [3]=> + float(4.2) +} diff --git a/ext/standard/tests/array/unexpected_array_mod_bug.phpt b/ext/standard/tests/array/unexpected_array_mod_bug.phpt index 58f2249205..2762ebd830 100644 --- a/ext/standard/tests/array/unexpected_array_mod_bug.phpt +++ b/ext/standard/tests/array/unexpected_array_mod_bug.phpt @@ -4,7 +4,7 @@ Crash when function parameter modified via reference <?php function usercompare($a,$b) { unset($GLOBALS['my_var'][2]); - return 0; + return $a <=> $b; } $my_var = array(1 => "entry_1", 2 => "entry_2", @@ -12,10 +12,19 @@ $my_var = array(1 => "entry_1", 4 => "entry_4", 5 => "entry_5"); usort($my_var, "usercompare"); +var_dump($my_var); -echo "Done.\n"; ?> ---EXPECTF-- - -Warning: usort(): Array was modified by the user comparison function in %s on line %d -Done. +--EXPECT-- +array(5) { + [0]=> + string(7) "entry_1" + [1]=> + string(7) "entry_2" + [2]=> + string(7) "entry_3" + [3]=> + string(7) "entry_4" + [4]=> + string(7) "entry_5" +} diff --git a/ext/standard/tests/array/unexpected_array_mod_bug_variation1.phpt b/ext/standard/tests/array/unexpected_array_mod_bug_variation1.phpt new file mode 100644 index 0000000000..b5a1ee24d5 --- /dev/null +++ b/ext/standard/tests/array/unexpected_array_mod_bug_variation1.phpt @@ -0,0 +1,33 @@ +--TEST-- +Crash when function parameter modified via reference while keeping orig refcount +--FILE-- +<?php + +$array = array( + 1 => "entry_1", + 2 => "entry_2", + 3 => "entry_3", + 4 => "entry_4", + 5 => "entry_5" +); +usort($array, function($a, $b) use (&$array, &$ref) { + unset($array[2]); + $ref = $array; + return $a <=> $b; +}); +var_dump($array); + +?> +--EXPECT-- +array(5) { + [0]=> + string(7) "entry_1" + [1]=> + string(7) "entry_2" + [2]=> + string(7) "entry_3" + [3]=> + string(7) "entry_4" + [4]=> + string(7) "entry_5" +} |
