From 2f9709ecb6118065ce0403c6973cb5b60fe40348 Mon Sep 17 00:00:00 2001 From: Josie Messa Date: Tue, 19 Feb 2008 17:03:11 +0000 Subject: [PATCH] - New tests for each() function --- ext/standard/tests/array/each_basic.phpt | 116 +++++ ext/standard/tests/array/each_error.phpt | 55 +++ ext/standard/tests/array/each_variation1.phpt | 347 +++++++++++++++ ext/standard/tests/array/each_variation2.phpt | 376 ++++++++++++++++ ext/standard/tests/array/each_variation3.phpt | 400 ++++++++++++++++++ ext/standard/tests/array/each_variation4.phpt | 138 ++++++ ext/standard/tests/array/each_variation5.phpt | 157 +++++++ ext/standard/tests/array/each_variation6.phpt | 72 ++++ 8 files changed, 1661 insertions(+) create mode 100644 ext/standard/tests/array/each_basic.phpt create mode 100644 ext/standard/tests/array/each_error.phpt create mode 100644 ext/standard/tests/array/each_variation1.phpt create mode 100644 ext/standard/tests/array/each_variation2.phpt create mode 100644 ext/standard/tests/array/each_variation3.phpt create mode 100644 ext/standard/tests/array/each_variation4.phpt create mode 100644 ext/standard/tests/array/each_variation5.phpt create mode 100644 ext/standard/tests/array/each_variation6.phpt diff --git a/ext/standard/tests/array/each_basic.phpt b/ext/standard/tests/array/each_basic.phpt new file mode 100644 index 0000000000..96d199c7d3 --- /dev/null +++ b/ext/standard/tests/array/each_basic.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test each() function : basic functionality +--FILE-- + 1, 'zero', 'two' => 'deux', 20 => 'twenty'); +echo "\n-- Passed array: --\n"; +var_dump($arr); + +echo "\n-- Initial position: --\n"; +var_dump(each($arr)); + +echo "\n-- End position: --\n"; +end($arr); +var_dump(each($arr)); + +echo "\n-- Passed the end of array: --\n"; +var_dump(each($arr)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing each() : basic functionality *** + +-- Passed array: -- +array(4) { + ["one"]=> + int(1) + [0]=> + string(4) "zero" + ["two"]=> + string(4) "deux" + [20]=> + string(6) "twenty" +} + +-- Initial position: -- +array(4) { + [1]=> + int(1) + ["value"]=> + int(1) + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} + +-- End position: -- +array(4) { + [1]=> + string(6) "twenty" + ["value"]=> + string(6) "twenty" + [0]=> + int(20) + ["key"]=> + int(20) +} + +-- Passed the end of array: -- +bool(false) +Done +--UEXPECTF-- +*** Testing each() : basic functionality *** + +-- Passed array: -- +array(4) { + [u"one"]=> + int(1) + [0]=> + unicode(4) "zero" + [u"two"]=> + unicode(4) "deux" + [20]=> + unicode(6) "twenty" +} + +-- Initial position: -- +array(4) { + [1]=> + int(1) + [u"value"]=> + int(1) + [0]=> + unicode(3) "one" + [u"key"]=> + unicode(3) "one" +} + +-- End position: -- +array(4) { + [1]=> + unicode(6) "twenty" + [u"value"]=> + unicode(6) "twenty" + [0]=> + int(20) + [u"key"]=> + int(20) +} + +-- Passed the end of array: -- +bool(false) +Done \ No newline at end of file diff --git a/ext/standard/tests/array/each_error.phpt b/ext/standard/tests/array/each_error.phpt new file mode 100644 index 0000000000..7c39b9e77d --- /dev/null +++ b/ext/standard/tests/array/each_error.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test each() function : error conditions - pass incorrect number of args +--FILE-- + + +--EXPECTF-- +*** Testing each() : error conditions *** + +-- Testing each() function with Zero arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL + +-- Testing each() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing each() : error conditions *** + +-- Testing each() function with Zero arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL + +-- Testing each() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL +Done \ No newline at end of file diff --git a/ext/standard/tests/array/each_variation1.phpt b/ext/standard/tests/array/each_variation1.phpt new file mode 100644 index 0000000000..9b0011211b --- /dev/null +++ b/ext/standard/tests/array/each_variation1.phpt @@ -0,0 +1,347 @@ +--TEST-- +Test each() function : usage variations - Pass different data types as $arr arg +--FILE-- + + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL +Done + +--UEXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/each_variation2.phpt b/ext/standard/tests/array/each_variation2.phpt new file mode 100644 index 0000000000..9031b43567 --- /dev/null +++ b/ext/standard/tests/array/each_variation2.phpt @@ -0,0 +1,376 @@ +--TEST-- +Test each() function : usage variations - arrays of different data types +--FILE-- + array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( each($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + int(0) + ["value"]=> + int(0) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + float(10.5) + ["value"]=> + float(10.5) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 3: null data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 4: bool data -- +array(4) { + [1]=> + bool(true) + ["value"]=> + bool(true) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 5: empty string data -- +array(4) { + [1]=> + string(0) "" + ["value"]=> + string(0) "" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 6: empty array data -- +bool(false) + +-- Iteration 7: string data -- +array(4) { + [1]=> + string(6) "string" + ["value"]=> + string(6) "string" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 8: object data -- +array(4) { + [1]=> + object(classA)#%d (0) { + } + ["value"]=> + object(classA)#%d (0) { + } + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 9: undefined data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 10: unset data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 11: resource data -- +array(4) { + [1]=> + resource(%d) of type (stream) + ["value"]=> + resource(%d) of type (stream) + [0]=> + int(0) + ["key"]=> + int(0) +} +Done +--UEXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + int(0) + [u"value"]=> + int(0) + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + float(10.5) + [u"value"]=> + float(10.5) + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 3: null data -- +array(4) { + [1]=> + NULL + [u"value"]=> + NULL + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 4: bool data -- +array(4) { + [1]=> + bool(true) + [u"value"]=> + bool(true) + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 5: empty string data -- +array(4) { + [1]=> + unicode(0) "" + [u"value"]=> + unicode(0) "" + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 6: empty array data -- +bool(false) + +-- Iteration 7: string data -- +array(4) { + [1]=> + unicode(6) "string" + [u"value"]=> + unicode(6) "string" + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 8: object data -- +array(4) { + [1]=> + object(classA)#%d (0) { + } + [u"value"]=> + object(classA)#%d (0) { + } + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 9: undefined data -- +array(4) { + [1]=> + NULL + [u"value"]=> + NULL + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 10: unset data -- +array(4) { + [1]=> + NULL + [u"value"]=> + NULL + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 11: resource data -- +array(4) { + [1]=> + resource(%d) of type (stream) + [u"value"]=> + resource(%d) of type (stream) + [0]=> + int(0) + [u"key"]=> + int(0) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/each_variation3.phpt b/ext/standard/tests/array/each_variation3.phpt new file mode 100644 index 0000000000..8814a80637 --- /dev/null +++ b/ext/standard/tests/array/each_variation3.phpt @@ -0,0 +1,400 @@ +--TEST-- +Test each() function : usage variations - keys of different data types +--FILE-- + array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( each($input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + string(8) "positive" + ["value"]=> + string(8) "positive" + [0]=> + int(10) + ["key"]=> + int(10) +} + +-- Iteration 3: extreme floats data -- +array(4) { + [1]=> + string(5) "large" + ["value"]=> + string(5) "large" + [0]=> + int(12345678) + ["key"]=> + int(12345678) +} + +-- Iteration 4: null uppercase data -- +array(4) { + [1]=> + string(6) "null 1" + ["value"]=> + string(6) "null 1" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 5: null lowercase data -- +array(4) { + [1]=> + string(6) "null 2" + ["value"]=> + string(6) "null 2" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 6: bool lowercase data -- +array(4) { + [1]=> + string(6) "lowert" + ["value"]=> + string(6) "lowert" + [0]=> + int(1) + ["key"]=> + int(1) +} + +-- Iteration 7: bool uppercase data -- +array(4) { + [1]=> + string(6) "uppert" + ["value"]=> + string(6) "uppert" + [0]=> + int(1) + ["key"]=> + int(1) +} + +-- Iteration 8: empty double quotes data -- +array(4) { + [1]=> + string(6) "emptyd" + ["value"]=> + string(6) "emptyd" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 9: empty single quotes data -- +array(4) { + [1]=> + string(6) "emptys" + ["value"]=> + string(6) "emptys" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 10: string data -- +array(4) { + [1]=> + string(7) "stringd" + ["value"]=> + string(7) "stringd" + [0]=> + string(7) "stringd" + ["key"]=> + string(7) "stringd" +} + +-- Iteration 11: undefined data -- +array(4) { + [1]=> + string(9) "undefined" + ["value"]=> + string(9) "undefined" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 12: unset data -- +array(4) { + [1]=> + string(5) "unset" + ["value"]=> + string(5) "unset" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} +Done +--UEXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + unicode(4) "zero" + [u"value"]=> + unicode(4) "zero" + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + unicode(8) "positive" + [u"value"]=> + unicode(8) "positive" + [0]=> + int(10) + [u"key"]=> + int(10) +} + +-- Iteration 3: extreme floats data -- +array(4) { + [1]=> + unicode(5) "large" + [u"value"]=> + unicode(5) "large" + [0]=> + int(12345678) + [u"key"]=> + int(12345678) +} + +-- Iteration 4: null uppercase data -- +array(4) { + [1]=> + unicode(6) "null 1" + [u"value"]=> + unicode(6) "null 1" + [0]=> + unicode(0) "" + [u"key"]=> + unicode(0) "" +} + +-- Iteration 5: null lowercase data -- +array(4) { + [1]=> + unicode(6) "null 2" + [u"value"]=> + unicode(6) "null 2" + [0]=> + unicode(0) "" + [u"key"]=> + unicode(0) "" +} + +-- Iteration 6: bool lowercase data -- +array(4) { + [1]=> + unicode(6) "lowert" + [u"value"]=> + unicode(6) "lowert" + [0]=> + int(1) + [u"key"]=> + int(1) +} + +-- Iteration 7: bool uppercase data -- +array(4) { + [1]=> + unicode(6) "uppert" + [u"value"]=> + unicode(6) "uppert" + [0]=> + int(1) + [u"key"]=> + int(1) +} + +-- Iteration 8: empty double quotes data -- +array(4) { + [1]=> + unicode(6) "emptyd" + [u"value"]=> + unicode(6) "emptyd" + [0]=> + unicode(0) "" + [u"key"]=> + unicode(0) "" +} + +-- Iteration 9: empty single quotes data -- +array(4) { + [1]=> + unicode(6) "emptys" + [u"value"]=> + unicode(6) "emptys" + [0]=> + unicode(0) "" + [u"key"]=> + unicode(0) "" +} + +-- Iteration 10: string data -- +array(4) { + [1]=> + unicode(7) "stringd" + [u"value"]=> + unicode(7) "stringd" + [0]=> + unicode(7) "stringd" + [u"key"]=> + unicode(7) "stringd" +} + +-- Iteration 11: undefined data -- +array(4) { + [1]=> + unicode(9) "undefined" + [u"value"]=> + unicode(9) "undefined" + [0]=> + unicode(0) "" + [u"key"]=> + unicode(0) "" +} + +-- Iteration 12: unset data -- +array(4) { + [1]=> + unicode(5) "unset" + [u"value"]=> + unicode(5) "unset" + [0]=> + unicode(0) "" + [u"key"]=> + unicode(0) "" +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/each_variation4.phpt b/ext/standard/tests/array/each_variation4.phpt new file mode 100644 index 0000000000..18bbf418da --- /dev/null +++ b/ext/standard/tests/array/each_variation4.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test each() function : usage variations - Referenced variables +--FILE-- + &$val1, &$val2); + +echo "-- Call each until at the end of the array: --\n"; +var_dump( each($arr1) ); +var_dump( each($arr1) ); +var_dump( each($arr1) ); + + +echo "\n-- Pass an array by reference to each(): --\n"; +$arr2 = array('zero', 'one', 'two'); + +var_dump( each(&$arr2) ); +echo "-- Check original array: --\n"; +var_dump($arr2); + +echo "Done"; +?> + +--EXPECTF-- +Strict Standards: Call-time pass-by-reference has been deprecated in %s on line %d +*** Testing each() : usage variations *** + +-- Array made up of referenced variables: -- +-- Call each until at the end of the array: -- +array(4) { + [1]=> + string(3) "foo" + ["value"]=> + string(3) "foo" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} +array(4) { + [1]=> + string(3) "bar" + ["value"]=> + string(3) "bar" + [0]=> + int(0) + ["key"]=> + int(0) +} +bool(false) + +-- Pass an array by reference to each(): -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} +-- Check original array: -- +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +Done +--UEXPECTF-- +Strict Standards: Call-time pass-by-reference has been deprecated in %s on line %d +*** Testing each() : usage variations *** + +-- Array made up of referenced variables: -- +-- Call each until at the end of the array: -- +array(4) { + [1]=> + unicode(3) "foo" + [u"value"]=> + unicode(3) "foo" + [0]=> + unicode(3) "one" + [u"key"]=> + unicode(3) "one" +} +array(4) { + [1]=> + unicode(3) "bar" + [u"value"]=> + unicode(3) "bar" + [0]=> + int(0) + [u"key"]=> + int(0) +} +bool(false) + +-- Pass an array by reference to each(): -- +array(4) { + [1]=> + unicode(4) "zero" + [u"value"]=> + unicode(4) "zero" + [0]=> + int(0) + [u"key"]=> + int(0) +} +-- Check original array: -- +array(3) { + [0]=> + unicode(4) "zero" + [1]=> + unicode(3) "one" + [2]=> + unicode(3) "two" +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/each_variation5.phpt b/ext/standard/tests/array/each_variation5.phpt new file mode 100644 index 0000000000..13c2a42b39 --- /dev/null +++ b/ext/standard/tests/array/each_variation5.phpt @@ -0,0 +1,157 @@ +--TEST-- +Test each() function : usage variations - Multi-dimensional arrays +--FILE-- + 'un', + array('a', 'b', 'c') + ); + +echo "\n-- Pass each() a two-dimensional array --\n"; +for ($i = 1; $i < count($arr); $i++) { + var_dump( each($arr) ); +} + +echo "\n-- Pass each() a sub-array --\n"; +var_dump( each($arr[2])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Pass each() a two-dimensional array -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} +array(4) { + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["value"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + int(1) + ["key"]=> + int(1) +} +array(4) { + [1]=> + string(2) "un" + ["value"]=> + string(2) "un" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} + +-- Pass each() a sub-array -- +array(4) { + [1]=> + string(1) "a" + ["value"]=> + string(1) "a" + [0]=> + int(0) + ["key"]=> + int(0) +} +Done +--UEXPECTF-- +*** Testing each() : usage variations *** + +-- Pass each() a two-dimensional array -- +array(4) { + [1]=> + unicode(4) "zero" + [u"value"]=> + unicode(4) "zero" + [0]=> + int(0) + [u"key"]=> + int(0) +} +array(4) { + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [u"value"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + int(1) + [u"key"]=> + int(1) +} +array(4) { + [1]=> + unicode(2) "un" + [u"value"]=> + unicode(2) "un" + [0]=> + unicode(3) "one" + [u"key"]=> + unicode(3) "one" +} + +-- Pass each() a sub-array -- +array(4) { + [1]=> + unicode(1) "a" + [u"value"]=> + unicode(1) "a" + [0]=> + int(0) + [u"key"]=> + int(0) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/each_variation6.phpt b/ext/standard/tests/array/each_variation6.phpt new file mode 100644 index 0000000000..267ad14ddf --- /dev/null +++ b/ext/standard/tests/array/each_variation6.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test each() function : usage variations - Internal array pointer +--FILE-- + " . current($arr) . "\n"; + +echo "\n-- Call to each(): --\n"; +var_dump( each($arr) ); + +echo "\n-- New position: --\n"; +echo key($arr) . " => " . current($arr) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Current position: -- +0 => zero + +-- Call to each(): -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- New position: -- +1 => one +Done +--UEXPECTF-- +*** Testing each() : usage variations *** + +-- Current position: -- +0 => zero + +-- Call to each(): -- +array(4) { + [1]=> + unicode(4) "zero" + [u"value"]=> + unicode(4) "zero" + [0]=> + int(0) + [u"key"]=> + int(0) +} + +-- New position: -- +1 => one +Done \ No newline at end of file -- 2.40.0