From: Raghubansh Kumar Date: Sat, 12 May 2007 11:20:52 +0000 (+0000) Subject: New version of 005.phpt, array_keys.phpt, array_values.phpt, extract.phpt, 009.phpt... X-Git-Tag: RELEASE_1_2_0~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c7cec34d1193862b046bafdbece77d253ee55184;p=php New version of 005.phpt, array_keys.phpt, array_values.phpt, extract.phpt, 009.phpt, array_map.phpt, each.phpt, array_change_key_case.phpt, array_pop.phpt, end.phpt, array_key_exists.phpt, array_search.phpt, extract.php --- diff --git a/ext/standard/tests/array/005.phpt b/ext/standard/tests/array/005.phpt index d38bf940d1..f72493215f 100644 --- a/ext/standard/tests/array/005.phpt +++ b/ext/standard/tests/array/005.phpt @@ -1,68 +1,291 @@ --TEST-- -Test array_shift behaviour +Test array_shift() function --FILE-- "foo", "4" => "bar", "5" => "fubar"); -$c = array("a" => "foo", "b" => "bar", "c" => "fubar"); +$empty_array = array(); +$number = 5; +$str = "abc"; -/* simple array */ -echo array_shift($a), "\n"; -var_dump($a); -/* numerical assoc indices */ -echo array_shift($b), "\n"; -var_dump($b); +/* Various combinations of arrays to be used for the test */ +$mixed_array = array( + array(), + array( 1,2,3,4,5,6,7,8,9 ), + array( "One", "_Two", "Three", "Four", "Five" ), + array( 6, "six", 7, "seven", 8, "eight", 9, "nine" ), + array( "a" => "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); -/* assoc indices */ -echo array_shift($c), "\n"; -var_dump($c); +/* Testing Error Conditions */ +echo "\n*** Testing Error Conditions ***\n"; +/* Zero argument */ +var_dump( array_shift() ); + +/* Scalar argument */ +var_dump( array_shift($number) ); + +/* String argument */ +var_dump( array_shift($str) ); + +/* Invalid Number of arguments */ +var_dump( array_shift($mixed_array[1],$mixed_array[2]) ); + +/* Empty Array as argument */ +var_dump( array_shift($empty_array) ); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) { + echo "\n-- Input Array for Iteration $counter is -- \n"; + print_r( $sub_array ); + echo "\nOutput after shift is :\n"; + var_dump( array_shift($sub_array) ); + $counter++; +} + +/*Checking for internal array pointer beint reset when shift is called */ + +echo"\n*** Checking for internal array pointer being reset when shift is called ***\n"; + +echo "\nCurrent Element is : "; +var_dump( current($mixed_array[1]) ); + +echo "\nNext Element is : "; +var_dump( next($mixed_array[1]) ); + +echo "\nNext Element is : "; +var_dump( next($mixed_array[1]) ); + +echo "\nshifted Element is : "; +var_dump( array_shift($mixed_array[1]) ); + +echo "\nCurrent Element after shift operation is: "; +var_dump( current($mixed_array[1]) ); + +echo"Done"; ?> ---EXPECT-- -foo -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(5) "fubar" -} -foo -array(2) { - [0]=> - string(3) "bar" - [1]=> - string(5) "fubar" -} -foo -array(2) { - ["b"]=> - string(3) "bar" - ["c"]=> - string(5) "fubar" -} ---UEXPECT-- -foo -array(2) { - [0]=> - unicode(3) "bar" - [1]=> - unicode(5) "fubar" -} -foo -array(2) { +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_shift() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_shift() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_shift() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_shift() expects exactly 1 parameter, 2 given in %s on line %d +NULL +NULL + +*** Testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +Output after shift is : +NULL + +-- Input Array for Iteration 2 is -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 +) + +Output after shift is : +int(1) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +Output after shift is : +string(3) "One" + +-- Input Array for Iteration 4 is -- +Array +( + [0] => 6 + [1] => six + [2] => 7 + [3] => seven + [4] => 8 + [5] => eight + [6] => 9 + [7] => nine +) + +Output after shift is : +int(6) + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +Output after shift is : +string(3) "aaa" + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +Output after shift is : +string(3) "one" + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +Output after shift is : +string(3) "one" + +-- Input Array for Iteration 8 is -- +Array +( + [f] => fff + [1] => one + [4] => 6 + [] => 3 + [2] => float + [F] => FFF + [blank] => + [3] => 3.7 + [5] => Five + [6] => 8.6 + [4name] => jonny + [a] => +) + +Output after shift is : +string(3) "fff" + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +Output after shift is : +int(12) + +-- Input Array for Iteration 10 is -- +Array +( + [0] => Array + ( + [0] => oNe + [1] => tWo + [2] => 4 + ) + + [1] => Array + ( + [0] => 10 + [1] => 20 + [2] => 30 + [3] => 40 + [4] => 50 + ) + + [2] => Array + ( + ) + +) + +Output after shift is : +array(3) { [0]=> - unicode(3) "bar" + string(3) "oNe" [1]=> - unicode(5) "fubar" -} -foo -array(2) { - [u"b"]=> - unicode(3) "bar" - [u"c"]=> - unicode(5) "fubar" + string(3) "tWo" + [2]=> + int(4) } + +-- Input Array for Iteration 11 is -- +Array +( + [one] => 2 + [three] => 3 + [0] => 3 + [1] => 4 + [3] => 33 + [4] => 44 + [5] => 57 + [6] => 6 + [5.4] => 554 + [5.7] => 557 +) + +Output after shift is : +int(2) + +*** Checking for internal array pointer being reset when shift is called *** + +Current Element is : int(1) + +Next Element is : int(2) + +Next Element is : int(3) + +shifted Element is : int(1) + +Current Element after shift operation is: int(2) +Done diff --git a/ext/standard/tests/array/009.phpt b/ext/standard/tests/array/009.phpt new file mode 100644 index 0000000000..f88f8763fa --- /dev/null +++ b/ext/standard/tests/array/009.phpt @@ -0,0 +1,535 @@ +--TEST-- +Test key(), current(), next() & reset() functions +--FILE-- + returns the index element of the current array position + mixed current ( array &$array ) -> returns the current element in the array + mixed next ( array &$array ) -> similar to current() but advances the internal pointer to next element + mixed reset ( array &$array ) -> Reset the internal pointer to first element +*/ + +$basic_arrays = array ( + array(0), // array with element as 0 + array(1), // array with single element + array(1,2, 3, -1, -2, -3), // array of integers + array(1.1, 2.2, 3.3, -1.1, -2.2, -3.3), // array of floats + array('a', 'b', 'c', "ab", "ac", "ad"), // string array + array("a" => "apple", "b" => "book", "c" => "cook"), // associative array + array('d' => 'drink', 'p' => 'port', 's' => 'set'), // another associative array + array(1 => 'One', 2 => 'two', 3 => "three") // associative array with key as integers +); + +$varient_arrays = array ( + array(), // empty array + array(""), // array with null string + array(NULL),// array with NULL + array(null),// array with null + array(NULL, true, null, "", 1), // mixed array + array(-1.5 => "test", -2 => "rest", 2.5 => "two", + "" => "string", 0 => "zero", "" => "" ) // mixed array +); + +echo "*** Testing basic operations ***\n"; +$loop_count = 1; +foreach ($basic_arrays as $sub_array ) { + echo "-- Iteration $loop_count --\n"; + $loop_count++; + $c = count ($sub_array); + $c++; // increment by one to create the situation of accessing beyond array size + while ( $c ) { + var_dump( current($sub_array)); // current element + var_dump( key($sub_array) ); // key of the current element + var_dump( next($sub_array) ); // move to next element + $c --; + } + var_dump( reset($sub_array) ); // reset the internal pointer to first element + var_dump( key($sub_array) ); // access the array after reset + var_dump( $sub_array ); // dump the array to see that its intact + + echo "\n"; +} + +echo "\n*** Testing possible variations ***\n"; +$loop_count = 1; +foreach ($varient_arrays as $sub_array ) { + echo "-- Iteration $loop_count --\n"; + $loop_count++; + $c = count ($sub_array); + $c++; // increment by one to create the situation of accessing beyond array size + while ( $c ) { + var_dump( current($sub_array)); // current element + var_dump( key($sub_array) ); // key of the current element + var_dump( next($sub_array) ); // move to next element + $c --; + } + var_dump( reset($sub_array) ); // reset the internal pointer to first element + var_dump( key($sub_array) ); // access the array after reset + var_dump( $sub_array ); // dump the array to see that its intact + echo "\n"; +} + +/*test these functions on array which is already unset */ +echo "\n-- Testing variation: when array is unset --\n"; +$unset_array = array (1); +unset($unset_array); + +var_dump( current($unset_array) ); +var_dump( key($unset_array) ); +var_dump( next($unset_array) ); +var_dump( reset($unset_array) ); + + +echo "\n*** Testing error conditions ***\n"; +//Zero argument, expected 1 argument +var_dump( key() ); +var_dump( current() ); +var_dump( reset() ); +var_dump( next() ); + +// args more than expected, expected 1 argument +$temp_array = array(1); +var_dump( key($temp_array, $temp_array) ); +var_dump( current($temp_array, $temp_array) ); +var_dump( reset($temp_array, $temp_array) ); +var_dump( next($temp_array, $temp_array) ); + +// invalid args type, valid arguement: array +$int_var = 1; +$float_var = 1.5; +$string = "string"; +var_dump( key($int_var) ); +var_dump( key($float_var) ); +var_dump( key($string) ); + +var_dump( current($int_var) ); +var_dump( current($float_var) ); +var_dump( current($string) ); + +var_dump( next($int_var) ); +var_dump( next($float_var) ); +var_dump( next($string) ); + +var_dump( reset($int_var) ); +var_dump( reset($float_var) ); +var_dump( reset($string) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing basic operations *** +-- Iteration 1 -- +int(0) +int(0) +bool(false) +bool(false) +NULL +bool(false) +int(0) +int(0) +array(1) { + [0]=> + int(0) +} + +-- Iteration 2 -- +int(1) +int(0) +bool(false) +bool(false) +NULL +bool(false) +int(1) +int(0) +array(1) { + [0]=> + int(1) +} + +-- Iteration 3 -- +int(1) +int(0) +int(2) +int(2) +int(1) +int(3) +int(3) +int(2) +int(-1) +int(-1) +int(3) +int(-2) +int(-2) +int(4) +int(-3) +int(-3) +int(5) +bool(false) +bool(false) +NULL +bool(false) +int(1) +int(0) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(-1) + [4]=> + int(-2) + [5]=> + int(-3) +} + +-- Iteration 4 -- +float(1.1) +int(0) +float(2.2) +float(2.2) +int(1) +float(3.3) +float(3.3) +int(2) +float(-1.1) +float(-1.1) +int(3) +float(-2.2) +float(-2.2) +int(4) +float(-3.3) +float(-3.3) +int(5) +bool(false) +bool(false) +NULL +bool(false) +float(1.1) +int(0) +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + float(3.3) + [3]=> + float(-1.1) + [4]=> + float(-2.2) + [5]=> + float(-3.3) +} + +-- Iteration 5 -- +string(1) "a" +int(0) +string(1) "b" +string(1) "b" +int(1) +string(1) "c" +string(1) "c" +int(2) +string(2) "ab" +string(2) "ab" +int(3) +string(2) "ac" +string(2) "ac" +int(4) +string(2) "ad" +string(2) "ad" +int(5) +bool(false) +bool(false) +NULL +bool(false) +string(1) "a" +int(0) +array(6) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(2) "ab" + [4]=> + string(2) "ac" + [5]=> + string(2) "ad" +} + +-- Iteration 6 -- +string(5) "apple" +string(1) "a" +string(4) "book" +string(4) "book" +string(1) "b" +string(4) "cook" +string(4) "cook" +string(1) "c" +bool(false) +bool(false) +NULL +bool(false) +string(5) "apple" +string(1) "a" +array(3) { + ["a"]=> + string(5) "apple" + ["b"]=> + string(4) "book" + ["c"]=> + string(4) "cook" +} + +-- Iteration 7 -- +string(5) "drink" +string(1) "d" +string(4) "port" +string(4) "port" +string(1) "p" +string(3) "set" +string(3) "set" +string(1) "s" +bool(false) +bool(false) +NULL +bool(false) +string(5) "drink" +string(1) "d" +array(3) { + ["d"]=> + string(5) "drink" + ["p"]=> + string(4) "port" + ["s"]=> + string(3) "set" +} + +-- Iteration 8 -- +string(3) "One" +int(1) +string(3) "two" +string(3) "two" +int(2) +string(5) "three" +string(5) "three" +int(3) +bool(false) +bool(false) +NULL +bool(false) +string(3) "One" +int(1) +array(3) { + [1]=> + string(3) "One" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} + + +*** Testing possible variations *** +-- Iteration 1 -- +bool(false) +NULL +bool(false) +bool(false) +NULL +array(0) { +} + +-- Iteration 2 -- +string(0) "" +int(0) +bool(false) +bool(false) +NULL +bool(false) +string(0) "" +int(0) +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 3 -- +NULL +int(0) +bool(false) +bool(false) +NULL +bool(false) +NULL +int(0) +array(1) { + [0]=> + NULL +} + +-- Iteration 4 -- +NULL +int(0) +bool(false) +bool(false) +NULL +bool(false) +NULL +int(0) +array(1) { + [0]=> + NULL +} + +-- Iteration 5 -- +NULL +int(0) +bool(true) +bool(true) +int(1) +NULL +NULL +int(2) +string(0) "" +string(0) "" +int(3) +int(1) +int(1) +int(4) +bool(false) +bool(false) +NULL +bool(false) +NULL +int(0) +array(5) { + [0]=> + NULL + [1]=> + bool(true) + [2]=> + NULL + [3]=> + string(0) "" + [4]=> + int(1) +} + +-- Iteration 6 -- +string(4) "test" +int(-1) +string(4) "rest" +string(4) "rest" +int(-2) +string(3) "two" +string(3) "two" +int(2) +string(0) "" +string(0) "" +string(0) "" +string(4) "zero" +string(4) "zero" +int(0) +bool(false) +bool(false) +NULL +bool(false) +string(4) "test" +int(-1) +array(5) { + [-1]=> + string(4) "test" + [-2]=> + string(4) "rest" + [2]=> + string(3) "two" + [""]=> + string(0) "" + [0]=> + string(4) "zero" +} + + +-- Testing variation: when array is unset -- + +Warning: current() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: next() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +*** Testing error conditions *** + +Warning: key() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: current() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: reset() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: next() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: key() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: current() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: reset() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: next() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: current() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: current() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: current() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: next() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: next() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: next() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_change_key_case.phpt b/ext/standard/tests/array/array_change_key_case.phpt index 11adce868f..387c1039c9 100644 --- a/ext/standard/tests/array/array_change_key_case.phpt +++ b/ext/standard/tests/array/array_change_key_case.phpt @@ -1,56 +1,91 @@ --TEST-- -array_change_key_case() +Test array_change_key_case() function --FILE-- 1), - array ("a" => 1), - array ("Z" => 1), - array ("one" => 1), - array ("ONE" => 1), - array ("OnE" => 1), - array ("oNe" => 1), - array ("one" => 1, "two" => 2), - array ("ONE" => 1, "two" => 2), - array ("OnE" => 1, "two" => 2), - array ("oNe" => 1, "two" => 2), - array ("one" => 1, "TWO" => 2), - array ("ONE" => 1, "TWO" => 2), - array ("OnE" => 1, "TWO" => 2), - array ("oNe" => 1, "TWO" => 2), - array ("one" => 1, "TwO" => 2), - array ("ONE" => 1, "TwO" => 2), - array ("OnE" => 1, "TwO" => 2), - array ("oNe" => 1, "TwO" => 2), - array ("one" => 1, "tWo" => 2), - array ("ONE" => 1, "tWo" => 2), - array ("OnE" => 1, "tWo" => 2), - array ("oNe" => 1, "tWo" => 2), - array ("one" => 1, 2), - array ("ONE" => 1, 2), - array ("OnE" => 1, 2), - array ("oNe" => 1, 2), - array ("ONE" => 1, "TWO" => 2, "THREE" => 3, "FOUR" => "four"), - array ("one" => 1, "two" => 2, "three" => 3, "four" => "FOUR"), - array ("ONE" => 1, "TWO" => 2, "three" => 3, "four" => "FOUR"), - array ("one" => 1, "two" => 2, "THREE" => 3, "FOUR" => "four") + array (), + array (0), + array (1), + array (-1), + array (0, 2, 3, 4, 5), + array (1, 2, 3, 4, 5), + array ("" => 1), + array ("a" => 1), + array ("Z" => 1), + array ("one" => 1), + array ("ONE" => 1), + array ("OnE" => 1), + array ("oNe" => 1), + array ("one" => 1, "two" => 2), + array ("ONE" => 1, "two" => 2), + array ("OnE" => 1, "two" => 2), + array ("oNe" => 1, "two" => 2), + array ("one" => 1, "TWO" => 2), + array ("ONE" => 1, "TWO" => 2), + array ("OnE" => 1, "TWO" => 2), + array ("oNe" => 1, "TWO" => 2), + array ("one" => 1, "TwO" => 2), + array ("ONE" => 1, "TwO" => 2), + array ("OnE" => 1, "TwO" => 2), + array ("oNe" => 1, "TwO" => 2), + array ("one" => 1, "tWo" => 2), + array ("ONE" => 1, "tWo" => 2), + array ("OnE" => 1, "tWo" => 2), + array ("oNe" => 1, "tWo" => 2), + array ("one" => 1, 2), + array ("ONE" => 1, 2), + array ("OnE" => 1, 2), + array ("oNe" => 1, 2), + array ("ONE" => 1, "TWO" => 2, "THREE" => 3, "FOUR" => "four"), + array ("one" => 1, "two" => 2, "three" => 3, "four" => "FOUR"), + array ("ONE" => 1, "TWO" => 2, "three" => 3, "four" => "FOUR"), + array ("one" => 1, "two" => 2, "THREE" => 3, "FOUR" => "four") ); +echo "*** Testing basic operations ***\n"; +$loop_counter = 1; foreach ($arrays as $item) { + echo "** Iteration $loop_counter **\n"; $loop_counter++; var_dump(array_change_key_case($item)); var_dump(array_change_key_case($item, CASE_UPPER)); var_dump(array_change_key_case($item, CASE_LOWER)); echo "\n"; } + +echo "\n*** Testing possible variations ***\n"; +$int_var = -19; +$item = array ("one" => 1, "two" => 2, "THREE" => 3, "FOUR" => "four"); + +/* use 'case' argument other than CASE_LOWER & CASE_UPPER */ +var_dump(array_change_key_case($item, 5)); + +/* when keys are different in terms of only case */ +/* should return one value key pair with key being in lowercase */ +var_dump( array_change_key_case( array("ONE" => 1, "one" => 3, "One" => 4) ) ); + +/* should return one value key pair with key being in uppercase */ +var_dump( array_change_key_case( array("ONE" => 1, "one" => 2, "One" => 3), CASE_UPPER ) ); +var_dump( array_change_key_case( array("ONE" => 1, "one" => 1, "One" => 2), 5 ) ); + +echo "\n*** Testing error conditions ***\n"; +/* generate different failure conditions */ +var_dump( array_change_key_case($int_var) ); // args less than expected +var_dump( array_change_key_case($int_var, CASE_UPPER) ); // invalid first argument +var_dump( array_change_key_case( array("ONE" => 1, "one" => 6, "One" => 5), "CASE_UPPER" ) ); //invalid 2rd arg +var_dump( array_change_key_case() ); // Zero argument +var_dump( array_change_key_case($item, $item["one"], "CASE_UPPER") ); // more than expected numbers + echo "end\n"; ?> ---EXPECT-- +--EXPECTF-- +*** Testing basic operations *** +** Iteration 1 ** array(0) { } array(0) { @@ -58,6 +93,7 @@ array(0) { array(0) { } +** Iteration 2 ** array(1) { [0]=> int(0) @@ -71,6 +107,7 @@ array(1) { int(0) } +** Iteration 3 ** array(1) { [0]=> int(1) @@ -84,6 +121,7 @@ array(1) { int(1) } +** Iteration 4 ** array(1) { [0]=> int(-1) @@ -97,6 +135,7 @@ array(1) { int(-1) } +** Iteration 5 ** array(5) { [0]=> int(0) @@ -134,6 +173,7 @@ array(5) { int(5) } +** Iteration 6 ** array(5) { [0]=> int(1) @@ -171,6 +211,7 @@ array(5) { int(5) } +** Iteration 7 ** array(1) { [""]=> int(1) @@ -184,6 +225,7 @@ array(1) { int(1) } +** Iteration 8 ** array(1) { ["a"]=> int(1) @@ -197,6 +239,7 @@ array(1) { int(1) } +** Iteration 9 ** array(1) { ["z"]=> int(1) @@ -210,6 +253,7 @@ array(1) { int(1) } +** Iteration 10 ** array(1) { ["one"]=> int(1) @@ -223,6 +267,7 @@ array(1) { int(1) } +** Iteration 11 ** array(1) { ["one"]=> int(1) @@ -236,6 +281,7 @@ array(1) { int(1) } +** Iteration 12 ** array(1) { ["one"]=> int(1) @@ -249,6 +295,7 @@ array(1) { int(1) } +** Iteration 13 ** array(1) { ["one"]=> int(1) @@ -262,6 +309,7 @@ array(1) { int(1) } +** Iteration 14 ** array(2) { ["one"]=> int(1) @@ -281,6 +329,7 @@ array(2) { int(2) } +** Iteration 15 ** array(2) { ["one"]=> int(1) @@ -300,6 +349,7 @@ array(2) { int(2) } +** Iteration 16 ** array(2) { ["one"]=> int(1) @@ -319,6 +369,7 @@ array(2) { int(2) } +** Iteration 17 ** array(2) { ["one"]=> int(1) @@ -338,6 +389,7 @@ array(2) { int(2) } +** Iteration 18 ** array(2) { ["one"]=> int(1) @@ -357,6 +409,7 @@ array(2) { int(2) } +** Iteration 19 ** array(2) { ["one"]=> int(1) @@ -376,6 +429,7 @@ array(2) { int(2) } +** Iteration 20 ** array(2) { ["one"]=> int(1) @@ -395,6 +449,7 @@ array(2) { int(2) } +** Iteration 21 ** array(2) { ["one"]=> int(1) @@ -414,6 +469,7 @@ array(2) { int(2) } +** Iteration 22 ** array(2) { ["one"]=> int(1) @@ -433,6 +489,7 @@ array(2) { int(2) } +** Iteration 23 ** array(2) { ["one"]=> int(1) @@ -452,6 +509,7 @@ array(2) { int(2) } +** Iteration 24 ** array(2) { ["one"]=> int(1) @@ -471,6 +529,7 @@ array(2) { int(2) } +** Iteration 25 ** array(2) { ["one"]=> int(1) @@ -490,6 +549,7 @@ array(2) { int(2) } +** Iteration 26 ** array(2) { ["one"]=> int(1) @@ -509,6 +569,7 @@ array(2) { int(2) } +** Iteration 27 ** array(2) { ["one"]=> int(1) @@ -528,6 +589,7 @@ array(2) { int(2) } +** Iteration 28 ** array(2) { ["one"]=> int(1) @@ -547,6 +609,7 @@ array(2) { int(2) } +** Iteration 29 ** array(2) { ["one"]=> int(1) @@ -566,6 +629,7 @@ array(2) { int(2) } +** Iteration 30 ** array(2) { ["one"]=> int(1) @@ -585,6 +649,7 @@ array(2) { int(2) } +** Iteration 31 ** array(2) { ["one"]=> int(1) @@ -604,6 +669,7 @@ array(2) { int(2) } +** Iteration 32 ** array(2) { ["one"]=> int(1) @@ -623,6 +689,7 @@ array(2) { int(2) } +** Iteration 33 ** array(2) { ["one"]=> int(1) @@ -642,6 +709,7 @@ array(2) { int(2) } +** Iteration 34 ** array(4) { ["one"]=> int(1) @@ -673,6 +741,7 @@ array(4) { string(4) "four" } +** Iteration 35 ** array(4) { ["one"]=> int(1) @@ -704,6 +773,7 @@ array(4) { string(4) "FOUR" } +** Iteration 36 ** array(4) { ["one"]=> int(1) @@ -735,6 +805,7 @@ array(4) { string(4) "FOUR" } +** Iteration 37 ** array(4) { ["one"]=> int(1) @@ -766,721 +837,45 @@ array(4) { string(4) "four" } -end ---UEXPECT-- -array(0) { -} -array(0) { -} -array(0) { -} - -array(1) { - [0]=> - int(0) -} -array(1) { - [0]=> - int(0) -} -array(1) { - [0]=> - int(0) -} - -array(1) { - [0]=> - int(1) -} -array(1) { - [0]=> - int(1) -} -array(1) { - [0]=> - int(1) -} - -array(1) { - [0]=> - int(-1) -} -array(1) { - [0]=> - int(-1) -} -array(1) { - [0]=> - int(-1) -} - -array(5) { - [0]=> - int(0) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(0) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(0) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -array(5) { - [0]=> +*** Testing possible variations *** +array(4) { + ["ONE"]=> int(1) - [1]=> + ["TWO"]=> int(2) - [2]=> + ["THREE"]=> int(3) - [3]=> - int(4) - [4]=> - int(5) -} - -array(1) { - [u""]=> - int(1) -} -array(1) { - [u""]=> - int(1) -} -array(1) { - [u""]=> - int(1) -} - -array(1) { - [u"a"]=> - int(1) -} -array(1) { - [u"A"]=> - int(1) -} -array(1) { - [u"a"]=> - int(1) -} - -array(1) { - [u"z"]=> - int(1) -} -array(1) { - [u"Z"]=> - int(1) -} -array(1) { - [u"z"]=> - int(1) -} - -array(1) { - [u"one"]=> - int(1) -} -array(1) { - [u"ONE"]=> - int(1) -} -array(1) { - [u"one"]=> - int(1) -} - -array(1) { - [u"one"]=> - int(1) -} -array(1) { - [u"ONE"]=> - int(1) -} -array(1) { - [u"one"]=> - int(1) -} - -array(1) { - [u"one"]=> - int(1) -} -array(1) { - [u"ONE"]=> - int(1) -} -array(1) { - [u"one"]=> - int(1) + ["FOUR"]=> + string(4) "four" } - array(1) { - [u"one"]=> - int(1) + ["one"]=> + int(4) } array(1) { - [u"ONE"]=> - int(1) + ["ONE"]=> + int(3) } array(1) { - [u"one"]=> - int(1) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> + ["ONE"]=> int(2) } -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} +*** Testing error conditions *** -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} - -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"ONE"]=> - int(1) - [0]=> - int(2) -} -array(2) { - [u"one"]=> - int(1) - [0]=> - int(2) -} - -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "four" -} -array(4) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) - [u"THREE"]=> - int(3) - [u"FOUR"]=> - unicode(4) "four" -} -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "four" -} - -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "FOUR" -} -array(4) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) - [u"THREE"]=> - int(3) - [u"FOUR"]=> - unicode(4) "FOUR" -} -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "FOUR" -} - -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "FOUR" -} -array(4) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) - [u"THREE"]=> - int(3) - [u"FOUR"]=> - unicode(4) "FOUR" -} -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "FOUR" -} - -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "four" -} -array(4) { - [u"ONE"]=> - int(1) - [u"TWO"]=> - int(2) - [u"THREE"]=> - int(3) - [u"FOUR"]=> - unicode(4) "four" -} -array(4) { - [u"one"]=> - int(1) - [u"two"]=> - int(2) - [u"three"]=> - int(3) - [u"four"]=> - unicode(4) "four" -} +Warning: array_change_key_case() expects at least 1 parameter, 0 given in %s on line %d +NULL +Warning: array_change_key_case() expects at most 2 parameters, 3 given in %s on line %d +NULL end diff --git a/ext/standard/tests/array/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt index 8178aa374a..66f8a5ab9c 100644 --- a/ext/standard/tests/array/array_key_exists.phpt +++ b/ext/standard/tests/array/array_key_exists.phpt @@ -1,24 +1,254 @@ --TEST-- -array_key_exists() tests +Test array_key_exists() function --FILE-- "Jack", "Loc" => "Mars", "Id" => "MS123"), + array('Red' => 'Rose', 'I' => 'You'), + array(0 => 'Zero', 1 => 'One', 2 => 'Two', 3 => "Three" ), + array(0.1 => 'Zero', 1.1 => 'One', 2.2 => 'Two', 3.3 => "Three" ) + ); +/* keys to search in $search_arrays. $keys[0] + is the key to be searched in $search_arrays[0] and so on */ +$keys = array( 1, 'a', 2, 4, "Name", "Red", 0, 3 ); -var_dump(array_key_exists(1, array(1,2,3))); -var_dump(array_key_exists("a", array(3,2,1,"a"=>1))); -var_dump(array_key_exists("a", array(3,2,1))); -var_dump(array_key_exists(NULL, array(5,6,7,""=>"value", 3,2,1))); -var_dump(array_key_exists(NULL, array(5,6,7,3,2,1))); -var_dump(array_key_exists(false, array(5,6,7,""=>"value", 3,2,1))); +$key_counter = 0; +foreach ($search_arrays as $search_array) { + $key = $keys[ $key_counter++ ]; + echo "-- Iteration $key_counter --\n"; + var_dump( array_key_exists($key, $search_array) ); +} +echo "\n*** Testing possible variations ***\n"; +// use different keys on each sub array of $search_arrays +$key_variations = array ("", NULL, null, " ", '', "test", 1); +$key_counter = 0; +$key_count = count ( $key_variations ); +echo "\n** Variation loop 1 **\n"; +$out_loop_count = 0; +foreach ($search_arrays as $search_array) { + $key_counter = 0; + $out_loop_count ++; echo "-- Iteration $out_loop_count --\n"; + while ( $key_counter < $key_count ) { + $key = $key_variations[ $key_counter++ ]; + var_dump( array_key_exists($key, $search_array) ); + } +} +// arrays with variation in elements +$search_arrays_v = array ( + array(), + array(NULL), + array(array(), 1, 2), + array(1,2,3, "" => "value", NULL => "value", true => "value" ), + array( array(2,4,5), array ("a","b","d") ) + ); +// search for $key_variations in each sub array of $search_arrays_v +echo "\n** Variation loop 2 **\n"; +$out_loop_count = 0; +foreach ($search_arrays_v as $search_array) { + $key_counter = 0; + $out_loop_count ++; echo "-- Iteration $out_loop_count --\n"; + while ( $key_counter < $key_count ) { + $key = $key_variations[ $key_counter++ ]; + var_dump( array_key_exists($key, $search_array) ); + } +} + +echo "\n*** Testing error conditions ***\n"; +//Zeor args +var_dump( array_key_exists() ); +// first args as array +var_dump( array_key_exists(array(), array()) ); +// second args as string +var_dump( array_key_exists("", "") ); +// second args a integer +var_dump( array_key_exists(1, 1) ); +// second args as NULL +var_dump( array_key_exists(1, NULL) ); +// second args as boolean +var_dump( array_key_exists(1, true) ); +// first args as boolean +var_dump( array_key_exists(false, true) ); +// second args as float +var_dump( array_key_exists(false, 17.5) ); +// args more than expected +var_dump( array_key_exists(1, array(), array()) ); +// first argument as floating point value +var_dump( array_key_exists(17.5, array(1,23) ) ) ; + +echo "\n*** Testing operation on objects ***\n"; +class key_check +{ + private $private_var = "Priviate var"; + protected $protected_var = "Protected var"; + public $public_var = "Public var"; + public $arr = array("var" => "value", "1" => "one", ""=>"value"); + public function print_member() + { + echo $this->$private_var."\n"; + echo $this->$protected_var."\n"; + echo $this->$public_var."\n"; + } +} + +$key_check_obj = new key_check; //new object +/* array_key_exists() on an object, it should work on only public member variables */ +var_dump(array_key_exists("private_var", $key_check_obj)); // not found, private member +var_dump(array_key_exists("protected_var", $key_check_obj)); // not found, private member +var_dump(array_key_exists("public_var", $key_check_obj)); // found, public member +var_dump(array_key_exists("print_member", $key_check_obj)); // not found, its a function +var_dump(array_key_exists("arr", $key_check_obj)); //found, public member +var_dump(array_key_exists("var", $key_check_obj->arr)); //found, key is in member array + +/* error condition, first arguemnt as object */ +var_dump( array_key_exists($key_check_obj, $key_check_obj) ); echo "Done\n"; ?> --EXPECTF-- +*** Testing basic functionalities *** +-- Iteration 1 -- +bool(true) +-- Iteration 2 -- +bool(false) +-- Iteration 3 -- +bool(true) +-- Iteration 4 -- +bool(false) +-- Iteration 5 -- +bool(true) +-- Iteration 6 -- +bool(true) +-- Iteration 7 -- +bool(true) +-- Iteration 8 -- +bool(true) + +*** Testing possible variations *** + +** Variation loop 1 ** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 4 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) + +** Variation loop 2 ** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(true) + +*** Testing error conditions *** + Warning: array_key_exists() expects exactly 2 parameters, 0 given in %s on line %d NULL @@ -27,13 +257,35 @@ bool(false) Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d bool(false) + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d bool(false) + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +Warning: array_key_exists() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +*** Testing operation on objects *** bool(false) -bool(true) -bool(true) bool(false) bool(true) bool(false) +bool(true) +bool(true) Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d bool(false) diff --git a/ext/standard/tests/array/array_keys.phpt b/ext/standard/tests/array/array_keys.phpt new file mode 100644 index 0000000000..8af0590187 --- /dev/null +++ b/ext/standard/tests/array/array_keys.phpt @@ -0,0 +1,461 @@ +--TEST-- +Test array_keys() function +--FILE-- + 1, "b" => 2, 2.0 => 2.0, -23.45 => "asdasd", + array(1,2,3)); +var_dump(array_keys($basic_arr)); + +echo "\n*** Testing array_keys() on various arrays ***"; +$arrays = array( + array(), + array(0), + array( array() ), + array("Hello" => "World"), + array("" => ""), + array(1,2,3, "d" => array(4,6, "d")), + array("a" => 1, "b" => 2, "c" =>3, "d" => array()), + array(0 => 0, 1 => 1, 2 => 2, 3 => 3), + array(0.001=>3.000, 1.002=>2, 1.999=>3, "a"=>3, 3=>5, "5"=>3.000), + array(TRUE => TRUE, FALSE => FALSE, NULL => NULL, "\x000", "\000"), + array("a" => "abcd", "a" => "", "ab" => -6, "cd" => -0.5 ), + array(0 => array(), 1=> array(0), 2 => array(1), ""=> array(),""=>"" ) +); + +$i = 0; +/* loop through to test array_keys() with different arrays */ +foreach ($arrays as $array) { + echo "\n-- Iteration $i --\n"; + var_dump(array_keys($array)); + $i++; +} + +echo "\n*** Testing array_keys() on all the types other than arrays ***"; +$types_arr = array( + TRUE => TRUE, + FALSE => FALSE, + 1 => 1, + 0 => 0, + -1 => -1, + "1" => "1", + "0" => "0", + "-1" => "-1", + NULL, + array(), + "php" => "php", + "" => "" +); +$values = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "php", ""); +foreach ($values as $value){ + echo "\n-- Loose type checking --\n"; + var_dump(array_keys($types_arr, $value)); + echo "\n-- strict type checking --\n"; + var_dump(array_keys($types_arr, $value, TRUE)); +} + +echo "\n*** Testing array_keys() with resource type ***\n"; +$resource1 = fopen( __FILE__, "r"); +$resource2 = opendir( "." ); + +/* creating an array with resource types as elements */ +$arr_resource = array($resource1, $resource2); + +var_dump(array_keys($arr_resource, $resource1)); // loose type checking +var_dump(array_keys($arr_resource, $resource1, TRUE)); // strict type checking +var_dump(array_keys($arr_resource, $resource2)); // loose type checking +var_dump(array_keys($arr_resource, $resource2, TRUE)); // strict type checking + +echo "\n*** Testing array_keys() on range of values ***\n"; +$arr_range = array( + 2147483647 => 1, + 2147483648 => 2, + -2147483647 => 3, + -2147483648 => 4, + -2147483649 => 5, + -0 => 6, + 0 => 7 +); +var_dump(array_keys($arr_range)); + +echo "\n*** Testing array_keys() on an array created on the fly ***\n"; +var_dump(array_keys(array("a" => 1, "b" => 2, "c" => 3))); +var_dump(array_keys(array())); // null array + +echo "\n*** Testing error conditions ***"; +var_dump(array_keys(100)); +var_dump(array_keys("string")); +var_dump(array_keys(new stdclass)); // object +var_dump(array_keys()); // Zero arguments +var_dump(array_keys(array(), "", TRUE, 100)); // args > expected +var_dump(array_keys(array(1,2,3, array() => array()))); // (W)illegal offset + +/* Closing the resource handles */ +fclose( $resource1 ); +closedir( $resource2 ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_keys() on basic array operation *** +array(5) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + int(2) + [3]=> + int(-23) + [4]=> + int(3) +} + +*** Testing array_keys() on various arrays *** +-- Iteration 0 -- +array(0) { +} + +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} + +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} + +-- Iteration 3 -- +array(1) { + [0]=> + string(5) "Hello" +} + +-- Iteration 4 -- +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 5 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(1) "d" +} + +-- Iteration 6 -- +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" +} + +-- Iteration 7 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + +-- Iteration 8 -- +array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "a" + [3]=> + int(3) + [4]=> + int(5) +} + +-- Iteration 9 -- +array(5) { + [0]=> + int(1) + [1]=> + int(0) + [2]=> + string(0) "" + [3]=> + int(2) + [4]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + [0]=> + string(1) "a" + [1]=> + string(2) "ab" + [2]=> + string(2) "cd" +} + +-- Iteration 11 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(0) "" +} + +*** Testing array_keys() on all the types other than arrays *** +-- Loose type checking -- +array(3) { + [0]=> + int(1) + [1]=> + int(-1) + [2]=> + string(3) "php" +} + +-- strict type checking -- +array(0) { +} + +-- Loose type checking -- +array(4) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(0) "" +} + +-- strict type checking -- +array(0) { +} + +-- Loose type checking -- +array(1) { + [0]=> + int(1) +} + +-- strict type checking -- +array(0) { +} + +-- Loose type checking -- +array(4) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + string(3) "php" + [3]=> + string(0) "" +} + +-- strict type checking -- +array(0) { +} + +-- Loose type checking -- +array(1) { + [0]=> + int(-1) +} + +-- strict type checking -- +array(0) { +} + +-- Loose type checking -- +array(1) { + [0]=> + int(1) +} + +-- strict type checking -- +array(1) { + [0]=> + int(1) +} + +-- Loose type checking -- +array(1) { + [0]=> + int(0) +} + +-- strict type checking -- +array(1) { + [0]=> + int(0) +} + +-- Loose type checking -- +array(1) { + [0]=> + int(-1) +} + +-- strict type checking -- +array(1) { + [0]=> + int(-1) +} + +-- Loose type checking -- +array(3) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + string(0) "" +} + +-- strict type checking -- +array(1) { + [0]=> + int(2) +} + +-- Loose type checking -- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} + +-- strict type checking -- +array(1) { + [0]=> + int(3) +} + +-- Loose type checking -- +array(1) { + [0]=> + string(3) "php" +} + +-- strict type checking -- +array(1) { + [0]=> + string(3) "php" +} + +-- Loose type checking -- +array(2) { + [0]=> + int(2) + [1]=> + string(0) "" +} + +-- strict type checking -- +array(1) { + [0]=> + string(0) "" +} + +*** Testing array_keys() with resource type *** +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} + +*** Testing array_keys() on range of values *** +array(4) { + [0]=> + int(2147483647) + [1]=> + int(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) +} + +*** Testing array_keys() on an array created on the fly *** +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(0) { +} + +*** Testing error conditions *** +Warning: array_keys() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_keys() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_keys() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_keys() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_keys() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: Illegal offset type in %s on line %d +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_map.phpt b/ext/standard/tests/array/array_map.phpt new file mode 100644 index 0000000000..740e05265a --- /dev/null +++ b/ext/standard/tests/array/array_map.phpt @@ -0,0 +1,418 @@ +--TEST-- +Test array_map() function +--FILE-- +"01", "Feb"=>"02", "March"=>"03"), + array("31"=>"Jan", "28"=>"Feb", "031"=>"March") + ) + ); + +/* using key as "string" where no.of arguments passed to array_map() is 2 */ +var_dump( array_map( create_function('$n', 'return $n*$n;'), + array("key1"=>1, "key2"=>2, "key3"=>3) + ) + ); + +echo "\n*** Testing possible variations ***\n"; +/* anonymous callback function */ +var_dump( array_map( create_function('$a,$b', 'return $a+$b;'), + array(1,2,3), + array(5,6,7,8,9) + ) + ); + +/* anonymous callback function with reference */ +var_dump( array_map( create_function('&$a, $b', 'return array($a,$b);'), + array("Hello","Good"), + array("World","Day") + ) + ); + +/* callback function with reference */ +$a = array(1,2,3); +function square(&$var) { + return( $var * $var ); +} +print_r( array_map('square', $a) ); + +/* array_map in recursion */ +function square_recur($var) { + if (is_array($var)) + return array_map('square_recur', $var); + return $var * $var; +} +$rec_array = array(1, 2, array(3, 4, array(5, 2), array() ) ); +var_dump( array_map('square_recur', $rec_array) ); + +/* callback function as string variable containing the function name */ +$string_var = "square"; +var_dump( array_map("square", $a) ); +var_dump( array_map($string_var, $a) ); + +echo "\n*** Testing error conditions ***\n"; +/* arguments of non array type */ +$int_var=10; +$float_var = 10.5; +var_dump( array_map('square', $int_var) ); +var_dump( array_map('square', $float_var) ); +var_dump( array_map('square', $string_var) ); + +/* Zero argument */ +var_dump( array_map() ); + +/* use array(), echo(), empty(), eval(), exit(), isset(), list(), print() + and unset() as callback, failure expected */ +var_dump( array_map( 'echo', array(1) ) ); +var_dump( array_map( 'array', array(1) ) ); +var_dump( array_map( 'empty', array(1) ) ); +var_dump( array_map( 'eval', array(1) ) ); +var_dump( array_map( 'exit', array(1) ) ); +var_dump( array_map( 'isset', array(1) ) ); +var_dump( array_map( 'list', array(1) ) ); +var_dump( array_map( 'print', array(1) ) ); + + +echo "\n*** Testing operation on objects ***\n"; +/* array_map with class object */ +class check_array_map { + public static function helloWorld() { + return "Static_Function_helloWorld(): Hello World"; + } + public function Message($v) { + return $v; + } + + public static function Square( $n ) { + return $n * $n; + } +} +/* call static member function */ +var_dump( array_map( array('check_array_map', 'Square'), array(1,2,3)) ); + +/* call non static member function - warning should be issues*/ +var_dump( array_map( array('check_array_map', 'Message'), array(1)) ); + +/* call function using object */ +$obj = new check_array_map(); +var_dump( array_map( array($obj, 'helloWorld' ) ) ); // not enough args warning +var_dump( array_map( array($obj, 'helloWorld'), array(1) ) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing basic operations *** +array(0) { +} +array(0) { +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(2) + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(3) + } +} +array(4) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(2) + } + [2]=> + array(2) { + [0]=> + NULL + [1]=> + int(3) + } + [3]=> + array(2) { + [0]=> + NULL + [1]=> + int(4) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "Jan" + [1]=> + string(2) "31" + } + [1]=> + array(2) { + [0]=> + string(3) "Feb" + [1]=> + string(2) "28" + } + [2]=> + array(2) { + [0]=> + string(5) "March" + [1]=> + string(2) "31" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(4) "Text" + [1]=> + int(4) + } + [1]=> + array(2) { + [0]=> + string(5) "Words" + [1]=> + int(5) + } + [2]=> + array(2) { + [0]=> + string(6) "Lineup" + [1]=> + int(6) + } +} +array(4) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + string(2) "ab" + [1]=> + NULL + } + [2]=> + array(2) { + [0]=> + string(3) "abc" + [1]=> + NULL + } + [3]=> + array(2) { + [0]=> + string(4) "abcd" + [1]=> + NULL + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(2) "01" + [1]=> + string(3) "Jan" + } + [1]=> + array(2) { + [0]=> + string(2) "02" + [1]=> + string(3) "Feb" + } + [2]=> + array(2) { + [0]=> + string(2) "03" + [1]=> + string(5) "March" + } +} +array(3) { + ["key1"]=> + int(1) + ["key2"]=> + int(4) + ["key3"]=> + int(9) +} + +*** Testing possible variations *** +array(5) { + [0]=> + int(6) + [1]=> + int(8) + [2]=> + int(10) + [3]=> + int(8) + [4]=> + int(9) +} +array(2) { + [0]=> + array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "World" + } + [1]=> + array(2) { + [0]=> + string(4) "Good" + [1]=> + string(3) "Day" + } +} +Array +( + [0] => 1 + [1] => 4 + [2] => 9 +) +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + array(4) { + [0]=> + int(9) + [1]=> + int(16) + [2]=> + array(2) { + [0]=> + int(25) + [1]=> + int(4) + } + [3]=> + array(0) { + } + } +} +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} + +*** Testing error conditions *** + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL + +Warning: array_map() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d +NULL + +*** Testing operation on objects *** +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d +NULL + +Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d +NULL +array(1) { + [0]=> + string(41) "Static_Function_helloWorld(): Hello World" +} +Done diff --git a/ext/standard/tests/array/array_pop.phpt b/ext/standard/tests/array/array_pop.phpt new file mode 100644 index 0000000000..b08339db71 --- /dev/null +++ b/ext/standard/tests/array/array_pop.phpt @@ -0,0 +1,286 @@ +--TEST-- +Test array_pop() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); + +/* Testing Error Conditions */ +echo "\n*** Testing Error Conditions ***\n"; + +/* Zero argument */ +var_dump( array_pop() ); + +/* Scalar argument */ +var_dump( array_pop($number) ); + +/* String argument */ +var_dump( array_pop($str) ); + +/* Invalid Number of arguments */ +var_dump( array_pop($mixed_array[1],$mixed_array[2]) ); + +/* Empty Array as argument */ +var_dump( array_pop($empty_array) ); + +/* Loop to test normal functionality with different arrays inputs */ +echo "\n*** Normal testing with various array inputs ***\n"; + +$counter = 1; +foreach( $mixed_array as $sub_array ) +{ + echo "\n-- Input Array for Iteration $counter is --\n"; + print_r( $sub_array ); + echo "\nOutput after Pop is :\n"; + var_dump( array_pop($sub_array) ); + $counter++; +} + +echo"\n*** Checking for internal array pointer being reset when pop is called ***\n"; + +echo "\nCurrent Element is : "; +var_dump( current($mixed_array[1]) ); + +echo "\nNext Element is : "; +var_dump( next($mixed_array[1]) ); + +echo "\nNext Element is : "; +var_dump( next($mixed_array[1]) ); + +echo "\nPOPed Element is : "; +var_dump( array_pop($mixed_array[1]) ); + +echo "\nCurrent Element after POP operation is: "; +var_dump( current($mixed_array[1]) ); + +echo"\nDone"; +?> +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_pop() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_pop() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pop() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pop() expects exactly 1 parameter, 2 given in %s on line %d +NULL +NULL + +*** Normal testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +Output after Pop is : +NULL + +-- Input Array for Iteration 2 is -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 +) + +Output after Pop is : +int(9) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +Output after Pop is : +string(4) "Five" + +-- Input Array for Iteration 4 is -- +Array +( + [0] => 6 + [1] => six + [2] => 7 + [3] => seven + [4] => 8 + [5] => eight + [6] => 9 + [7] => nine +) + +Output after Pop is : +string(4) "nine" + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +Output after Pop is : +string(3) "eee" + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +Output after Pop is : +string(4) "five" + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +Output after Pop is : +string(4) "five" + +-- Input Array for Iteration 8 is -- +Array +( + [f] => fff + [1] => one + [4] => 6 + [] => 3 + [2] => float + [F] => FFF + [blank] => + [3] => 3.7 + [5] => Five + [6] => 8.6 + [4name] => jonny + [a] => +) + +Output after Pop is : +NULL + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +Output after Pop is : +string(2) "45" + +-- Input Array for Iteration 10 is -- +Array +( + [0] => Array + ( + [0] => oNe + [1] => tWo + [2] => 4 + ) + + [1] => Array + ( + [0] => 10 + [1] => 20 + [2] => 30 + [3] => 40 + [4] => 50 + ) + + [2] => Array + ( + ) + +) + +Output after Pop is : +array(0) { +} + +-- Input Array for Iteration 11 is -- +Array +( + [one] => 2 + [three] => 3 + [0] => 3 + [1] => 4 + [3] => 33 + [4] => 44 + [5] => 57 + [6] => 6 + [5.4] => 554 + [5.7] => 557 +) + +Output after Pop is : +int(557) + +*** Checking for internal array pointer being reset when pop is called *** + +Current Element is : int(1) + +Next Element is : int(2) + +Next Element is : int(3) + +POPed Element is : int(9) + +Current Element after POP operation is: int(1) + +Done diff --git a/ext/standard/tests/array/array_search.phpt b/ext/standard/tests/array/array_search.phpt index e95fda1286..33f77a899a 100644 --- a/ext/standard/tests/array/array_search.phpt +++ b/ext/standard/tests/array/array_search.phpt @@ -1,7 +1,13 @@ --TEST-- -search_array and in_array (including bug 13567) +Test array_search() and in_array() functions (including bug 13567) --FILE-- 'd'); $arr4 = array("a\0b"=>'e','key'=>'d', 'f'); $tests = << "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL, "b", "ab", "abcd"), + array(4, array(1, 2 => 3), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, -2.989888, "-0.005" => "neg0.005", 2.0 => "float2", "-.9" => -.9), + array(TRUE, FALSE), + array("", array()), + array("abcd\x00abcd\x00abcd"), + array("abcd\tabcd\nabcd\rabcd\0abcdefghij") +); + +$array_compare = array ( + 4, + "4", + 4.00, + "b", + "5", + -2, + -2.0, + -2.98989, + "-.9", + "True", + "", + array(), + NULL, + "ab", + "abcd", + 0.0, + -0, + "abcd\x00abcd\x00abcd" +); +/* loop to check if elements in $array_compare exist in $arrays + using in_array() */ +$counter = 1; +foreach($arrays as $array) { + foreach($array_compare as $compare) { + echo "-- Iteration $counter --\n"; + //strict option OFF + var_dump(in_array($compare,$array)); + //strict option ON + var_dump(in_array($compare,$array,TRUE)); + //strict option OFF + var_dump(in_array($compare,$array,FALSE)); + $counter++; + } +} + +/* checking loose and strict TYPE comparisons in in_array() */ +echo "\n*** Testing loose and strict TYPE comparison of in_array() ***\n"; +$misc_array = array ( + 'a', + 'key' =>'d', + 3, + ".001" =>-67, + "-.051" =>"k", + 0.091 =>"-.08", + "e" =>"5", + "y" =>NULL, + NULL =>"", + 0, + TRUE, + FALSE, + -27.39999999999, + " ", + "abcd\x00abcd\x00\abcd\x00abcdefghij", + "abcd\nabcd\tabcd\rabcd\0abcd" +); +$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); +/* loop to do loose and strict type check of elements in + $array_type on elements in $misc_array using in_array(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( in_array($type,$misc_array ) ); + //strict type checking + var_dump( in_array($type,$misc_array,true) ); + //loose type checking + var_dump( in_array($type,$misc_array,false) ); + $counter++; +} + +/* checking for sub-arrays with in_array() */ +echo "\n*** Testing sub-arrays with in_array() ***\n"; +$sub_array = array ( + "one", + array(1, 2 => "two", "three" => 3), + 4 => "four", + "five" => 5, + array('', 'i') +); +var_dump( in_array("four", $sub_array) ); +//checking for element in a sub-array +var_dump( in_array(3, $sub_array[1]) ); +var_dump( in_array(array('','i'), $sub_array) ); + +/* checking for objects in in_array() */ +echo "\n*** Testing objects with in_array() ***\n"; +class in_array_check { + public $array_var = array(1=>"one", "two"=>2, 3=>3); + public function foo() { + echo "Public function\n"; + } +} + +$in_array_obj = new in_array_check(); //creating new object +//error: as wrong datatype for second argument +var_dump( in_array("array_var", $in_array_obj) ); +//error: as wrong datatype for second argument +var_dump( in_array("foo", $in_array_obj) ); +//element found as "one" exists in array $array_var +var_dump( in_array("one", $in_array_obj->array_var) ); + +/* checking for Resources */ +echo "\n*** Testing resource type with in_array() ***\n"; +//file type resource +$file_handle = fopen(__FILE__, "r"); + +//directory type resource +$dir_handle = opendir( dirname(__FILE__) ); + +//store resources in array for comparision. +$resources = array($file_handle, $dir_handle); + +// search for resouce type in the resource array +var_dump( in_array($file_handle, $resources, true) ); +//checking for (int) type resource +var_dump( in_array((int)$dir_handle, $resources, true) ); + +/* Miscellenous input check */ +echo "\n*** Testing miscelleneos inputs with in_array() ***\n"; +//matching "Good" in array(0,"hello"), result:true in loose type check +var_dump( in_array("Good", array(0,"hello")) ); +//false in strict mode +var_dump( in_array("Good", array(0,"hello"), TRUE) ); + +//matching integer 0 in array("this"), result:true in loose type check +var_dump( in_array(0, array("this")) ); +// false in strict mode +var_dump( in_array(0, array("this")),TRUE ); + +//matching string "this" in array(0), result:true in loose type check +var_dump( in_array("this", array(0)) ); +// false in stric mode +var_dump( in_array("this", array(0), TRUE) ); + +//checking for type FALSE in multidimensional array with loose checking, result:false in loose type check +var_dump( in_array(FALSE, + array("a"=> TRUE, "b"=> TRUE, + array("c"=> TRUE, "d"=>TRUE) + ) + ) + ); + +//matching string having integer in beginning, result:true in loose type check +var_dump( in_array('123abc', array(123)) ); +var_dump( in_array('123abc', array(123), TRUE) ); // false in strict mode + +echo "\n*** Testing error conditions of in_array() ***\n"; +/* zero argument */ +var_dump( in_array() ); + +/* unexpected no.of arguments in in_array() */ +$var = array("mon", "tues", "wed", "thurs"); +var_dump( in_array(1, $var, 0, "test") ); +var_dump( in_array("test") ); + +/* unexpected second argument in in_array() */ +$var="test"; +var_dump( in_array("test",$var) ); +var_dump( in_array(1,123) ); + +/* closing resource handles */ +fclose($file_handle); +closedir($dir_handle); + +echo "Done\n"; +?> +--EXPECTF-- OK +*** Testing STRICT option of in_array() on arrays *** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +-- Iteration 9 -- +bool(false) +bool(false) +bool(false) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +bool(true) +bool(false) +bool(true) +-- Iteration 14 -- +bool(true) +bool(false) +bool(true) +-- Iteration 15 -- +bool(true) +bool(false) +bool(true) +-- Iteration 16 -- +bool(true) +bool(false) +bool(true) +-- Iteration 17 -- +bool(true) +bool(true) +bool(true) +-- Iteration 18 -- +bool(true) +bool(false) +bool(true) +-- Iteration 19 -- +bool(true) +bool(true) +bool(true) +-- Iteration 20 -- +bool(true) +bool(false) +bool(true) +-- Iteration 21 -- +bool(true) +bool(false) +bool(true) +-- Iteration 22 -- +bool(true) +bool(true) +bool(true) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +bool(true) +bool(false) +bool(true) +-- Iteration 30 -- +bool(true) +bool(false) +bool(true) +-- Iteration 31 -- +bool(true) +bool(true) +bool(true) +-- Iteration 32 -- +bool(true) +bool(true) +bool(true) +-- Iteration 33 -- +bool(true) +bool(true) +bool(true) +-- Iteration 34 -- +bool(true) +bool(false) +bool(true) +-- Iteration 35 -- +bool(true) +bool(false) +bool(true) +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +bool(true) +bool(true) +bool(true) +-- Iteration 38 -- +bool(true) +bool(false) +bool(true) +-- Iteration 39 -- +bool(true) +bool(false) +bool(true) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +bool(true) +bool(false) +bool(true) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +bool(true) +bool(true) +bool(true) +-- Iteration 61 -- +bool(true) +bool(false) +bool(true) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +bool(true) +bool(false) +bool(true) +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +bool(true) +bool(false) +bool(true) +-- Iteration 71 -- +bool(true) +bool(false) +bool(true) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +bool(true) +bool(false) +bool(true) +-- Iteration 74 -- +bool(true) +bool(false) +bool(true) +-- Iteration 75 -- +bool(true) +bool(false) +bool(true) +-- Iteration 76 -- +bool(true) +bool(false) +bool(true) +-- Iteration 77 -- +bool(true) +bool(false) +bool(true) +-- Iteration 78 -- +bool(true) +bool(false) +bool(true) +-- Iteration 79 -- +bool(true) +bool(false) +bool(true) +-- Iteration 80 -- +bool(true) +bool(false) +bool(true) +-- Iteration 81 -- +bool(true) +bool(false) +bool(true) +-- Iteration 82 -- +bool(true) +bool(false) +bool(true) +-- Iteration 83 -- +bool(true) +bool(false) +bool(true) +-- Iteration 84 -- +bool(true) +bool(false) +bool(true) +-- Iteration 85 -- +bool(true) +bool(false) +bool(true) +-- Iteration 86 -- +bool(true) +bool(false) +bool(true) +-- Iteration 87 -- +bool(true) +bool(false) +bool(true) +-- Iteration 88 -- +bool(true) +bool(false) +bool(true) +-- Iteration 89 -- +bool(true) +bool(false) +bool(true) +-- Iteration 90 -- +bool(true) +bool(false) +bool(true) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +bool(true) +bool(true) +bool(true) +-- Iteration 102 -- +bool(true) +bool(true) +bool(true) +-- Iteration 103 -- +bool(true) +bool(false) +bool(true) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +bool(true) +bool(false) +bool(true) +-- Iteration 107 -- +bool(true) +bool(false) +bool(true) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +bool(true) +bool(false) +bool(true) +-- Iteration 125 -- +bool(true) +bool(false) +bool(true) +-- Iteration 126 -- +bool(true) +bool(true) +bool(true) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +bool(true) +bool(false) +bool(true) +-- Iteration 143 -- +bool(true) +bool(false) +bool(true) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) + +*** Testing loose and strict TYPE comparison of in_array() *** +-- Iteration 1 -- +bool(true) +bool(true) +bool(true) +-- Iteration 2 -- +bool(true) +bool(true) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +-- Iteration 5 -- +bool(true) +bool(false) +bool(true) +-- Iteration 6 -- +bool(true) +bool(false) +bool(true) +-- Iteration 7 -- +bool(true) +bool(false) +bool(true) +-- Iteration 8 -- +bool(true) +bool(false) +bool(true) +-- Iteration 9 -- +bool(true) +bool(true) +bool(true) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(true) +bool(true) +bool(true) + +*** Testing sub-arrays with in_array() *** +bool(true) +bool(true) +bool(true) + +*** Testing objects with in_array() *** + +Warning: in_array() expects parameter 2 to be array, object given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, object given in %s on line %d +NULL +bool(true) + +*** Testing resource type with in_array() *** +bool(true) +bool(false) + +*** Testing miscelleneos inputs with in_array() *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) + +*** Testing error conditions of in_array() *** + +Warning: in_array() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: in_array() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: in_array() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, string given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, integer given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_values.phpt b/ext/standard/tests/array/array_values.phpt index 485b9b7a37..2772120e56 100644 Binary files a/ext/standard/tests/array/array_values.phpt and b/ext/standard/tests/array/array_values.phpt differ diff --git a/ext/standard/tests/array/each.phpt b/ext/standard/tests/array/each.phpt new file mode 100644 index 0000000000..1953a04397 Binary files /dev/null and b/ext/standard/tests/array/each.phpt differ diff --git a/ext/standard/tests/array/end.phpt b/ext/standard/tests/array/end.phpt new file mode 100644 index 0000000000..df0465c9d4 --- /dev/null +++ b/ext/standard/tests/array/end.phpt @@ -0,0 +1,1790 @@ +--TEST-- +Test print_r() function +--FILE-- + + 'One'), + array("test" => "is_array"), + array(0), + array(-1), + array(10.5, 5.6), + array("string", "test"), + array('string', 'test'), + $array1 = array(1,2,3,4, &$array1) // recursive array +); +/* calling check_printr() to display contents of $arrays */ +check_printr($arrays); + +echo "\n*** Testing print_r() on object variables ***\n"; +class object_class +{ + var $value; + public $public_var1 = 10; + private $private_var1 = 20; + private $private_var2; + protected $protected_var1 = "string_1"; + protected $protected_var2; + + function object_class ( ) { + $this->value = 50; + $this->public_var2 = 11; + $this->private_var2 = 21; + $this->protected_var2 = "string_2"; + } + + public function foo1() { + echo "foo1() is called\n"; + } + protected function foo2() { + echo "foo2() is called\n"; + } + private function foo3() { + echo "foo3() is called\n"; + } +} +/* class with no member */ +class no_member_class { + // no members +} + +/* class with member as object of other class */ +class contains_object_class +{ + var $p = 30; + var $class_object1; + public $class_object2; + private $class_object3; + protected $class_object4; + var $no_member_class_object; + + public function func() { + echo "func() is called \n"; + } + + function contains_object_class () { + $this->class_object1 = new object_class(); + $this->class_object2 = new object_class(); + $this->class_object3 = $this->class_object1; + $this->class_object4 = $this->class_object2; + $this->no_member_class_object = new no_member_class(); + $this->class_object5 = $this; //recursive reference + } +} + +/* objects of different classes */ +$obj = new contains_object_class; +$temp_class_obj = new object_class(); + +/* object which is unset */ +$unset_obj = new object_class(); +unset($unset_obj); + +$objects = array ( + new object_class, + new no_member_class, + new contains_object_class, + $obj, + $obj->class_object1, + $obj->class_object2, + $obj->no_member_class_object, + $temp_class_obj, + @$unset_obj +); +/* calling check_printr() to display contents of the objects using print_r() */ +check_printr($objects); + +echo "\n** Testing print_r() on objects having circular reference **\n"; +$recursion_obj1 = new object_class(); +$recursion_obj2 = new object_class(); +$recursion_obj1->obj = &$recursion_obj2; //circular reference +$recursion_obj2->obj = &$recursion_obj1; //circular reference +print_r($recursion_obj2); + +echo "\n*** Testing print_r() on resources ***\n"; +/* file type resource */ +$file_handle = fopen(__FILE__, "r"); + +/* directory type resource */ +$dir_handle = opendir( dirname(__FILE__) ); + +$resources = array ( + $file_handle, + $dir_handle +); +/* calling check_printr() to display the resource content type + using print_r() */ +check_printr($resources); + +echo "\n*** Testing print_r() on different combinations of scalar + and non-scalar variables ***\n"; +/* a variable which is unset */ +$unset_var = 10.5; +unset($unset_var); + +/* unset file type resource */ +unset($file_handle); + +$variations = array ( + array( 123, -1.2345, "a" ), + array( "d", array(1, 3, 5), true, null), + array( new no_member_class, array(), false, 0 ), + array( -0.00, "Where am I?", array(7,8,9), TRUE, 'A', 987654321 ), + array( @$unset_var, 2.E+10, 100-20.9, 000004.599998 ), //unusual data + array( "array(1,2,3,4)1.0000002TRUE", @$file_handle, 111333.00+45e5, '/00\7') +); +/* calling check_printr() to display combinations of scalar and + non-scalar variables using print_r() */ +check_printr($variations); + +echo "\n*** Testing print_r() on miscelleneous input arguments ***\n"; +$misc_values = array ( + @$unset_var, + NULL, // NULL argument + @$undef_variable, //undefined variable + null +); +/* calling check_printr() to display miscelleneous data using print_r() */ +check_printr($misc_values); + +/* checking print_r() on functions */ +echo "\n*** Testing print_r() on anonymous functions ***\n"; +$newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);'); +echo "New anonymous function: $newfunc\n"; +print_r( $newfunc(2, 3) ); +/* creating anonymous function dynamically */ +print_r( create_function('$a', 'return "$a * $a = " . ($a * $b);') ); + +echo "\n\n*** Testing error conditions ***\n"; +//passing zero argument +var_dump( print_r() ); + +//passing more than required no. of arguments +var_dump( print_r(123, true, "abc") ); + +// check when second arg is given other than boolean TRUE +var_dump( print_r ($value, "string") ); + +/* closing resource handle used */ +closedir($dir_handle); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing print_r() on integer variables *** + +-- Iteration 1 -- +0 +0 +0 +-- Iteration 2 -- +83 +83 +83 +-- Iteration 3 -- +123000000 +123000000 +123000000 +-- Iteration 4 -- +-83 +-83 +-83 +-- Iteration 5 -- +-12300000 +-12300000 +-12300000 +-- Iteration 6 -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 + [9] => 10 +) + +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 + [9] => 10 +) + +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => 5 + [5] => 6 + [6] => 7 + [7] => 8 + [8] => 9 + [9] => 10 +) + +-- Iteration 7 -- +Array +( + [0] => -1 + [1] => -2 + [2] => -3 + [3] => -4 + [4] => -5 + [5] => -6 + [6] => -7 + [7] => -8 + [8] => -9 + [9] => -10 +) + +Array +( + [0] => -1 + [1] => -2 + [2] => -3 + [3] => -4 + [4] => -5 + [5] => -6 + [6] => -7 + [7] => -8 + [8] => -9 + [9] => -10 +) + +Array +( + [0] => -1 + [1] => -2 + [2] => -3 + [3] => -4 + [4] => -5 + [5] => -6 + [6] => -7 + [7] => -8 + [8] => -9 + [9] => -10 +) + +-- Iteration 8 -- +2147483647 +2147483647 +2147483647 +-- Iteration 9 -- +2147483648 +2147483648 +2147483648 +-- Iteration 10 -- +-2147483648 +-2147483648 +-2147483648 +-- Iteration 11 -- +-2147483647 +-2147483647 +-2147483647 +-- Iteration 12 -- +2147483647 +2147483647 +2147483647 +-- Iteration 13 -- +-2147483648 +-2147483648 +-2147483648 +-- Iteration 14 -- +2147483647 +2147483647 +2147483647 +-- Iteration 15 -- +-2147483648 +-2147483648 +-2147483648 +*** Testing print_r() on float variables *** + +-- Iteration 1 -- +0 +0 +0 +-- Iteration 2 -- +0 +0 +0 +-- Iteration 3 -- +1.234 +1.234 +1.234 +-- Iteration 4 -- +-1.234 +-1.234 +-1.234 +-- Iteration 5 -- +-2 +-2 +-2 +-- Iteration 6 -- +2 +2 +2 +-- Iteration 7 -- +-0.5 +-0.5 +-0.5 +-- Iteration 8 -- +0.567 +0.567 +0.567 +-- Iteration 9 -- +-0.00067 +-0.00067 +-0.00067 +-- Iteration 10 -- +-670 +-670 +-670 +-- Iteration 11 -- +670 +670 +670 +-- Iteration 12 -- +670 +670 +670 +-- Iteration 13 -- +-0.00410003 +-0.00410003 +-0.00410003 +-- Iteration 14 -- +-4100.03 +-4100.03 +-4100.03 +-- Iteration 15 -- +0.004100003 +0.004100003 +0.004100003 +-- Iteration 16 -- +4100.003 +4100.003 +4100.003 +-- Iteration 17 -- +100000 +100000 +100000 +-- Iteration 18 -- +-100000 +-100000 +-100000 +-- Iteration 19 -- +1.0E-5 +1.0E-5 +1.0E-5 +-- Iteration 20 -- +-1.0E-5 +-1.0E-5 +-1.0E-5 +-- Iteration 21 -- +100000 +100000 +100000 +-- Iteration 22 -- +-100000 +-100000 +-100000 +-- Iteration 23 -- +100000 +100000 +100000 +-- Iteration 24 -- +-100000 +-100000 +-100000 +-- Iteration 25 -- +100000 +100000 +100000 +-- Iteration 26 -- +-100000 +-100000 +-100000 +-- Iteration 27 -- +1.0E-5 +1.0E-5 +1.0E-5 +-- Iteration 28 -- +-1.0E-5 +-1.0E-5 +-1.0E-5 +-- Iteration 29 -- +-2147483649 +-2147483649 +-2147483649 +-- Iteration 30 -- +2147483649 +2147483649 +2147483649 +-- Iteration 31 -- +2147483649 +2147483649 +2147483649 +-- Iteration 32 -- +-2147483649 +-2147483649 +-2147483649 +*** Testing print_r() on string variables *** + +-- Iteration 1 -- + + + +-- Iteration 2 -- + + + +-- Iteration 3 -- + + + +-- Iteration 4 -- + + + +-- Iteration 5 -- +0 +0 +0 +-- Iteration 6 -- + + + +-- Iteration 7 -- +\0 +\0 +\0 +-- Iteration 8 -- + + + +-- Iteration 9 -- +\t +\t +\t +-- Iteration 10 -- +PHP +PHP +PHP +-- Iteration 11 -- +PHP +PHP +PHP +-- Iteration 12 -- +abcdn12340567800efgh\xijkl +abcdn12340567800efgh\xijkl +abcdn12340567800efgh\xijkl +-- Iteration 13 -- +abcdefghijklmnop0qrstuvwx0yz +abcdefghijklmnop0qrstuvwx0yz +abcdefghijklmnop0qrstuvwx0yz +-- Iteration 14 -- +1234 +5678 + 9100 +abcda +1234 +5678 + 9100 +abcda +1234 +5678 + 9100 +abcda +*** Testing print_r() on boolean variables *** + +-- Iteration 1 -- +1 +1 +1 +-- Iteration 2 -- + + + +-- Iteration 3 -- +1 +1 +1 +-- Iteration 4 -- + + +bool(true) + +bool(true) + +*** Testing print_r() on array variables *** + +-- Iteration 1 -- +Array +( +) + +Array +( +) + +Array +( +) + +-- Iteration 2 -- +Array +( + [0] => +) + +Array +( + [0] => +) + +Array +( + [0] => +) + +-- Iteration 3 -- +Array +( + [0] => +) + +Array +( + [0] => +) + +Array +( + [0] => +) + +-- Iteration 4 -- +Array +( + [0] => 1 +) + +Array +( + [0] => 1 +) + +Array +( + [0] => 1 +) + +-- Iteration 5 -- +Array +( + [0] => +) + +Array +( + [0] => +) + +Array +( + [0] => +) + +-- Iteration 6 -- +Array +( + [0] => +) + +Array +( + [0] => +) + +Array +( + [0] => +) + +-- Iteration 7 -- +Array +( + [0] => Array + ( + ) + + [1] => Array + ( + ) + +) + +Array +( + [0] => Array + ( + ) + + [1] => Array + ( + ) + +) + +Array +( + [0] => Array + ( + ) + + [1] => Array + ( + ) + +) + +-- Iteration 8 -- +Array +( + [0] => Array + ( + [0] => 1 + [1] => 2 + ) + + [1] => Array + ( + [0] => a + [1] => b + ) + +) + +Array +( + [0] => Array + ( + [0] => 1 + [1] => 2 + ) + + [1] => Array + ( + [0] => a + [1] => b + ) + +) + +Array +( + [0] => Array + ( + [0] => 1 + [1] => 2 + ) + + [1] => Array + ( + [0] => a + [1] => b + ) + +) + +-- Iteration 9 -- +Array +( + [1] => One +) + +Array +( + [1] => One +) + +Array +( + [1] => One +) + +-- Iteration 10 -- +Array +( + [test] => is_array +) + +Array +( + [test] => is_array +) + +Array +( + [test] => is_array +) + +-- Iteration 11 -- +Array +( + [0] => 0 +) + +Array +( + [0] => 0 +) + +Array +( + [0] => 0 +) + +-- Iteration 12 -- +Array +( + [0] => -1 +) + +Array +( + [0] => -1 +) + +Array +( + [0] => -1 +) + +-- Iteration 13 -- +Array +( + [0] => 10.5 + [1] => 5.6 +) + +Array +( + [0] => 10.5 + [1] => 5.6 +) + +Array +( + [0] => 10.5 + [1] => 5.6 +) + +-- Iteration 14 -- +Array +( + [0] => string + [1] => test +) + +Array +( + [0] => string + [1] => test +) + +Array +( + [0] => string + [1] => test +) + +-- Iteration 15 -- +Array +( + [0] => string + [1] => test +) + +Array +( + [0] => string + [1] => test +) + +Array +( + [0] => string + [1] => test +) + +-- Iteration 16 -- +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => Array + ( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => Array + *RECURSION* + ) + +) + +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => Array + ( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => Array + *RECURSION* + ) + +) + +Array +( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => Array + ( + [0] => 1 + [1] => 2 + [2] => 3 + [3] => 4 + [4] => Array + *RECURSION* + ) + +) + +*** Testing print_r() on object variables *** + +-- Iteration 1 -- +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +-- Iteration 2 -- +no_member_class Object +( +) + +no_member_class Object +( +) + +no_member_class Object +( +) + +-- Iteration 3 -- +contains_object_class Object +( + [p] => 30 + [class_object1] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object2] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object3:contains_object_class:private] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object4:protected] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [no_member_class_object] => no_member_class Object + ( + ) + + [class_object5] => contains_object_class Object + *RECURSION* +) + +contains_object_class Object +( + [p] => 30 + [class_object1] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object2] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object3:contains_object_class:private] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object4:protected] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [no_member_class_object] => no_member_class Object + ( + ) + + [class_object5] => contains_object_class Object + *RECURSION* +) + +contains_object_class Object +( + [p] => 30 + [class_object1] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object2] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object3:contains_object_class:private] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object4:protected] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [no_member_class_object] => no_member_class Object + ( + ) + + [class_object5] => contains_object_class Object + *RECURSION* +) + +-- Iteration 4 -- +contains_object_class Object +( + [p] => 30 + [class_object1] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object2] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object3:contains_object_class:private] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object4:protected] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [no_member_class_object] => no_member_class Object + ( + ) + + [class_object5] => contains_object_class Object + *RECURSION* +) + +contains_object_class Object +( + [p] => 30 + [class_object1] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object2] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object3:contains_object_class:private] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object4:protected] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [no_member_class_object] => no_member_class Object + ( + ) + + [class_object5] => contains_object_class Object + *RECURSION* +) + +contains_object_class Object +( + [p] => 30 + [class_object1] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object2] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object3:contains_object_class:private] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [class_object4:protected] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + ) + + [no_member_class_object] => no_member_class Object + ( + ) + + [class_object5] => contains_object_class Object + *RECURSION* +) + +-- Iteration 5 -- +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +-- Iteration 6 -- +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +-- Iteration 7 -- +no_member_class Object +( +) + +no_member_class Object +( +) + +no_member_class Object +( +) + +-- Iteration 8 -- +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 +) + +-- Iteration 9 -- + + + +** Testing print_r() on objects having circular reference ** +object_class Object +( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + [obj] => object_class Object + ( + [value] => 50 + [public_var1] => 10 + [private_var1:object_class:private] => 20 + [private_var2:object_class:private] => 21 + [protected_var1:protected] => string_1 + [protected_var2:protected] => string_2 + [public_var2] => 11 + [obj] => object_class Object + *RECURSION* + ) + +) + +*** Testing print_r() on resources *** + +-- Iteration 1 -- +Resource id #%d +Resource id #%d +Resource id #%d +-- Iteration 2 -- +Resource id #%d +Resource id #%d +Resource id #%d +*** Testing print_r() on different combinations of scalar + and non-scalar variables *** + +-- Iteration 1 -- +Array +( + [0] => 123 + [1] => -1.2345 + [2] => a +) + +Array +( + [0] => 123 + [1] => -1.2345 + [2] => a +) + +Array +( + [0] => 123 + [1] => -1.2345 + [2] => a +) + +-- Iteration 2 -- +Array +( + [0] => d + [1] => Array + ( + [0] => 1 + [1] => 3 + [2] => 5 + ) + + [2] => 1 + [3] => +) + +Array +( + [0] => d + [1] => Array + ( + [0] => 1 + [1] => 3 + [2] => 5 + ) + + [2] => 1 + [3] => +) + +Array +( + [0] => d + [1] => Array + ( + [0] => 1 + [1] => 3 + [2] => 5 + ) + + [2] => 1 + [3] => +) + +-- Iteration 3 -- +Array +( + [0] => no_member_class Object + ( + ) + + [1] => Array + ( + ) + + [2] => + [3] => 0 +) + +Array +( + [0] => no_member_class Object + ( + ) + + [1] => Array + ( + ) + + [2] => + [3] => 0 +) + +Array +( + [0] => no_member_class Object + ( + ) + + [1] => Array + ( + ) + + [2] => + [3] => 0 +) + +-- Iteration 4 -- +Array +( + [0] => 0 + [1] => Where am I? + [2] => Array + ( + [0] => 7 + [1] => 8 + [2] => 9 + ) + + [3] => 1 + [4] => A + [5] => 987654321 +) + +Array +( + [0] => 0 + [1] => Where am I? + [2] => Array + ( + [0] => 7 + [1] => 8 + [2] => 9 + ) + + [3] => 1 + [4] => A + [5] => 987654321 +) + +Array +( + [0] => 0 + [1] => Where am I? + [2] => Array + ( + [0] => 7 + [1] => 8 + [2] => 9 + ) + + [3] => 1 + [4] => A + [5] => 987654321 +) + +-- Iteration 5 -- +Array +( + [0] => + [1] => 20000000000 + [2] => 79.1 + [3] => 4.599998 +) + +Array +( + [0] => + [1] => 20000000000 + [2] => 79.1 + [3] => 4.599998 +) + +Array +( + [0] => + [1] => 20000000000 + [2] => 79.1 + [3] => 4.599998 +) + +-- Iteration 6 -- +Array +( + [0] => array(1,2,3,4)1.0000002TRUE + [1] => + [2] => 4611333 + [3] => /00\7 +) + +Array +( + [0] => array(1,2,3,4)1.0000002TRUE + [1] => + [2] => 4611333 + [3] => /00\7 +) + +Array +( + [0] => array(1,2,3,4)1.0000002TRUE + [1] => + [2] => 4611333 + [3] => /00\7 +) + +*** Testing print_r() on miscelleneous input arguments *** + +-- Iteration 1 -- + + + +-- Iteration 2 -- + + + +-- Iteration 3 -- + + + +-- Iteration 4 -- + + + +*** Testing print_r() on anonymous functions *** +New anonymous function: lambda_1 +2 * 3 = 6lambda_2 + +*** Testing error conditions *** + +Warning: print_r() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +Warning: print_r() expects at most 2 parameters, 3 given in %s on line %d +bool(false) + +Notice: Undefined variable: value in %s on line %d +string(0) "" +Done diff --git a/ext/standard/tests/array/extract.phpt b/ext/standard/tests/array/extract.phpt new file mode 100644 index 0000000000..8c247d0d13 --- /dev/null +++ b/ext/standard/tests/array/extract.phpt @@ -0,0 +1,300 @@ +--TEST-- +Test extract() function +--FILE-- + "aaa", "A" => "AAA", "c" => "ccc", "d" => "ddd", "e" => "eee" ), + array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ), + array( 1 => "one", 2 => "two", 3 => 7, 4 => "four", 5 => "five" ), + array( "f" => "fff", "1" => "one", 4 => 6, "" => "blank", 2.4 => "float", "F" => "FFF", + "blank" => "", 3.7 => 3.7, 5.4 => 7, 6 => 8.6, '5' => "Five", "4name" => "jonny", "a" => NULL, NULL => 3 ), + array( 12, "name", 'age', '45' ), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array() ), + array( "one" => 1, "one" => 2, "three" => 3, 3, 4, 3 => 33, 4 => 44, 5, 6, + 5.4 => 54, 5.7 => 57, "5.4" => 554, "5.7" => 557 ) +); + +$val = 4; +$str = "John"; + +/* Extracting Global Variables */ +extract($GLOBALS, EXTR_REFS); + +/* Testing Error Conditions */ +echo "*** Testing Error Conditions ***\n"; + +/* Zero Arguments */ +var_dump( extract() ); + +/* Invalid second argument ( only 0-6 is valid) */ +var_dump( extract($mixed_array[7], -1 . "wddr") ); +var_dump( extract($mixed_array[7], 7 , "wddr") ); + +/* scalar argument */ +var_dump( extract($val) ); + +/* string argument */ +var_dump( extract($str) ); + +/* More than valid number of arguments i.e. 3 args */ +var_dump( extract($mixed_array[7], EXTR_SKIP, "aa", "ee") ); + +/* Two Arguments, second as prefix but without prefix string as third argument */ +var_dump( extract($mixed_array[7],EXTR_PREFIX_IF_EXISTS) ); + +$counter = 0; + +foreach ( $mixed_array as $sub_array ) { + echo "\n-- Iteration $counter --\n"; + $counter++; + + var_dump ( extract($sub_array)); /* Single Argument */ + + /* variations of two arguments */ + var_dump ( extract($sub_array, EXTR_OVERWRITE)); + var_dump ( extract($sub_array, EXTR_SKIP)); + var_dump ( extract($sub_array, EXTR_IF_EXISTS)); + + /* variations of three arguments with use of various extract types*/ + var_dump ( extract($sub_array, EXTR_PREFIX_INVALID, "ssd")); + var_dump ( extract($sub_array, EXTR_PREFIX_SAME, "sss")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "bb")); + var_dump ( extract($sub_array, EXTR_PREFIX_ALL, "")); // "_" taken as default prefix + var_dump ( extract($sub_array, EXTR_PREFIX_IF_EXISTS, "bb")); +} + + +/* EXTR_REFS as second Argument */ +$a = array ('foo' => 'aaa'); +var_dump ( extract($a, EXTR_REFS)); +$b = $a; +$b['foo'] = 'bbb'; +var_dump ( extract($a, EXTR_REFS)); + +/* EXTR_PREFIX_ALL called twice with same prefix string */ +echo "\n*** Testing for EXTR_PREFIX_ALL called twice with same prefix string ***\n"; +var_dump ( extract($mixed_array[5], EXTR_PREFIX_ALL, "same")); +var_dump ( extract($mixed_array[7], EXTR_PREFIX_ALL, "same")); +var_dump ( extract($mixed_array[7], EXTR_PREFIX_ALL, "diff")); + +/* To show variables with numerical prefixes cannot be extracted */ +$var["i"] = 1; +$var["j"] = 2; +$var["k"] = 3; +echo "\n*** Testing for Numerical prefixes ***\n"; +var_dump(extract($var)); + + +$var1["m"] = 1; +$var1[2] = 2; +$var1[] = 3; +var_dump ( extract($var1)); + + +/* Using Class and objects */ + +echo "\n*** Testing for object ***\n"; +class classA +{ + public $v; +} + +$A = new classA(); +var_dump ( extract(get_object_vars($A),EXTR_REFS)); + +echo "\nDone"; +?> + +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: extract() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Notice: A non well formed numeric value encountered in %s on line %d + +Warning: extract(): Invalid extract type in %s on line %d +NULL + +Warning: extract(): Invalid extract type in %s on line %d +NULL + +Warning: extract() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: extract() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: extract() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: extract(): specified extract type requires the prefix parameter in %s on line %d +NULL + +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 1 -- +int(0) +int(0) +int(0) +int(0) +int(9) +int(0) +int(9) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 3 -- +int(0) +int(0) +int(0) +int(0) +int(8) +int(0) +int(8) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 4 -- +int(5) +int(5) +int(0) +int(5) +int(5) +int(5) +int(5) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(5) + +-- Iteration 5 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 6 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 7 -- +int(6) +int(6) +int(0) +int(6) +int(12) +int(5) +int(11) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(6) + +-- Iteration 8 -- +int(0) +int(0) +int(0) +int(0) +int(4) +int(0) +int(4) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 9 -- +int(0) +int(0) +int(0) +int(0) +int(3) +int(0) +int(3) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(0) + +-- Iteration 10 -- +int(4) +int(4) +int(0) +int(4) +int(10) +int(4) +int(10) + +Warning: extract(): prefix is not a valid identifier in %s on line %d +NULL +int(4) +int(1) +int(1) + +*** Testing for EXTR_PREFIX_ALL called twice with same prefix string *** +int(5) +int(11) +int(11) + +*** Testing for Numerical prefixes *** +int(3) +int(1) + +*** Testing for object *** +int(1) + +Done