From: Raghubansh Kumar Date: Fri, 19 Oct 2007 09:19:57 +0000 (+0000) Subject: New testcases for array_unshift() function X-Git-Tag: RELEASE_2_0_0a1~1570 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8b8d0541c2c8622b060079bb581a7b1a939cd5d8;p=php New testcases for array_unshift() function --- diff --git a/ext/standard/tests/array/array_unshift_basic1.phpt b/ext/standard/tests/array/array_unshift_basic1.phpt new file mode 100644 index 0000000000..6a46808a3f --- /dev/null +++ b/ext/standard/tests/array/array_unshift_basic1.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test array_unshift() function : basic functionality - array with default keys for 'array' argument +--FILE-- + +--EXPECTF-- +*** Testing array_unshift() : basic functionality with default key array *** +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(222) + [1]=> + string(5) "hello" + [2]=> + float(12.33) + [3]=> + int(1) + [4]=> + int(2) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : basic functionality with default key array *** +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(222) + [1]=> + unicode(5) "hello" + [2]=> + float(12.33) + [3]=> + int(1) + [4]=> + int(2) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_unshift_error.phpt b/ext/standard/tests/array/array_unshift_error.phpt new file mode 100644 index 0000000000..4ee8909979 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_error.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_unshift() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing array_unshift() : error conditions *** + +-- Testing array_unshift() function with Zero arguments -- + +Warning: Wrong parameter count for array_unshift() in %s on line %d +NULL + +-- Testing array_unshift() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_unshift() in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing array_unshift() : error conditions *** + +-- Testing array_unshift() function with Zero arguments -- + +Warning: Wrong parameter count for array_unshift() in %s on line %d +NULL + +-- Testing array_unshift() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_unshift() in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/array_unshift_variation1.phpt b/ext/standard/tests/array/array_unshift_variation1.phpt new file mode 100644 index 0000000000..cd40ce0a7b --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation1.phpt @@ -0,0 +1,559 @@ +--TEST-- +Test array_unshift() function : usage variations - unexpected values for 'array' argument +--FILE-- + +--EXPECTF-- +*** Testing array_unshift() : unexpected values for $array argument *** + +-- Iteration 1 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(0) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(0) + +-- Iteration 2 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(1) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(1) + +-- Iteration 3 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(12345) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(12345) + +-- Iteration 4 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(-2345) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(-2345) + +-- Iteration 5 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(10.5) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(10.5) + +-- Iteration 6 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(-10.5) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(-10.5) + +-- Iteration 7 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(123456789000) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(123456789000) + +-- Iteration 8 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(1.23456789E-9) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(1.23456789E-9) + +-- Iteration 9 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(0.5) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(0.5) + +-- Iteration 10 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 11 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 12 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +-- Iteration 13 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +-- Iteration 14 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +-- Iteration 15 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +-- Iteration 16 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(0) "" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(0) "" + +-- Iteration 17 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(0) "" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(0) "" + +-- Iteration 18 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(6) "string" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(6) "string" + +-- Iteration 19 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(6) "string" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(6) "string" + +-- Iteration 20 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(11) "hello world" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +string(11) "hello world" + +-- Iteration 21 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +object(classA)#%d (0) { +} + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +object(classA)#%d (0) { +} + +-- Iteration 22 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 23 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 24 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +resource(%d) of type (stream) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +resource(%d) of type (stream) +Done +--UEXPECTF-- +*** Testing array_unshift() : unexpected values for $array argument *** + +-- Iteration 1 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(0) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(0) + +-- Iteration 2 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(1) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(1) + +-- Iteration 3 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(12345) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(12345) + +-- Iteration 4 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(-2345) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +int(-2345) + +-- Iteration 5 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(10.5) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(10.5) + +-- Iteration 6 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(-10.5) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(-10.5) + +-- Iteration 7 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(123456789000) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(123456789000) + +-- Iteration 8 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(1.23456789E-9) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(1.23456789E-9) + +-- Iteration 9 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(0.5) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +float(0.5) + +-- Iteration 10 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 11 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 12 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +-- Iteration 13 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +-- Iteration 14 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(true) + +-- Iteration 15 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +bool(false) + +-- Iteration 16 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(0) "" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(0) "" + +-- Iteration 17 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(0) "" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(0) "" + +-- Iteration 18 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(6) "string" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(6) "string" + +-- Iteration 19 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(6) "string" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(6) "string" + +-- Iteration 20 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(11) "hello world" + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +unicode(11) "hello world" + +-- Iteration 21 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +object(classA)#%d (0) { +} + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +object(classA)#%d (0) { +} + +-- Iteration 22 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 23 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +NULL + +-- Iteration 24 -- +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +resource(%d) of type (stream) + +Warning: array_unshift(): The first argument should be an array in %s on line %d +bool(false) +resource(%d) of type (stream) +Done diff --git a/ext/standard/tests/array/array_unshift_variation2.phpt b/ext/standard/tests/array/array_unshift_variation2.phpt new file mode 100644 index 0000000000..d28bc832d6 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation2.phpt @@ -0,0 +1,1999 @@ +--TEST-- +Test array_unshift() function : usage variations - all possible values for 'var' argument +--FILE-- + "first", "s" => 'second', 1, 2.222); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// heredoc string +$heredoc = << 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // object data +/*26*/ new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable +/*29*/ $fp +); + +// loop through each element of $vars to check the functionality of array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : all possible values for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + int(0) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + int(1) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(1) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + int(12345) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(12345) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(-2345) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(-2345) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + float(10.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(10.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + float(-10.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(-10.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + float(123456789000) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(123456789000) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + float(1.23456789E-9) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(1.23456789E-9) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 9 -- +int(5) +array(5) { + [0]=> + float(0.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(0.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + array(0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 11 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 12 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(1) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 13 -- +int(5) +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 15 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 16 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 17 -- +int(5) +array(5) { + [0]=> + bool(true) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 18 -- +int(5) +array(5) { + [0]=> + bool(false) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 19 -- +int(5) +array(5) { + [0]=> + bool(true) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 20 -- +int(5) +array(5) { + [0]=> + bool(false) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 21 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 22 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 23 -- +int(5) +array(5) { + [0]=> + string(6) "string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(6) "string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 24 -- +int(5) +array(5) { + [0]=> + string(6) "string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(6) "string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 25 -- +int(5) +array(5) { + [0]=> + string(11) "hello world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(11) "hello world" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 26 -- +int(5) +array(5) { + [0]=> + object(classA)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 27 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 28 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 29 -- +int(5) +array(5) { + [0]=> + resource(%d) of type (stream) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + resource(%d) of type (stream) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : all possible values for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + int(0) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(0) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + int(1) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(1) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + int(12345) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(12345) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(-2345) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(-2345) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + float(10.5) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(10.5) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + float(-10.5) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(-10.5) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + float(123456789000) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(123456789000) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + float(1.23456789E-9) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(1.23456789E-9) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 9 -- +int(5) +array(5) { + [0]=> + float(0.5) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(0.5) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + array(0) { + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(0) { + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 11 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 12 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(1) + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 13 -- +int(5) +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + array(2) { + [u"color"]=> + unicode(3) "red" + [u"item"]=> + unicode(3) "pen" + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + [u"color"]=> + unicode(3) "red" + [u"item"]=> + unicode(3) "pen" + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 15 -- +int(5) +array(5) { + [0]=> + NULL + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 16 -- +int(5) +array(5) { + [0]=> + NULL + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 17 -- +int(5) +array(5) { + [0]=> + bool(true) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 18 -- +int(5) +array(5) { + [0]=> + bool(false) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 19 -- +int(5) +array(5) { + [0]=> + bool(true) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 20 -- +int(5) +array(5) { + [0]=> + bool(false) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 21 -- +int(5) +array(5) { + [0]=> + unicode(0) "" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(0) "" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 22 -- +int(5) +array(5) { + [0]=> + unicode(0) "" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(0) "" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 23 -- +int(5) +array(5) { + [0]=> + unicode(6) "string" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(6) "string" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 24 -- +int(5) +array(5) { + [0]=> + unicode(6) "string" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(6) "string" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 25 -- +int(5) +array(5) { + [0]=> + unicode(11) "hello world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(11) "hello world" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 26 -- +int(5) +array(5) { + [0]=> + object(classA)#%d (0) { + } + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 27 -- +int(5) +array(5) { + [0]=> + NULL + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 28 -- +int(5) +array(5) { + [0]=> + NULL + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 29 -- +int(5) +array(5) { + [0]=> + resource(%d) of type (stream) + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + resource(%d) of type (stream) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation3.phpt b/ext/standard/tests/array/array_unshift_variation3.phpt new file mode 100644 index 0000000000..0ce49ee920 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation3.phpt @@ -0,0 +1,1068 @@ +--TEST-- +Test array_unshift() function : usage variations - different array values for 'array' argument +--FILE-- + "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : different arrays for $array argument *** +-- Iteration 1 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(1) + [4]=> + int(2) +} +-- Iteration 2 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + float(1.1) + [2]=> + float(2.2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + float(1.1) + [4]=> + float(2.2) +} +-- Iteration 3 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(1) + } +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + array(1) { + [0]=> + int(2) + } + [4]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + bool(false) + [2]=> + bool(true) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + bool(false) + [4]=> + bool(true) +} +-- Iteration 5 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 6 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + NULL +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + NULL +} +-- Iteration 7 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(1) "a" + [2]=> + string(4) "aaaa" + [3]=> + string(1) "b" + [4]=> + string(4) "bbbb" + [5]=> + string(1) "c" + [6]=> + string(5) "ccccc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "a" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "b" + [6]=> + string(4) "bbbb" + [7]=> + string(1) "c" + [8]=> + string(5) "ccccc" +} +-- Iteration 8 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 9 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + int(10) + [2]=> + int(20) + [3]=> + int(40) + [4]=> + int(30) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(10) + [4]=> + int(20) + [5]=> + int(40) + [6]=> + int(30) +} +-- Iteration 11 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + int(1) + [1]=> + string(3) "two" + [2]=> + string(4) "four" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(4) "true" + [2]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(4) "true" + [4]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + NULL + [6]=> + NULL + [7]=> + bool(false) + [8]=> + bool(true) +} +-- Iteration 17 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 18 -- +int(4) +array(4) { + [0]=> + int(10) + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : different arrays for $array argument *** +-- Iteration 1 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + int(1) + [4]=> + int(2) +} +-- Iteration 2 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + float(1.1) + [2]=> + float(2.2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + float(1.1) + [4]=> + float(2.2) +} +-- Iteration 3 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(1) + } +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + array(1) { + [0]=> + int(2) + } + [4]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + bool(false) + [2]=> + bool(true) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + bool(false) + [4]=> + bool(true) +} +-- Iteration 5 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" +} +-- Iteration 6 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + NULL +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + NULL +} +-- Iteration 7 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(1) "a" + [2]=> + unicode(4) "aaaa" + [3]=> + unicode(1) "b" + [4]=> + unicode(4) "bbbb" + [5]=> + unicode(1) "c" + [6]=> + unicode(5) "ccccc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(1) "a" + [4]=> + unicode(4) "aaaa" + [5]=> + unicode(1) "b" + [6]=> + unicode(4) "bbbb" + [7]=> + unicode(1) "c" + [8]=> + unicode(5) "ccccc" +} +-- Iteration 8 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(3) "one" + [2]=> + unicode(3) "two" + [3]=> + unicode(5) "three" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(3) "one" + [4]=> + unicode(3) "two" + [5]=> + unicode(5) "three" +} +-- Iteration 9 -- +int(4) +array(4) { + [0]=> + int(10) + [u"one"]=> + int(1) + [u"two"]=> + int(2) + [u"three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"one"]=> + int(1) + [u"two"]=> + int(2) + [u"three"]=> + int(3) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + int(10) + [2]=> + int(20) + [3]=> + int(40) + [4]=> + int(30) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + int(10) + [4]=> + int(20) + [5]=> + int(40) + [6]=> + int(30) +} +-- Iteration 11 -- +int(4) +array(4) { + [0]=> + int(10) + [u"one"]=> + unicode(3) "ten" + [u"two"]=> + unicode(6) "twenty" + [u"three"]=> + unicode(6) "thirty" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"one"]=> + unicode(3) "ten" + [u"two"]=> + unicode(6) "twenty" + [u"three"]=> + unicode(6) "thirty" +} +-- Iteration 12 -- +int(4) +array(4) { + [0]=> + int(10) + [u"one"]=> + int(1) + [1]=> + unicode(3) "two" + [2]=> + unicode(4) "four" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"one"]=> + int(1) + [3]=> + unicode(3) "two" + [4]=> + unicode(4) "four" +} +-- Iteration 13 -- +int(4) +array(4) { + [0]=> + int(10) + [u""]=> + unicode(4) "null" + [u"NULL"]=> + NULL + [u"null"]=> + NULL +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u""]=> + unicode(4) "null" + [u"NULL"]=> + NULL + [u"null"]=> + NULL +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(4) "true" + [2]=> + unicode(5) "false" + [u"false"]=> + bool(false) + [u"true"]=> + bool(true) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(4) "true" + [4]=> + unicode(5) "false" + [u"false"]=> + bool(false) + [u"true"]=> + bool(true) +} +-- Iteration 15 -- +int(4) +array(4) { + [0]=> + int(10) + [u""]=> + unicode(6) "emptys" + [u"emptyd"]=> + unicode(0) "" + [u"emptys"]=> + unicode(0) "" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u""]=> + unicode(6) "emptys" + [u"emptyd"]=> + unicode(0) "" + [u"emptys"]=> + unicode(0) "" +} +-- Iteration 16 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(0) "" + [2]=> + unicode(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(0) "" + [4]=> + unicode(0) "" + [5]=> + NULL + [6]=> + NULL + [7]=> + bool(false) + [8]=> + bool(true) +} +-- Iteration 17 -- +int(4) +array(4) { + [0]=> + int(10) + [u""]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 18 -- +int(4) +array(4) { + [0]=> + int(10) + [u"One"]=> + int(10) + [u"two"]=> + int(20) + [u"three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"One"]=> + int(10) + [u"two"]=> + int(20) + [u"three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation4.phpt b/ext/standard/tests/array/array_unshift_variation4.phpt new file mode 100644 index 0000000000..aad52bdf9d --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation4.phpt @@ -0,0 +1,680 @@ +--TEST-- +Test array_unshift() function : usage variations - assoc. array with diff. keys for 'array' argument +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable + array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed keys +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : associative array with different keys *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(1) "0" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "0" +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(1) "1" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "1" +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "1" + [4]=> + string(1) "2" + [5]=> + string(1) "3" + [6]=> + string(1) "4" +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(5) "float" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "float" +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(2) "f1" + [2]=> + string(2) "f2" + [3]=> + string(2) "f3" + [4]=> + string(2) "f4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(2) "f1" + [4]=> + string(2) "f2" + [5]=> + string(2) "f3" + [6]=> + string(2) "f4" +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +int(2) +array(2) { + [0]=> + int(10) + [""]=> + string(5) "hello" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(5) "hello" +} +-- Iteration 11 -- +int(7) +array(7) { + [0]=> + int(10) + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [1]=> + string(3) "int" + [2]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [3]=> + string(3) "int" + [4]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done +--UEXPECTF-- +*** Testing array_unshift() : associative array with different keys *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + unicode(1) "0" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(1) "0" +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + unicode(1) "1" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(1) "1" +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(1) "1" + [2]=> + unicode(1) "2" + [3]=> + unicode(1) "3" + [4]=> + unicode(1) "4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(1) "1" + [4]=> + unicode(1) "2" + [5]=> + unicode(1) "3" + [6]=> + unicode(1) "4" +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + unicode(5) "float" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(5) "float" +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(2) "f1" + [2]=> + unicode(2) "f2" + [3]=> + unicode(2) "f3" + [4]=> + unicode(2) "f4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(2) "f1" + [4]=> + unicode(2) "f2" + [5]=> + unicode(2) "f3" + [6]=> + unicode(2) "f4" +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + [u"\tHello"]=> + int(111) + [u"re\td"]=> + unicode(5) "color" + [u"\v\fworld"]=> + float(2.2) + [u"pen\n"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"\tHello"]=> + int(111) + [u"re\td"]=> + unicode(5) "color" + [u"\v\fworld"]=> + float(2.2) + [u"pen\n"]=> + int(33) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [u" Hello"]=> + int(111) + [u"re d"]=> + unicode(5) "color" + [u" world"]=> + float(2.2) + [u"pen +"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u" Hello"]=> + int(111) + [u"re d"]=> + unicode(5) "color" + [u" world"]=> + float(2.2) + [u"pen +"]=> + int(33) +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [u"Hello world"]=> + unicode(6) "string" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(5) "hello" + [u"Hello world"]=> + unicode(6) "string" +} +-- Iteration 10 -- +int(2) +array(2) { + [0]=> + int(10) + [u""]=> + unicode(5) "hello" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u""]=> + unicode(5) "hello" +} +-- Iteration 11 -- +int(7) +array(7) { + [0]=> + int(10) + [u"hello"]=> + int(1) + [u"fruit"]=> + float(2.2) + [1]=> + unicode(3) "int" + [2]=> + unicode(5) "float" + [u""]=> + unicode(5) "unset" + [u"Hello world"]=> + unicode(7) "heredoc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"hello"]=> + int(1) + [u"fruit"]=> + float(2.2) + [3]=> + unicode(3) "int" + [4]=> + unicode(5) "float" + [u""]=> + unicode(5) "unset" + [u"Hello world"]=> + unicode(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation5.phpt b/ext/standard/tests/array/array_unshift_variation5.phpt new file mode 100644 index 0000000000..7d87b2f930 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation5.phpt @@ -0,0 +1,698 @@ +--TEST-- +Test array_unshift() function : usage variations - assoc. array with diff values for 'array' argument +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : associative array with different values *** +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(0) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(0) +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(1) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(1) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [3]=> + int(4) +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + ["float"]=> + float(2.3333) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [1]=> + float(4.8999992284) + ["f4"]=> + float(33333333.333333) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(33333333.333333) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" + [3]=> + string(4) "pen +" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [4]=> + string(7) " world" + [5]=> + string(4) "pen +" +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [4]=> + string(9) "\v\fworld" + [5]=> + string(5) "pen\n" +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [3]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +int(11) +array(11) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + [4]=> + object(classA)#%d (0) { + } + [5]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done +--UEXPECTF-- +*** Testing array_unshift() : associative array with different values *** +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(0) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + int(0) +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(1) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + int(1) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + [u"one"]=> + int(1) + [u"two"]=> + int(2) + [u"three"]=> + int(3) + [1]=> + int(4) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"one"]=> + int(1) + [u"two"]=> + int(2) + [u"three"]=> + int(3) + [3]=> + int(4) +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + [u"float"]=> + float(2.3333) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"float"]=> + float(2.3333) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + [u"f1"]=> + float(1.2) + [u"f2"]=> + float(3.33) + [1]=> + float(4.8999992284) + [u"f4"]=> + float(33333333.333333) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f1"]=> + float(1.2) + [u"f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + [u"f4"]=> + float(33333333.333333) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(6) " Hello" + [u"red"]=> + unicode(6) "col or" + [2]=> + unicode(7) " world" + [3]=> + unicode(4) "pen +" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(6) " Hello" + [u"red"]=> + unicode(6) "col or" + [4]=> + unicode(7) " world" + [5]=> + unicode(4) "pen +" +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(7) "\tHello" + [u"red"]=> + unicode(7) "col\tor" + [2]=> + unicode(9) "\v\fworld" + [3]=> + unicode(5) "pen\n" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(7) "\tHello" + [u"red"]=> + unicode(7) "col\tor" + [4]=> + unicode(9) "\v\fworld" + [5]=> + unicode(5) "pen\n" +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [u"heredoc"]=> + unicode(11) "Hello world" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(5) "hello" + [u"heredoc"]=> + unicode(11) "Hello world" +} +-- Iteration 10 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + object(classA)#%d (0) { + } + [u"unset"]=> + NULL + [u"resource"]=> + resource(%d) of type (stream) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + object(classA)#%d (0) { + } + [u"unset"]=> + NULL + [u"resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +int(9) +array(9) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [3]=> + unicode(5) "fruit" + [u"resource"]=> + resource(%d) of type (stream) + [u"int"]=> + int(133) + [u"float"]=> + float(444.432) + [u"unset"]=> + NULL + [u"heredoc"]=> + unicode(11) "Hello world" +} +int(11) +array(11) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + unicode(5) "hello" + [4]=> + object(classA)#%d (0) { + } + [5]=> + unicode(5) "fruit" + [u"resource"]=> + resource(%d) of type (stream) + [u"int"]=> + int(133) + [u"float"]=> + float(444.432) + [u"unset"]=> + NULL + [u"heredoc"]=> + unicode(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation6.phpt b/ext/standard/tests/array/array_unshift_variation6.phpt new file mode 100644 index 0000000000..f7376cc3b5 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation6.phpt @@ -0,0 +1,317 @@ +--TEST-- +Test array_unshift() function : usage variations - two dimensional arrays for 'array' argument +--FILE-- + 'red', 'item' => 'pen', 'place' => 'LA'), + + // numeric array + array(1, 2, 3, 4, 5), + + // combination of numeric and associative arrays + array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball') +); + +/* Passing the entire $two_dimensional_array to $array */ + +/* With default argument */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array; +var_dump( array_unshift($temp_array, $var) ); // whole 2-d array + +// dumps the resulting array +var_dump($temp_array); + +/* With optional arguments */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array; +var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // whole 2-d array + +// dumps the resulting array +var_dump($temp_array); + +/* Passing the sub-array within the $two_dimensional_array to $array argument */ + +/* With default argument */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array[0]; +var_dump( array_unshift($temp_array, $var) ); // sub array + +// dumps the resulting array +var_dump($temp_array); + +/* With optional arguments */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array[0]; +var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // sub array + +// dumps the resulting array +var_dump($temp_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : two dimensional arrays for $array argument *** +int(4) +array(4) { + [0]=> + int(10) + [1]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } + [2]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [3]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } + [4]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [5]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } +} +int(4) +array(4) { + [0]=> + int(10) + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" +} +Done +--UEXPECTF-- +*** Testing array_unshift() : two dimensional arrays for $array argument *** +int(4) +array(4) { + [0]=> + int(10) + [1]=> + array(3) { + [u"color"]=> + unicode(3) "red" + [u"item"]=> + unicode(3) "pen" + [u"place"]=> + unicode(2) "LA" + } + [2]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [3]=> + array(7) { + [u"a"]=> + unicode(5) "green" + [0]=> + unicode(3) "red" + [1]=> + unicode(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + unicode(6) "orange" + [u"item"]=> + unicode(4) "ball" + } +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [3]=> + array(3) { + [u"color"]=> + unicode(3) "red" + [u"item"]=> + unicode(3) "pen" + [u"place"]=> + unicode(2) "LA" + } + [4]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [5]=> + array(7) { + [u"a"]=> + unicode(5) "green" + [0]=> + unicode(3) "red" + [1]=> + unicode(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + unicode(6) "orange" + [u"item"]=> + unicode(4) "ball" + } +} +int(4) +array(4) { + [0]=> + int(10) + [u"color"]=> + unicode(3) "red" + [u"item"]=> + unicode(3) "pen" + [u"place"]=> + unicode(2) "LA" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"color"]=> + unicode(3) "red" + [u"item"]=> + unicode(3) "pen" + [u"place"]=> + unicode(2) "LA" +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation7.phpt b/ext/standard/tests/array/array_unshift_variation7.phpt new file mode 100644 index 0000000000..b75ad0dc08 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation7.phpt @@ -0,0 +1,384 @@ +--TEST-- +Test array_unshift() function : usage variations - double quoted strings for 'var' argument +--FILE-- + "first", "s" => 'second', 1, 2.222); + +// different variations of double quoted strings to be passed to $var argument +$vars = array ( + "\$ -> This represents the dollar sign. hello dollar!!!", + "\t\r\v The quick brown fo\fx jumped over the lazy dog", + "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\", + "hello world\\t", + "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + +// dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : double quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(53) "$ -> This represents the dollar sign. hello dollar!!!" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(53) "$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(49) " + The quick brown fo x jumped over the lazy dog" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(49) " + The quick brown fo x jumped over the lazy dog" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(13) "hello world\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(13) "hello world\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(70) "This is a text in bold letters +\s\malong with slashes + : HELLO WORLD " + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(70) "This is a text in bold letters +\s\malong with slashes + : HELLO WORLD " + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : double quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + unicode(53) "$ -> This represents the dollar sign. hello dollar!!!" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(53) "$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + unicode(49) " + The quick brown fo x jumped over the lazy dog" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(49) " + The quick brown fo x jumped over the lazy dog" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + unicode(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + unicode(13) "hello world\t" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(13) "hello world\t" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + unicode(70) "This is a text in bold letters +\s\malong with slashes + : HELLO WORLD " + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(70) "This is a text in bold letters +\s\malong with slashes + : HELLO WORLD " + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation8.phpt b/ext/standard/tests/array/array_unshift_variation8.phpt new file mode 100644 index 0000000000..08f03386e9 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation8.phpt @@ -0,0 +1,372 @@ +--TEST-- +Test array_unshift() function : usage variations - single quoted strings for 'var' argument +--FILE-- + "first", "s" => 'second', 1, 2.222); + +// different variations of single quoted strings to be passed to $var argument +$vars = array ( + '\$ -> This represents the dollar sign. hello dollar!!!', + '\t\r\v The quick brown fo\fx jumped over the lazy dog', + 'This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\', + 'hello world\\t', + 'This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t' +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : single quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(54) "\$ -> This represents the dollar sign. hello dollar!!!" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(54) "\$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(13) "hello world\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(13) "hello world\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : single quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + unicode(54) "\$ -> This represents the dollar sign. hello dollar!!!" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(54) "\$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + unicode(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + unicode(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + unicode(13) "hello world\t" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(13) "hello world\t" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + unicode(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation9.phpt b/ext/standard/tests/array/array_unshift_variation9.phpt new file mode 100644 index 0000000000..77d2f3a131 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation9.phpt @@ -0,0 +1,526 @@ +--TEST-- +Test array_unshift() function : usage variations - heredoc strings for 'var' argument +--FILE-- +22 +2222 != 1111.\t 0000 = 0000\n +EOT; + +// heredoc with quote chars & slash +$quote_char_string = << "first", "s" => 'second', 1, 2.222); + +// different heredoc strings to be passed to $var argument +$vars = array( + $empty_string, + $blank_line, + $multiline_string, + $diff_whitespaces, + $numeric_string, + $quote_char_string +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with all possible arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : heredoc strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(1) " +" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(1) " +" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(88) "hello + world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(88) "hello + world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + string(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done +--UEXPECTF-- +*** Testing array_unshift() : heredoc strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + unicode(0) "" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(0) "" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + unicode(1) " +" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(1) " +" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + unicode(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + unicode(88) "hello + world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(88) "hello + world +1111 != 2222 +heredoc +double quoted string. with different white spaces" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + unicode(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + unicode(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + unicode(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + [1]=> + unicode(5) "hello" + [2]=> + unicode(5) "world" + [u"f"]=> + unicode(5) "first" + [u"s"]=> + unicode(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done