diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-03-14 05:42:27 +0000 |
---|---|---|
committer | <> | 2013-04-03 16:25:08 +0000 |
commit | c4dd7a1a684490673e25aaf4fabec5df138854c4 (patch) | |
tree | 4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/array | |
download | php2-master.tar.gz |
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/array')
878 files changed, 119519 insertions, 0 deletions
diff --git a/ext/standard/tests/array/001.phpt b/ext/standard/tests/array/001.phpt new file mode 100644 index 0000000..797a797 --- /dev/null +++ b/ext/standard/tests/array/001.phpt @@ -0,0 +1,157 @@ +--TEST-- +Test array_merge and array_walk +--INI-- +precision=14 +--FILE-- +<?php +require(dirname(__FILE__) . '/data.inc'); +/* +** Create sample arrays +** Test alpha, numeric (decimal, hex, octal) and special data +** +** +*/ + +/* Helper function to build testing arrays */ +function make_nested_array ($depth, $breadth, $function = NULL, $args = array ()) { + for ($x = 0; $x < $breadth; ++$x) { + if (NULL === $function) { + $array = array (0); + } else { + $array = array (call_user_func_array ($function, $args)); + } + for ($y = 1; $y < $depth; ++$y) { + $array[0] = array ($array[0]); + } + $temp[$x] = $array; + } + return $temp; +} + +/* Nested array */ +$data2 = make_nested_array (3, 3); +$data = array_merge($data, $data2); + +var_dump ($data); + +function echo_kv ($value, $key) { + var_dump ($key); + var_dump ($value); +} + +echo " -- Testing array_walk() -- \n"; +array_walk ($data, 'echo_kv'); + +?> +--EXPECT-- +array(11) { + [0]=> + string(3) "PHP" + [1]=> + string(27) "PHP: Hypertext Preprocessor" + [2]=> + string(4) "Test" + ["test"]=> + int(27) + [3]=> + string(4) "test" + [4]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [5]=> + string(6) "monkey" + [6]=> + float(-0.33333333333333) + [7]=> + array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } + } + } + [8]=> + array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } + } + } + [9]=> + array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } + } + } +} + -- Testing array_walk() -- +int(0) +string(3) "PHP" +int(1) +string(27) "PHP: Hypertext Preprocessor" +int(2) +string(4) "Test" +string(4) "test" +int(27) +int(3) +string(4) "test" +int(4) +array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" +} +int(5) +string(6) "monkey" +int(6) +float(-0.33333333333333) +int(7) +array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } + } +} +int(8) +array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } + } +} +int(9) +array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } + } +} diff --git a/ext/standard/tests/array/002.phpt b/ext/standard/tests/array/002.phpt new file mode 100644 index 0000000..469e862 --- /dev/null +++ b/ext/standard/tests/array/002.phpt @@ -0,0 +1,684 @@ +--TEST-- +Test arsort, asort, krsort, ksort, rsort, and sort +--INI-- +precision=14 +--FILE-- +<?php +require(dirname(__FILE__) . '/data.inc'); + +function test_sort ($sort_function, $data) { + echo "\n -- Testing $sort_function() -- \n"; + echo "No second argument:\n"; + $sort_function ($data); + var_dump ($data); + echo "Using SORT_REGULAR:\n"; + $sort_function ($data, SORT_REGULAR); + var_dump ($data); + echo "Using SORT_NUMERIC:\n"; + $sort_function ($data, SORT_NUMERIC); + var_dump ($data); + echo "Using SORT_STRING\n"; + $sort_function ($data, SORT_STRING); + var_dump ($data); +} + +echo "Unsorted data:\n"; +var_dump ($data); +foreach (array ('arsort', 'asort', 'krsort', 'ksort', 'rsort', 'sort') as $test_function) { + test_sort ($test_function, $data); +} + +?> +--EXPECTF-- +Unsorted data: +array(8) { + [0]=> + string(3) "PHP" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + ["test"]=> + int(27) + [1000]=> + string(4) "test" + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [1001]=> + string(6) "monkey" + [16777216]=> + float(-0.33333333333333) +} + + -- Testing arsort() -- +No second argument: +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + ["test"]=> + int(27) + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [0]=> + string(3) "PHP" + [16777216]=> + float(-0.33333333333333) +} +Using SORT_REGULAR: +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + ["test"]=> + int(27) + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [0]=> + string(3) "PHP" + [16777216]=> + float(-0.33333333333333) +} +Using SORT_NUMERIC: +array(8) { + ["test"]=> + int(27) + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [0]=> + string(3) "PHP" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [1001]=> + string(6) "monkey" + [5]=> + string(4) "Test" + [1000]=> + string(4) "test" + [16777216]=> + float(-0.33333333333333) +} +Using SORT_STRING + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d +array(8) { + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [0]=> + string(3) "PHP" + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + ["test"]=> + int(27) + [16777216]=> + float(-0.33333333333333) +} + + -- Testing asort() -- +No second argument: +array(8) { + [16777216]=> + float(-0.33333333333333) + [0]=> + string(3) "PHP" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + ["test"]=> + int(27) + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_REGULAR: +array(8) { + [16777216]=> + float(-0.33333333333333) + [0]=> + string(3) "PHP" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + ["test"]=> + int(27) + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_NUMERIC: +array(8) { + [16777216]=> + float(-0.33333333333333) + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [0]=> + string(3) "PHP" + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + ["test"]=> + int(27) +} +Using SORT_STRING + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d +array(8) { + [16777216]=> + float(-0.33333333333333) + ["test"]=> + int(27) + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [0]=> + string(3) "PHP" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" +} + + -- Testing krsort() -- +No second argument: +array(8) { + [16777216]=> + float(-0.33333333333333) + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + ["test"]=> + int(27) + [0]=> + string(3) "PHP" + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_REGULAR: +array(8) { + [16777216]=> + float(-0.33333333333333) + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [0]=> + string(3) "PHP" + ["test"]=> + int(27) + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_NUMERIC: +array(8) { + [16777216]=> + float(-0.33333333333333) + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + ["test"]=> + int(27) + [0]=> + string(3) "PHP" + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_STRING +array(8) { + ["test"]=> + int(27) + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [16777216]=> + float(-0.33333333333333) + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" + [0]=> + string(3) "PHP" + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} + + -- Testing ksort() -- +No second argument: +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [0]=> + string(3) "PHP" + ["test"]=> + int(27) + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [16777216]=> + float(-0.33333333333333) +} +Using SORT_REGULAR: +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + ["test"]=> + int(27) + [0]=> + string(3) "PHP" + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [16777216]=> + float(-0.33333333333333) +} +Using SORT_NUMERIC: +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [0]=> + string(3) "PHP" + ["test"]=> + int(27) + [5]=> + string(4) "Test" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [16777216]=> + float(-0.33333333333333) +} +Using SORT_STRING +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [0]=> + string(3) "PHP" + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [16777216]=> + float(-0.33333333333333) + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + ["test"]=> + int(27) +} + + -- Testing rsort() -- +No second argument: +array(8) { + [0]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [1]=> + int(27) + [2]=> + string(4) "test" + [3]=> + string(6) "monkey" + [4]=> + string(4) "Test" + [5]=> + string(27) "PHP: Hypertext Preprocessor" + [6]=> + string(3) "PHP" + [7]=> + float(-0.33333333333333) +} +Using SORT_REGULAR: +array(8) { + [0]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [1]=> + int(27) + [2]=> + string(4) "test" + [3]=> + string(6) "monkey" + [4]=> + string(4) "Test" + [5]=> + string(27) "PHP: Hypertext Preprocessor" + [6]=> + string(3) "PHP" + [7]=> + float(-0.33333333333333) +} +Using SORT_NUMERIC: +array(8) { + [0]=> + int(27) + [1]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [2]=> + string(3) "PHP" + [3]=> + string(27) "PHP: Hypertext Preprocessor" + [4]=> + string(6) "monkey" + [5]=> + string(4) "Test" + [6]=> + string(4) "test" + [7]=> + float(-0.33333333333333) +} +Using SORT_STRING + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d +array(8) { + [0]=> + string(4) "test" + [1]=> + string(6) "monkey" + [2]=> + string(4) "Test" + [3]=> + string(27) "PHP: Hypertext Preprocessor" + [4]=> + string(3) "PHP" + [5]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [6]=> + int(27) + [7]=> + float(-0.33333333333333) +} + + -- Testing sort() -- +No second argument: +array(8) { + [0]=> + float(-0.33333333333333) + [1]=> + string(3) "PHP" + [2]=> + string(27) "PHP: Hypertext Preprocessor" + [3]=> + string(4) "Test" + [4]=> + string(6) "monkey" + [5]=> + string(4) "test" + [6]=> + int(27) + [7]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_REGULAR: +array(8) { + [0]=> + float(-0.33333333333333) + [1]=> + string(3) "PHP" + [2]=> + string(27) "PHP: Hypertext Preprocessor" + [3]=> + string(4) "Test" + [4]=> + string(6) "monkey" + [5]=> + string(4) "test" + [6]=> + int(27) + [7]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } +} +Using SORT_NUMERIC: +array(8) { + [0]=> + float(-0.33333333333333) + [1]=> + string(6) "monkey" + [2]=> + string(4) "test" + [3]=> + string(4) "Test" + [4]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(3) "PHP" + [6]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [7]=> + int(27) +} +Using SORT_STRING + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d + +Notice: Array to string conversion in %s002.php on line %d +array(8) { + [0]=> + float(-0.33333333333333) + [1]=> + int(27) + [2]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [3]=> + string(3) "PHP" + [4]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [6]=> + string(6) "monkey" + [7]=> + string(4) "test" +} diff --git a/ext/standard/tests/array/003.phpt b/ext/standard/tests/array/003.phpt new file mode 100644 index 0000000..f307186 --- /dev/null +++ b/ext/standard/tests/array/003.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test usort, uksort and uasort +--INI-- +precision=14 +--FILE-- +<?php +require(dirname(__FILE__) . '/data.inc'); + +function cmp ($a, $b) { + is_array ($a) + and $a = array_sum ($a); + is_array ($b) + and $b = array_sum ($b); + return strcmp ($a, $b); +} + +echo " -- Testing uasort() -- \n"; +uasort ($data, 'cmp'); +var_dump ($data); + + +echo "\n -- Testing uksort() -- \n"; +uksort ($data, 'cmp'); +var_dump ($data); + +echo "\n -- Testing usort() -- \n"; +usort ($data, 'cmp'); +var_dump ($data); +?> +--EXPECT-- +-- Testing uasort() -- +array(8) { + [16777216]=> + float(-0.33333333333333) + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + ["test"]=> + int(27) + [0]=> + string(3) "PHP" + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [1001]=> + string(6) "monkey" + [1000]=> + string(4) "test" +} + + -- Testing uksort() -- +array(8) { + [-1000]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [0]=> + string(3) "PHP" + [1000]=> + string(4) "test" + [1001]=> + string(6) "monkey" + [16777216]=> + float(-0.33333333333333) + [17]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + ["test"]=> + int(27) +} + + -- Testing usort() -- +array(8) { + [0]=> + float(-0.33333333333333) + [1]=> + array(2) { + [0]=> + string(6) "banana" + [1]=> + string(6) "orange" + } + [2]=> + int(27) + [3]=> + string(3) "PHP" + [4]=> + string(27) "PHP: Hypertext Preprocessor" + [5]=> + string(4) "Test" + [6]=> + string(6) "monkey" + [7]=> + string(4) "test" +} diff --git a/ext/standard/tests/array/004.phpt b/ext/standard/tests/array/004.phpt new file mode 100644 index 0000000..765637b --- /dev/null +++ b/ext/standard/tests/array/004.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test natsort and natcasesort +--INI-- +precision=14 +--FILE-- +<?php +$data = array( + 'Test1', + 'teST2'=>0, + 5=>'test2', + 'abc'=>'test10', + 'test21' +); + +var_dump($data); + +natsort($data); +var_dump($data); + +natcasesort($data); +var_dump($data); +?> +--EXPECT-- +array(5) { + [0]=> + string(5) "Test1" + ["teST2"]=> + int(0) + [5]=> + string(5) "test2" + ["abc"]=> + string(6) "test10" + [6]=> + string(6) "test21" +} +array(5) { + ["teST2"]=> + int(0) + [0]=> + string(5) "Test1" + [5]=> + string(5) "test2" + ["abc"]=> + string(6) "test10" + [6]=> + string(6) "test21" +} +array(5) { + ["teST2"]=> + int(0) + [0]=> + string(5) "Test1" + [5]=> + string(5) "test2" + ["abc"]=> + string(6) "test10" + [6]=> + string(6) "test21" +} diff --git a/ext/standard/tests/array/005.phpt b/ext/standard/tests/array/005.phpt new file mode 100644 index 0000000..f724932 --- /dev/null +++ b/ext/standard/tests/array/005.phpt @@ -0,0 +1,291 @@ +--TEST-- +Test array_shift() function +--FILE-- +<?php +/* Prototype: mixed array_shift( array &array ); + * Description: Shifts the first value of the array off and returns it. + */ + +array_shift($GLOBALS); + +$empty_array = array(); +$number = 5; +$str = "abc"; + + +/* 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 ) +); + +/* 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"; +?> +--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]=> + string(3) "oNe" + [1]=> + 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/006.phpt b/ext/standard/tests/array/006.phpt new file mode 100644 index 0000000..4893ad3 --- /dev/null +++ b/ext/standard/tests/array/006.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_pop behaviour +--FILE-- +<?php + +array_pop($GLOBALS); + +$a = array("foo", "bar", "fubar"); +$b = array("3" => "foo", "4" => "bar", "5" => "fubar"); +$c = array("a" => "foo", "b" => "bar", "c" => "fubar"); + +/* simple array */ +echo array_pop($a), "\n"; +array_push($a, "foobar"); +var_dump($a); + +/* numerical assoc indices */ +echo array_pop($b), "\n"; +var_dump($b); + +/* assoc indices */ +echo array_pop($c), "\n"; +var_dump($c); + +?> +--EXPECT-- +fubar +array(3) { + [0]=> + string(3) "foo" + [1]=> + string(3) "bar" + [2]=> + string(6) "foobar" +} +fubar +array(2) { + [3]=> + string(3) "foo" + [4]=> + string(3) "bar" +} +fubar +array(2) { + ["a"]=> + string(3) "foo" + ["b"]=> + string(3) "bar" +} diff --git a/ext/standard/tests/array/007.phpt b/ext/standard/tests/array/007.phpt new file mode 100644 index 0000000..e30b8fe --- /dev/null +++ b/ext/standard/tests/array/007.phpt @@ -0,0 +1,553 @@ +--TEST-- +Test array_diff and array_diff_assoc behaviour +--FILE-- +<?php +$a = array(1,"big"=>2,3,6,3,5,3,3,3,3,3,3,3,3,3,3); +$b = array(2,2,3,3,3,3,3,3,3,3,3,3,3,3,3); +$c = array(-1,1); +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo '$c='.var_export($c,TRUE).";\n"; +var_dump(array_diff($a,$b,$c)); +var_dump(array_diff_assoc($a,$b,$c)); +$a = array( +'a'=>2, +'b'=>'some', +'c'=>'done', +'z'=>'foo', +'f'=>5, +'fan'=>'fen', +7=>18, +9=>25, +11=>42, +12=>42, +45=>42, +73=>'foo', +95=>'some', +'som3'=>'some', +'want'=>'wanna'); +$b = array( +'a'=>7, +7=>18, +9=>13, +11=>42, +45=>46, +'som3'=>'some', +'foo'=>'some', +'goo'=>'foo', +'f'=>5, +'z'=>'equal' +); +$c = array( +73=>'foo', +95=>'some'); +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo '$c='.var_export($c,TRUE).";\n"; +echo "Results:\n\n"; +var_dump(array_diff($a,$b,$c)); +var_dump(array_diff_assoc($a,$b,$c)); + +echo "-=-=-=-=-=-=-=-=- New functionality from 5.0.0 -=-=-=-=-=-=-=-\n"; +error_reporting(E_ALL); +class cr { + private $priv_member; + public $public_member; + function cr($val) { + $this->priv_member = $val; + $this->public_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member)? 1:-1; + } +} + +function comp_func($a, $b) { + if ($a === $b) return 0; + return ($a > $b)? 1:-1; + +} + +function comp_func_cr($a, $b) { + if ($a->public_member === $b->public_member) return 0; + return ($a->public_member > $b->public_member)? 1:-1; +} + + +/* +$a = array(1,"big"=>2,3,6,3,5,3,3,3,3,3,3,3,3,3,3); +$b = array(2,2,3,3,3,3,3,3,3,3,3,3,3,3,3); +$c = array(-1,1); +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo '$c='.var_export($c,TRUE).";\n"; +var_dump(array_diff($a,$b,$c)); +var_dump(array_diff_assoc($a,$b,$c)); +var_dump(array_udiff($a, $b, $c, "comp_func")); +var_dump(array_diff_uassoc($a,$b,$c, "comp_func")); +*/ + +/* + $a = array(new cr(9),new cr(12),new cr(23),new cr(4),new cr(-15),); + $b = array(new cr(9),new cr(22),new cr( 3),new cr(4),new cr(-15),); + var_dump(array_udiff($a, $b, "comp_func_cr")); +*/ +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr( 3), 1=> new cr(4), 2 => new cr(-15),); + +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_udiff_uassoc($a, $b, "comp_func_cr", "comp_func"));'."\n"; +var_dump(array_udiff_uassoc($a, $b, "comp_func_cr", "comp_func")); + + +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));'."\n"; +var_dump(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); + + +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_udiff($a, $b, "comp_func_cr"));'."\n"; +var_dump(array_udiff($a, $b, "comp_func_cr")); + + +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_udiff_assoc($a, $b, "comp_func_cr"));'."\n"; +var_dump(array_udiff_assoc($a, $b, "comp_func_cr")); + +?> +--EXPECTF-- +$a=array ( + 0 => 1, + 'big' => 2, + 1 => 3, + 2 => 6, + 3 => 3, + 4 => 5, + 5 => 3, + 6 => 3, + 7 => 3, + 8 => 3, + 9 => 3, + 10 => 3, + 11 => 3, + 12 => 3, + 13 => 3, + 14 => 3, +); +$b=array ( + 0 => 2, + 1 => 2, + 2 => 3, + 3 => 3, + 4 => 3, + 5 => 3, + 6 => 3, + 7 => 3, + 8 => 3, + 9 => 3, + 10 => 3, + 11 => 3, + 12 => 3, + 13 => 3, + 14 => 3, +); +$c=array ( + 0 => -1, + 1 => 1, +); +array(2) { + [2]=> + int(6) + [4]=> + int(5) +} +array(5) { + [0]=> + int(1) + ["big"]=> + int(2) + [1]=> + int(3) + [2]=> + int(6) + [4]=> + int(5) +} +$a=array ( + 'a' => 2, + 'b' => 'some', + 'c' => 'done', + 'z' => 'foo', + 'f' => 5, + 'fan' => 'fen', + 7 => 18, + 9 => 25, + 11 => 42, + 12 => 42, + 45 => 42, + 73 => 'foo', + 95 => 'some', + 'som3' => 'some', + 'want' => 'wanna', +); +$b=array ( + 'a' => 7, + 7 => 18, + 9 => 13, + 11 => 42, + 45 => 46, + 'som3' => 'some', + 'foo' => 'some', + 'goo' => 'foo', + 'f' => 5, + 'z' => 'equal', +); +$c=array ( + 73 => 'foo', + 95 => 'some', +); +Results: + +array(5) { + ["a"]=> + int(2) + ["c"]=> + string(4) "done" + ["fan"]=> + string(3) "fen" + [9]=> + int(25) + ["want"]=> + string(5) "wanna" +} +array(9) { + ["a"]=> + int(2) + ["b"]=> + string(4) "some" + ["c"]=> + string(4) "done" + ["z"]=> + string(3) "foo" + ["fan"]=> + string(3) "fen" + [9]=> + int(25) + [12]=> + int(42) + [45]=> + int(42) + ["want"]=> + string(5) "wanna" +} +-=-=-=-=-=-=-=-=- New functionality from 5.0.0 -=-=-=-=-=-=-=- +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_udiff_uassoc($a, $b, "comp_func_cr", "comp_func")); +array(3) { + ["0.1"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(9) + ["public_member"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(12) + ["public_member"]=> + int(12) + } + [0]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(23) + ["public_member"]=> + int(23) + } +} +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); +array(3) { + ["0.1"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(9) + ["public_member"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(12) + ["public_member"]=> + int(12) + } + [0]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(23) + ["public_member"]=> + int(23) + } +} +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_udiff($a, $b, "comp_func_cr")); +array(2) { + ["0.5"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(12) + ["public_member"]=> + int(12) + } + [0]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(23) + ["public_member"]=> + int(23) + } +} +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_udiff_assoc($a, $b, "comp_func_cr")); +array(3) { + ["0.1"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(9) + ["public_member"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(12) + ["public_member"]=> + int(12) + } + [0]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(23) + ["public_member"]=> + int(23) + } +} diff --git a/ext/standard/tests/array/008.phpt b/ext/standard/tests/array/008.phpt new file mode 100644 index 0000000..a3dde36 --- /dev/null +++ b/ext/standard/tests/array/008.phpt @@ -0,0 +1,310 @@ +--TEST-- +Test array_intersect and array_intersect_assoc behaviour +--FILE-- +<?php +//-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=- TEST 1 -=-=-=-=- +$a = array(1,"big"=>2,2,6,3,5,3,3,454,'some_string',3,3,3,3,3,3,3,3,17); +$b = array(2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,17,25,'some_string',7,8,9,109,78,17); +$c = array(-1,2,1,15,25,17); +echo str_repeat("-=",10)." TEST 1 ".str_repeat("-=",20)."\n"; +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo '$c='.var_export($c,TRUE).";\n"; + +echo 'array_intersect($a,$b,$c);'."\n"; +var_dump(array_intersect($a,$b,$c)); + +echo 'array_intersect_assoc($a,$b,$c);'."\n"; +var_dump(array_intersect_assoc($a,$b,$c)); + +echo 'array_intersect($a,$b);'."\n"; +var_dump(array_intersect($a,$b)); + +echo 'array_intersect_assoc($a,$b);'."\n"; +var_dump(array_intersect_assoc($a,$b)); + +//-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=- TEST 2 -=-=-=-=-=- +$a = array( +'a'=>2, +'b'=>'some', +'c'=>'done', +'z'=>'foo', +'f'=>5, +'fan'=>'fen', +'bad'=>'bed', +'gate'=>'web', +7=>18, +9=>25, +11=>42, +12=>42, +45=>42, +73=>'foo', +95=>'some', +'som3'=>'some', +'want'=>'wanna'); + + +$b = array( +'a'=>7, +7=>18, +9=>13, +11=>42, +45=>46, +'som3'=>'some', +'foo'=>'some', +'goo'=>'foo', +'f'=>5, +'z'=>'equal', +'gate'=>'web' +); +$c = array( +'gate'=>'web', +73=>'foo', +95=>'some' +); + +echo str_repeat("-=",10)." TEST 2 ".str_repeat("-=",20)."\n"; +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo '$c='.var_export($c,TRUE).";\n"; +echo "\n\nResults:\n\n"; + +echo 'array_intersect($a,$b,$c);'."\n"; +var_dump(array_intersect($a,$b,$c)); + +echo 'array_intersect_assoc($a,$b,$c);'."\n"; +var_dump(array_intersect_assoc($a,$b,$c)); + +echo 'array_intersect($a,$b);'."\n"; +var_dump(array_intersect($a,$b)); + +echo 'array_intersect_assoc($a,$b);'."\n"; +var_dump(array_intersect_assoc($a,$b)); +?> +--EXPECT-- +-=-=-=-=-=-=-=-=-=-= TEST 1 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +$a=array ( + 0 => 1, + 'big' => 2, + 1 => 2, + 2 => 6, + 3 => 3, + 4 => 5, + 5 => 3, + 6 => 3, + 7 => 454, + 8 => 'some_string', + 9 => 3, + 10 => 3, + 11 => 3, + 12 => 3, + 13 => 3, + 14 => 3, + 15 => 3, + 16 => 3, + 17 => 17, +); +$b=array ( + 0 => 2, + 1 => 2, + 2 => 3, + 3 => 3, + 4 => 3, + 5 => 3, + 6 => 3, + 7 => 3, + 8 => 3, + 9 => 3, + 10 => 3, + 11 => 3, + 12 => 3, + 13 => 3, + 14 => 3, + 15 => 17, + 16 => 25, + 17 => 'some_string', + 18 => 7, + 19 => 8, + 20 => 9, + 21 => 109, + 22 => 78, + 23 => 17, +); +$c=array ( + 0 => -1, + 1 => 2, + 2 => 1, + 3 => 15, + 4 => 25, + 5 => 17, +); +array_intersect($a,$b,$c); +array(3) { + ["big"]=> + int(2) + [1]=> + int(2) + [17]=> + int(17) +} +array_intersect_assoc($a,$b,$c); +array(1) { + [1]=> + int(2) +} +array_intersect($a,$b); +array(15) { + ["big"]=> + int(2) + [1]=> + int(2) + [3]=> + int(3) + [5]=> + int(3) + [6]=> + int(3) + [8]=> + string(11) "some_string" + [9]=> + int(3) + [10]=> + int(3) + [11]=> + int(3) + [12]=> + int(3) + [13]=> + int(3) + [14]=> + int(3) + [15]=> + int(3) + [16]=> + int(3) + [17]=> + int(17) +} +array_intersect_assoc($a,$b); +array(10) { + [1]=> + int(2) + [3]=> + int(3) + [5]=> + int(3) + [6]=> + int(3) + [9]=> + int(3) + [10]=> + int(3) + [11]=> + int(3) + [12]=> + int(3) + [13]=> + int(3) + [14]=> + int(3) +} +-=-=-=-=-=-=-=-=-=-= TEST 2 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +$a=array ( + 'a' => 2, + 'b' => 'some', + 'c' => 'done', + 'z' => 'foo', + 'f' => 5, + 'fan' => 'fen', + 'bad' => 'bed', + 'gate' => 'web', + 7 => 18, + 9 => 25, + 11 => 42, + 12 => 42, + 45 => 42, + 73 => 'foo', + 95 => 'some', + 'som3' => 'some', + 'want' => 'wanna', +); +$b=array ( + 'a' => 7, + 7 => 18, + 9 => 13, + 11 => 42, + 45 => 46, + 'som3' => 'some', + 'foo' => 'some', + 'goo' => 'foo', + 'f' => 5, + 'z' => 'equal', + 'gate' => 'web', +); +$c=array ( + 'gate' => 'web', + 73 => 'foo', + 95 => 'some', +); + + +Results: + +array_intersect($a,$b,$c); +array(6) { + ["b"]=> + string(4) "some" + ["z"]=> + string(3) "foo" + ["gate"]=> + string(3) "web" + [73]=> + string(3) "foo" + [95]=> + string(4) "some" + ["som3"]=> + string(4) "some" +} +array_intersect_assoc($a,$b,$c); +array(1) { + ["gate"]=> + string(3) "web" +} +array_intersect($a,$b); +array(11) { + ["b"]=> + string(4) "some" + ["z"]=> + string(3) "foo" + ["f"]=> + int(5) + ["gate"]=> + string(3) "web" + [7]=> + int(18) + [11]=> + int(42) + [12]=> + int(42) + [45]=> + int(42) + [73]=> + string(3) "foo" + [95]=> + string(4) "some" + ["som3"]=> + string(4) "some" +} +array_intersect_assoc($a,$b); +array(5) { + ["f"]=> + int(5) + ["gate"]=> + string(3) "web" + [7]=> + int(18) + [11]=> + int(42) + ["som3"]=> + string(4) "some" +} diff --git a/ext/standard/tests/array/009.phpt b/ext/standard/tests/array/009.phpt new file mode 100644 index 0000000..f88f876 --- /dev/null +++ b/ext/standard/tests/array/009.phpt @@ -0,0 +1,535 @@ +--TEST-- +Test key(), current(), next() & reset() functions +--FILE-- +<?php +/* Prototype & Usage: + mixed key ( array &$array ) -> 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 new file mode 100644 index 0000000..3123458 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case.phpt @@ -0,0 +1,817 @@ +--TEST-- +Test array_change_key_case() function +--FILE-- +<?php +/* Prototype: array array_change_key_case ( array $input [, int $case] ) + Description: Changes the keys in the input array to be all lowercase + or uppercase. The change depends on the last optional case parameter. + You can pass two constants there, CASE_UPPER and CASE_LOWER(default). + The function will leave number indices as is. +*/ +$arrays = array ( + 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 "end\n"; +?> +--EXPECTF-- +*** Testing basic operations *** +** Iteration 1 ** +array(0) { +} +array(0) { +} +array(0) { +} + +** Iteration 2 ** +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} + +** Iteration 3 ** +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} + +** Iteration 4 ** +array(1) { + [0]=> + int(-1) +} +array(1) { + [0]=> + int(-1) +} +array(1) { + [0]=> + int(-1) +} + +** Iteration 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(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} + +** Iteration 6 ** +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]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} + +** Iteration 7 ** +array(1) { + [""]=> + int(1) +} +array(1) { + [""]=> + int(1) +} +array(1) { + [""]=> + int(1) +} + +** Iteration 8 ** +array(1) { + ["a"]=> + int(1) +} +array(1) { + ["A"]=> + int(1) +} +array(1) { + ["a"]=> + int(1) +} + +** Iteration 9 ** +array(1) { + ["z"]=> + int(1) +} +array(1) { + ["Z"]=> + int(1) +} +array(1) { + ["z"]=> + int(1) +} + +** Iteration 10 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 11 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 12 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 13 ** +array(1) { + ["one"]=> + int(1) +} +array(1) { + ["ONE"]=> + int(1) +} +array(1) { + ["one"]=> + int(1) +} + +** Iteration 14 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 15 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 16 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 17 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 18 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 19 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 20 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 21 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 22 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 23 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 24 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 25 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 26 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 27 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 28 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 29 ** +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} + +** Iteration 30 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 31 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 32 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 33 ** +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["ONE"]=> + int(1) + [0]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + [0]=> + int(2) +} + +** Iteration 34 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "four" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} + +** Iteration 35 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "FOUR" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} + +** Iteration 36 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "FOUR" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "FOUR" +} + +** Iteration 37 ** +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "four" +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + ["four"]=> + string(4) "four" +} + +end diff --git a/ext/standard/tests/array/array_change_key_case_errors.phpt b/ext/standard/tests/array/array_change_key_case_errors.phpt new file mode 100644 index 0000000..ec506f7 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_errors.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test array_change_key_case() function - 3 +--FILE-- +<?php +/* generate different failure conditions */ +$int_var = -19; +$item = array ("one" => 1, "two" => 2, "THREE" => 3, "FOUR" => "four"); + +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() ); // Zero argument +var_dump( array_change_key_case($item, $item["one"], "CASE_UPPER") ); // more than expected numbers + +echo "end\n"; +?> +--EXPECTF-- +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL + +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_change_key_case_variation.phpt b/ext/standard/tests/array/array_change_key_case_variation.phpt new file mode 100644 index 0000000..e03b8d5 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_change_key_case() function - 2 +--FILE-- +<?php + +$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, "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) ) ); +var_dump( array_change_key_case( array("ONE" => 1, "one" => 6, "One" => 5), "CASE_UPPER" ) ); + +/* 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 "end\n"; +?> +--EXPECTF-- +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL +array(4) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) + ["FOUR"]=> + string(4) "four" +} +array(1) { + ["one"]=> + int(4) +} + +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL +array(1) { + ["ONE"]=> + int(3) +} +array(1) { + ["ONE"]=> + int(2) +} +end diff --git a/ext/standard/tests/array/array_change_key_case_variation1.phpt b/ext/standard/tests/array/array_change_key_case_variation1.phpt new file mode 100644 index 0000000..bb490a7 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation1.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Pass different data types as $input arg +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $input argument to test behaviour of array_change_key_case() + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_change_key_case($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 -- + +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_change_key_case() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_change_key_case() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_change_key_case() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_change_key_case() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_change_key_case() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_change_key_case() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_change_key_case() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_change_key_case() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_change_key_case() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_change_key_case() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_change_key_case() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_change_key_case() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_change_key_case() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_change_key_case() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_change_key_case() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_change_key_case() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_change_key_case() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_change_key_case() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_change_key_case() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_change_key_case() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_change_key_case() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation2.phpt b/ext/standard/tests/array/array_change_key_case_variation2.phpt new file mode 100644 index 0000000..929ccb1 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation2.phpt @@ -0,0 +1,288 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Pass different data types as $case arg +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $case argument to array_change_key_case() to test behaviour + * Where possible, CASE_UPPER has been entered as a string value + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$array = array ('one' => 1, 'TWO' => 2, 'Three' => 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +CASE_UPPER +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $case argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "CASE_UPPER", + 'CASE_UPPER', + $heredoc, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_change_key_case($array, $input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 2 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 3 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 4 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 5 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 6 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 7 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 8 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 11 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 12 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 14 -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} + +-- Iteration 15 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 16 -- + +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_change_key_case() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_change_key_case() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 22 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 23 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation3.phpt b/ext/standard/tests/array/array_change_key_case_variation3.phpt new file mode 100644 index 0000000..5967033 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation3.phpt @@ -0,0 +1,197 @@ +--TEST-- +Test array_change_key_case() function : usage variations - different data types as keys +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays with different data types as keys to array_change_key_case() + * to test conversion + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays of different data types to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + + 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each sub-array of $inputs to check the behavior of array_change_key_case() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( array_change_key_case($input, CASE_UPPER) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Iteration 1 : int data -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} + +-- Iteration 2 : float data -- +array(3) { + [10]=> + string(8) "positive" + [-10]=> + string(8) "negative" + [0]=> + string(4) "half" +} + +-- Iteration 3 : extreme floats data -- +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} + +-- Iteration 4 : null uppercase data -- +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 : null lowercase data -- +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 : bool lowercase data -- +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} + +-- Iteration 7 : bool uppercase data -- +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} + +-- Iteration 8 : empty double quotes data -- +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 : empty single quotes data -- +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 : string data -- +array(3) { + ["STRINGD"]=> + string(7) "stringd" + ["STRINGS"]=> + string(7) "strings" + ["HELLO WORLD"]=> + string(7) "stringh" +} + +-- Iteration 11 : undefined data -- +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 : unset data -- +array(1) { + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation4.phpt b/ext/standard/tests/array/array_change_key_case_variation4.phpt new file mode 100644 index 0000000..ad9ad75 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation4.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test array_change_key_case() function : usage variations - different int values for $case +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Pass different integer values as $case argument to array_change_key_case() to test behaviour + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array('One' => 'un', 'TWO' => 'deux', 'three' => 'trois'); +for ($i = -5; $i <=5; $i += 1){ + echo "\n-- \$sort argument is $i --\n"; + $temp = $input; + var_dump(array_change_key_case($temp, $i)); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- $sort argument is -5 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -4 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -3 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -2 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is -1 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 0 -- +array(3) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + ["three"]=> + string(5) "trois" +} + +-- $sort argument is 1 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 2 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 3 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 4 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} + +-- $sort argument is 5 -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation5.phpt b/ext/standard/tests/array/array_change_key_case_variation5.phpt new file mode 100644 index 0000000..aa3852a --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation5.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_change_key_case() function : usage variations - position of internal pointer +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling the function + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_change_key_case() --\n"; +var_dump($result = array_change_key_case($input, CASE_UPPER)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Call array_change_key_case() -- +array(3) { + ["ONE"]=> + string(2) "un" + ["TWO"]=> + string(4) "deux" + ["THREE"]=> + string(5) "trois" +} +-- Position of Internal Pointer in Result: -- +ONE => un + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation6.phpt b/ext/standard/tests/array/array_change_key_case_variation6.phpt new file mode 100644 index 0000000..d4371d3 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation6.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_change_key_case() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Test how array_change_key_case() converts keys in multi-dimensional arrays + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array('English' => array('one' => 1, 'two' => 2, 'three' => 3), + 'French' => array('un' => 1, 'deux' => 2, 'trois' => 3), + 'German' => array('eins' => 1, 'zwei' => 2, 'drei' => 3)); + +echo "\n-- Pass a two-dimensional array as \$input argument --\n"; +var_dump(array_change_key_case($input, CASE_UPPER)); + +echo "\n-- Pass a sub-arry as \$input argument --\n"; +var_dump(array_change_key_case($input['English'], CASE_UPPER)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- Pass a two-dimensional array as $input argument -- +array(3) { + ["ENGLISH"]=> + array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + } + ["FRENCH"]=> + array(3) { + ["un"]=> + int(1) + ["deux"]=> + int(2) + ["trois"]=> + int(3) + } + ["GERMAN"]=> + array(3) { + ["eins"]=> + int(1) + ["zwei"]=> + int(2) + ["drei"]=> + int(3) + } +} + +-- Pass a sub-arry as $input argument -- +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["THREE"]=> + int(3) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_change_key_case_variation7.phpt b/ext/standard/tests/array/array_change_key_case_variation7.phpt new file mode 100644 index 0000000..8cbc23a --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation7.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_change_key_case() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Test array_change_key_case() when: + * 1. Passed a referenced variable + * 2. Passed an argument by reference + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$input = array('one' => 1, 'two' => 2, 'ABC' => 'xyz'); + +echo "\n-- \$input argument is a reference to array --\n"; +$new_input = &$input; +echo "Result:\n"; +var_dump(array_change_key_case($new_input, CASE_UPPER)); +echo "Original:\n"; +var_dump($input); +echo "Referenced:\n"; +var_dump($new_input); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- $input argument is a reference to array -- +Result: +array(3) { + ["ONE"]=> + int(1) + ["TWO"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Original: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Referenced: +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["ABC"]=> + string(3) "xyz" +} +Done + diff --git a/ext/standard/tests/array/array_change_key_case_variation8.phpt b/ext/standard/tests/array/array_change_key_case_variation8.phpt new file mode 100644 index 0000000..3614800 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation8.phpt @@ -0,0 +1,133 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Different strings as keys +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : array array_change_key_case(array $input [, int $case]) + * Description: Retuns an array with all string keys lowercased [or uppercased] + * Source code: ext/standard/array.c + */ + +/* + * Test how array_change_key_case() behaves with different strings + */ + +echo "*** Testing array_change_key_case() : usage variations ***\n"; + +$inputs = array ( + // group of escape sequences + array(null => 1, NULL => 2, "\a" => 3, "\cx" => 4, "\e" => 5, "\f" => 6, "\n" => 7, "\t" => 8, "\xhh" => 9, "\ddd" => 10, "\v" => 11), + + // array contains combination of capital/small letters + array("lemoN" => 1, "Orange" => 2, "banana" => 3, "apple" => 4, "Test" => 5, "TTTT" => 6, "ttt" => 7, "ww" => 8, "x" => 9, "X" => 10, "oraNGe" => 11, "BANANA" => 12) +); + +foreach($inputs as $input) { + echo "\n-- \$case = default --\n"; + var_dump(array_change_key_case($input)); + echo "-- \$case = upper --\n"; + var_dump(array_change_key_case($input, CASE_UPPER)); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_change_key_case() : usage variations *** + +-- $case = default -- +array(10) { + [""]=> + int(2) + ["\a"]=> + int(3) + ["\cx"]=> + int(4) + [""]=> + int(5) + [""]=> + int(6) + [" +"]=> + int(7) + [" "]=> + int(8) + ["\xhh"]=> + int(9) + ["\ddd"]=> + int(10) + [""]=> + int(11) +} +-- $case = upper -- +array(10) { + [""]=> + int(2) + ["\A"]=> + int(3) + ["\CX"]=> + int(4) + [""]=> + int(5) + [""]=> + int(6) + [" +"]=> + int(7) + [" "]=> + int(8) + ["\XHH"]=> + int(9) + ["\DDD"]=> + int(10) + [""]=> + int(11) +} + +-- $case = default -- +array(9) { + ["lemon"]=> + int(1) + ["orange"]=> + int(11) + ["banana"]=> + int(12) + ["apple"]=> + int(4) + ["test"]=> + int(5) + ["tttt"]=> + int(6) + ["ttt"]=> + int(7) + ["ww"]=> + int(8) + ["x"]=> + int(10) +} +-- $case = upper -- +array(9) { + ["LEMON"]=> + int(1) + ["ORANGE"]=> + int(11) + ["BANANA"]=> + int(12) + ["APPLE"]=> + int(4) + ["TEST"]=> + int(5) + ["TTTT"]=> + int(6) + ["TTT"]=> + int(7) + ["WW"]=> + int(8) + ["X"]=> + int(10) +} +Done diff --git a/ext/standard/tests/array/array_chunk.phpt b/ext/standard/tests/array/array_chunk.phpt new file mode 100644 index 0000000..2ee77e1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk.phpt @@ -0,0 +1,21 @@ +--TEST-- +array_chunk() +--FILE-- +<?php +$array = array (); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(0) { +} +[0] +NULL +NULL +NULL diff --git a/ext/standard/tests/array/array_chunk2.phpt b/ext/standard/tests/array/array_chunk2.phpt new file mode 100644 index 0000000..2560332 --- /dev/null +++ b/ext/standard/tests/array/array_chunk2.phpt @@ -0,0 +1,146 @@ +--TEST-- +basic array_chunk test +--FILE-- +<?php +$input_array = array('a', 'b', 'c', 'd', 'e'); +var_dump(array_chunk($input_array, 0)); +var_dump(array_chunk($input_array, 0, true)); +var_dump(array_chunk($input_array, 1)); +var_dump(array_chunk($input_array, 1, true)); +var_dump(array_chunk($input_array, 2)); +var_dump(array_chunk($input_array, 2, true)); +var_dump(array_chunk($input_array, 10)); +var_dump(array_chunk($input_array, 10, true)); +?> +--EXPECTF-- +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL +array(5) { + [0]=> + array(1) { + [0]=> + string(1) "a" + } + [1]=> + array(1) { + [0]=> + string(1) "b" + } + [2]=> + array(1) { + [0]=> + string(1) "c" + } + [3]=> + array(1) { + [0]=> + string(1) "d" + } + [4]=> + array(1) { + [0]=> + string(1) "e" + } +} +array(5) { + [0]=> + array(1) { + [0]=> + string(1) "a" + } + [1]=> + array(1) { + [1]=> + string(1) "b" + } + [2]=> + array(1) { + [2]=> + string(1) "c" + } + [3]=> + array(1) { + [3]=> + string(1) "d" + } + [4]=> + array(1) { + [4]=> + string(1) "e" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [1]=> + array(2) { + [0]=> + string(1) "c" + [1]=> + string(1) "d" + } + [2]=> + array(1) { + [0]=> + string(1) "e" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [1]=> + array(2) { + [2]=> + string(1) "c" + [3]=> + string(1) "d" + } + [2]=> + array(1) { + [4]=> + string(1) "e" + } +} +array(1) { + [0]=> + array(5) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + } +} +array(1) { + [0]=> + array(5) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + } +} diff --git a/ext/standard/tests/array/array_chunk_basic1.phpt b/ext/standard/tests/array/array_chunk_basic1.phpt new file mode 100644 index 0000000..56a90f4 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic1.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test array_chunk() function : basic functionality - defualt 'preserve_keys' +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : basic functionality ***\n"; +$size = 2; + +$input_arrays = array ( + // array with default keys - numeric values + array(1, 2, 3, 4, 5), + + // array with default keys - string values + array('value1', "value2", "value3"), + + // associative arrays - key as string + array('key1' => 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/witout keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) + +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + $count++; +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_basic2.phpt b/ext/standard/tests/array/array_chunk_basic2.phpt new file mode 100644 index 0000000..f96d863 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic2.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test array_chunk() function : basic functionality - 'preserve_keys' as true/false +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : basic functionality ***\n"; +$size = 2; + +$input_arrays = array( + // array with default keys - numeric values + array(1, 2, 3, 4, 5), + + // array with default keys - string values + array('value1', "value2", "value3"), + + // associative arrays - key as string + array('key1' => 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/without keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(1) { + [4]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [2]=> + string(6) "value3" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + ["key1"]=> + int(1) + ["key2"]=> + int(2) + } + [1]=> + array(1) { + ["key3"]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(1) { + [3]=> + string(5) "three" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(2) { + [3]=> + string(5) "three" + [4]=> + int(4) + } + [2]=> + array(1) { + ["five"]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_error.phpt b/ext/standard/tests/array/array_chunk_error.phpt new file mode 100644 index 0000000..5197945 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_chunk() function : error conditions +--FILE-- +<?php +/* Prototype : array array_chunk(array input, int size [, bool preserve_keys]) + * Description: Split array into chunks + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_chunk() function with zero arguments --\n"; +var_dump( array_chunk() ); + +echo "\n-- Testing array_chunk() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$size = 10; +$preserve_keys = true; +$extra_arg = 10; +var_dump( array_chunk($input,$size,$preserve_keys, $extra_arg) ); + +echo "\n-- Testing array_chunk() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +var_dump( array_chunk($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : error conditions *** + +-- Testing array_chunk() function with zero arguments -- + +Warning: array_chunk() expects at least 2 parameters, 0 given in %s on line %d +NULL + +-- Testing array_chunk() function with more than expected no. of arguments -- + +Warning: array_chunk() expects at most 3 parameters, 4 given in %s on line %d +NULL + +-- Testing array_chunk() function with less than expected no. of arguments -- + +Warning: array_chunk() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation1.phpt b/ext/standard/tests/array/array_chunk_variation1.phpt new file mode 100644 index 0000000..caaf274 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation1.phpt @@ -0,0 +1,325 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : proto array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'array' argument +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// Initialise function arguments +$size = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new stdclass(), + + // undefined data +/*21*/ @undefined_var, + + // unset data +/*22*/ @unset_var + +); + +$count = 1; +// loop through each element of the array for input +foreach($values as $value){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($value, $size) ); + var_dump( array_chunk($value, $size, true) ); + var_dump( array_chunk($value, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation10.phpt b/ext/standard/tests/array/array_chunk_variation10.phpt new file mode 100644 index 0000000..7b4bee1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation10.phpt @@ -0,0 +1,159 @@ +--TEST-- +array_chunk() - variation 10 +--FILE-- +<?php +$array = array (1 => 1, 2 => 2, 3 => 3); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +[0] +NULL +NULL +NULL + +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [1]=> + int(1) + } + [1]=> + array(1) { + [2]=> + int(2) + } + [2]=> + array(1) { + [3]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [3]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation11.phpt b/ext/standard/tests/array/array_chunk_variation11.phpt new file mode 100644 index 0000000..dca3666 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation11.phpt @@ -0,0 +1,93 @@ +--TEST-- +array_chunk() - variation 11 +--FILE-- +<?php +$array = array (0 => 0, 3 => 2); + +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + [0]=> + int(0) + [3]=> + int(2) +} +[0] +NULL +NULL +NULL + +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [3]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [3]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation12.phpt b/ext/standard/tests/array/array_chunk_variation12.phpt new file mode 100644 index 0000000..3b87dba --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation12.phpt @@ -0,0 +1,159 @@ +--TEST-- +array_chunk() - variation 12 +--FILE-- +<?php +$array = array (1 => 1, 5 => 2, 8 => 3); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [1]=> + int(1) + [5]=> + int(2) + [8]=> + int(3) +} +[0] +NULL +NULL +NULL + +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [1]=> + int(1) + } + [1]=> + array(1) { + [5]=> + int(2) + } + [2]=> + array(1) { + [8]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [1]=> + int(1) + [5]=> + int(2) + } + [1]=> + array(1) { + [8]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [1]=> + int(1) + [5]=> + int(2) + [8]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation13.phpt b/ext/standard/tests/array/array_chunk_variation13.phpt new file mode 100644 index 0000000..f6369df --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation13.phpt @@ -0,0 +1,92 @@ +--TEST-- +array_chunk() - variation 13 +--FILE-- +<?php +$array = array (1, 2); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +[0] +NULL +NULL +NULL + +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation14.phpt b/ext/standard/tests/array/array_chunk_variation14.phpt new file mode 100644 index 0000000..f8d1b11 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation14.phpt @@ -0,0 +1,159 @@ +--TEST-- +array_chunk() - variation 14 +--FILE-- +<?php +$array = array (0, 1, 2); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +[0] +NULL +NULL +NULL + +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(1) { + [2]=> + int(2) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation15.phpt b/ext/standard/tests/array/array_chunk_variation15.phpt new file mode 100644 index 0000000..abec754 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation15.phpt @@ -0,0 +1,159 @@ +--TEST-- +array_chunk() - variation 15 +--FILE-- +<?php +$array = array (1, 2, 3); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +[0] +NULL +NULL +NULL + +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [2]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation16.phpt b/ext/standard/tests/array/array_chunk_variation16.phpt new file mode 100644 index 0000000..18179c8 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation16.phpt @@ -0,0 +1,238 @@ +--TEST-- +array_chunk() - variation 16 +--FILE-- +<?php +$array = array (0, 1, 2, 3); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +[0] +NULL +NULL +NULL + +[1] +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } + [3]=> + array(1) { + [3]=> + int(3) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [2]=> + int(2) + [3]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [3]=> + int(3) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[4] +array(1) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation17.phpt b/ext/standard/tests/array/array_chunk_variation17.phpt new file mode 100644 index 0000000..27507ea --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation17.phpt @@ -0,0 +1,238 @@ +--TEST-- +array_chunk() - variation 17 +--FILE-- +<?php +$array = array (1, 2, 3, 4); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +} +[0] +NULL +NULL +NULL + +[1] +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } + [3]=> + array(1) { + [3]=> + int(4) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(1) { + [3]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} + +[4] +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation18.phpt b/ext/standard/tests/array/array_chunk_variation18.phpt new file mode 100644 index 0000000..7f0946f --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation18.phpt @@ -0,0 +1,338 @@ +--TEST-- +array_chunk() - variation 18 +--FILE-- +<?php +$array = array (0, 1, 2, 3, 4); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) +} +[0] +NULL +NULL +NULL + +[1] +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } +} +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } + [3]=> + array(1) { + [3]=> + int(3) + } + [4]=> + array(1) { + [4]=> + int(4) + } +} +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } +} + +[2] +array(3) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(1) { + [0]=> + int(4) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [2]=> + int(2) + [3]=> + int(3) + } + [2]=> + array(1) { + [4]=> + int(4) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(1) { + [0]=> + int(4) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(2) { + [3]=> + int(3) + [4]=> + int(4) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} + +[4] +array(2) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} +array(2) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(1) { + [4]=> + int(4) + } +} +array(2) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(1) { + [0]=> + int(4) + } +} + +[5] +array(1) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } +} +array(1) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } +} +array(1) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation19.phpt b/ext/standard/tests/array/array_chunk_variation19.phpt new file mode 100644 index 0000000..d51389c --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation19.phpt @@ -0,0 +1,1018 @@ +--TEST-- +array_chunk() - variation 19 +--FILE-- +<?php +$array = array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} +[0] +NULL +NULL +NULL + +[1] +array(10) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } + [6]=> + array(1) { + [0]=> + int(7) + } + [7]=> + array(1) { + [0]=> + int(8) + } + [8]=> + array(1) { + [0]=> + int(9) + } + [9]=> + array(1) { + [0]=> + int(10) + } +} +array(10) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } + [3]=> + array(1) { + [3]=> + int(4) + } + [4]=> + array(1) { + [4]=> + int(5) + } + [5]=> + array(1) { + [5]=> + int(6) + } + [6]=> + array(1) { + [6]=> + int(7) + } + [7]=> + array(1) { + [7]=> + int(8) + } + [8]=> + array(1) { + [8]=> + int(9) + } + [9]=> + array(1) { + [9]=> + int(10) + } +} +array(10) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } + [6]=> + array(1) { + [0]=> + int(7) + } + [7]=> + array(1) { + [0]=> + int(8) + } + [8]=> + array(1) { + [0]=> + int(9) + } + [9]=> + array(1) { + [0]=> + int(10) + } +} + +[2] +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } + [3]=> + array(2) { + [0]=> + int(7) + [1]=> + int(8) + } + [4]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(2) { + [4]=> + int(5) + [5]=> + int(6) + } + [3]=> + array(2) { + [6]=> + int(7) + [7]=> + int(8) + } + [4]=> + array(2) { + [8]=> + int(9) + [9]=> + int(10) + } +} +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } + [3]=> + array(2) { + [0]=> + int(7) + [1]=> + int(8) + } + [4]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[3] +array(4) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } + [2]=> + array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + } + [3]=> + array(1) { + [0]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [2]=> + array(3) { + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [3]=> + array(1) { + [9]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } + [2]=> + array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + } + [3]=> + array(1) { + [0]=> + int(10) + } +} + +[4] +array(3) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + } + [2]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [2]=> + array(2) { + [8]=> + int(9) + [9]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + } + [2]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[5] +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(5) { + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} + +[6] +array(2) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(4) { + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} + +[7] +array(2) { + [0]=> + array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + } + [1]=> + array(3) { + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} + +[8] +array(2) { + [0]=> + array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [1]=> + array(2) { + [8]=> + int(9) + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[9] +array(2) { + [0]=> + array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [1]=> + array(1) { + [9]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} + +[10] +array(1) { + [0]=> + array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(1) { + [0]=> + array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} +array(1) { + [0]=> + array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation2.phpt b/ext/standard/tests/array/array_chunk_variation2.phpt new file mode 100644 index 0000000..8cfe994 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation2.phpt @@ -0,0 +1,427 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'size' argument +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'size' argument +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array ( + + // float data +/*1*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array data +/*6*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*11*/ NULL, + null, + + // boolean data +/*13*/ true, + false, + TRUE, + FALSE, + + // empty data +/*17*/ "", + '', + + // string data +/*19*/ "string", + 'string', + + // object data +/*21*/ new stdclass(), + + // undefined data +/*22*/ @undefined_var, + + // unset data +/*23*/ @unset_var + +); + +// loop through each element of the array for size +$count = 1; +foreach($values as $value){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input, $value) ); + var_dump( array_chunk($input, $value, true) ); + var_dump( array_chunk($input, $value, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 2 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 3 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 4 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 13 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +-- Iteration 14 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 15 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +-- Iteration 16 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation20.phpt b/ext/standard/tests/array/array_chunk_variation20.phpt new file mode 100644 index 0000000..cd5314f --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation20.phpt @@ -0,0 +1,1199 @@ +--TEST-- +array_chunk() - variation 20 +--FILE-- +<?php +$array = array (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) +} +[0] +NULL +NULL +NULL + +[1] +array(11) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } + [5]=> + array(1) { + [0]=> + int(5) + } + [6]=> + array(1) { + [0]=> + int(6) + } + [7]=> + array(1) { + [0]=> + int(7) + } + [8]=> + array(1) { + [0]=> + int(8) + } + [9]=> + array(1) { + [0]=> + int(9) + } + [10]=> + array(1) { + [0]=> + int(10) + } +} +array(11) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(1) + } + [2]=> + array(1) { + [2]=> + int(2) + } + [3]=> + array(1) { + [3]=> + int(3) + } + [4]=> + array(1) { + [4]=> + int(4) + } + [5]=> + array(1) { + [5]=> + int(5) + } + [6]=> + array(1) { + [6]=> + int(6) + } + [7]=> + array(1) { + [7]=> + int(7) + } + [8]=> + array(1) { + [8]=> + int(8) + } + [9]=> + array(1) { + [9]=> + int(9) + } + [10]=> + array(1) { + [10]=> + int(10) + } +} +array(11) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + array(1) { + [0]=> + int(2) + } + [3]=> + array(1) { + [0]=> + int(3) + } + [4]=> + array(1) { + [0]=> + int(4) + } + [5]=> + array(1) { + [0]=> + int(5) + } + [6]=> + array(1) { + [0]=> + int(6) + } + [7]=> + array(1) { + [0]=> + int(7) + } + [8]=> + array(1) { + [0]=> + int(8) + } + [9]=> + array(1) { + [0]=> + int(9) + } + [10]=> + array(1) { + [0]=> + int(10) + } +} + +[2] +array(6) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(2) { + [0]=> + int(4) + [1]=> + int(5) + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [4]=> + array(2) { + [0]=> + int(8) + [1]=> + int(9) + } + [5]=> + array(1) { + [0]=> + int(10) + } +} +array(6) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [2]=> + int(2) + [3]=> + int(3) + } + [2]=> + array(2) { + [4]=> + int(4) + [5]=> + int(5) + } + [3]=> + array(2) { + [6]=> + int(6) + [7]=> + int(7) + } + [4]=> + array(2) { + [8]=> + int(8) + [9]=> + int(9) + } + [5]=> + array(1) { + [10]=> + int(10) + } +} +array(6) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } + [2]=> + array(2) { + [0]=> + int(4) + [1]=> + int(5) + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [4]=> + array(2) { + [0]=> + int(8) + [1]=> + int(9) + } + [5]=> + array(1) { + [0]=> + int(10) + } +} + +[3] +array(4) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(3) { + [0]=> + int(3) + [1]=> + int(4) + [2]=> + int(5) + } + [2]=> + array(3) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + } + [3]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(3) { + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [2]=> + array(3) { + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [3]=> + array(2) { + [9]=> + int(9) + [10]=> + int(10) + } +} +array(4) { + [0]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + [1]=> + array(3) { + [0]=> + int(3) + [1]=> + int(4) + [2]=> + int(5) + } + [2]=> + array(3) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + } + [3]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[4] +array(3) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(4) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + [3]=> + int(7) + } + [2]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(4) { + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [2]=> + array(3) { + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(3) { + [0]=> + array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + } + [1]=> + array(4) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + [3]=> + int(7) + } + [2]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} + +[5] +array(3) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + [4]=> + int(9) + } + [2]=> + array(1) { + [0]=> + int(10) + } +} +array(3) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } + [1]=> + array(5) { + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [2]=> + array(1) { + [10]=> + int(10) + } +} +array(3) { + [0]=> + array(5) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(7) + [3]=> + int(8) + [4]=> + int(9) + } + [2]=> + array(1) { + [0]=> + int(10) + } +} + +[6] +array(2) { + [0]=> + array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [1]=> + array(5) { + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + } + [1]=> + array(5) { + [0]=> + int(6) + [1]=> + int(7) + [2]=> + int(8) + [3]=> + int(9) + [4]=> + int(10) + } +} + +[7] +array(2) { + [0]=> + array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + } + [1]=> + array(4) { + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + } + [1]=> + array(4) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) + [3]=> + int(10) + } +} + +[8] +array(2) { + [0]=> + array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [1]=> + array(3) { + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(8) + [1]=> + int(9) + [2]=> + int(10) + } +} + +[9] +array(2) { + [0]=> + array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [1]=> + array(2) { + [9]=> + int(9) + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + } + [1]=> + array(2) { + [0]=> + int(9) + [1]=> + int(10) + } +} + +[10] +array(2) { + [0]=> + array(10) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} +array(2) { + [0]=> + array(10) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [1]=> + array(1) { + [10]=> + int(10) + } +} +array(2) { + [0]=> + array(10) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + } + [1]=> + array(1) { + [0]=> + int(10) + } +} + +[11] +array(1) { + [0]=> + array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(1) { + [0]=> + array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} +array(1) { + [0]=> + array(11) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) + [7]=> + int(7) + [8]=> + int(8) + [9]=> + int(9) + [10]=> + int(10) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation21.phpt b/ext/standard/tests/array/array_chunk_variation21.phpt new file mode 100644 index 0000000..678bf16 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation21.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 21 +--FILE-- +<?php +$array = array ("a" => 1); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + ["a"]=> + int(1) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + ["a"]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation22.phpt b/ext/standard/tests/array/array_chunk_variation22.phpt new file mode 100644 index 0000000..45c458e --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation22.phpt @@ -0,0 +1,92 @@ +--TEST-- +array_chunk() - variation 22 +--FILE-- +<?php +$array = array ("b" => 1, "c" => 2); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +[0] +NULL +NULL +NULL + +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + ["b"]=> + int(1) + } + [1]=> + array(1) { + ["c"]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation23.phpt b/ext/standard/tests/array/array_chunk_variation23.phpt new file mode 100644 index 0000000..80b9298 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation23.phpt @@ -0,0 +1,441 @@ +--TEST-- +array_chunk() - variation 23 +--FILE-- +<?php +$array = array ("p" => 1, "q" => 2, "r" => 3, "s" => 4, "u" => 5, "v" => 6); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(6) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + ["u"]=> + int(5) + ["v"]=> + int(6) +} +[0] +NULL +NULL +NULL + +[1] +array(6) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } +} +array(6) { + [0]=> + array(1) { + ["p"]=> + int(1) + } + [1]=> + array(1) { + ["q"]=> + int(2) + } + [2]=> + array(1) { + ["r"]=> + int(3) + } + [3]=> + array(1) { + ["s"]=> + int(4) + } + [4]=> + array(1) { + ["u"]=> + int(5) + } + [5]=> + array(1) { + ["v"]=> + int(6) + } +} +array(6) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } + [3]=> + array(1) { + [0]=> + int(4) + } + [4]=> + array(1) { + [0]=> + int(5) + } + [5]=> + array(1) { + [0]=> + int(6) + } +} + +[2] +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} +array(3) { + [0]=> + array(2) { + ["p"]=> + int(1) + ["q"]=> + int(2) + } + [1]=> + array(2) { + ["r"]=> + int(3) + ["s"]=> + int(4) + } + [2]=> + array(2) { + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } +} +array(2) { + [0]=> + array(3) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + } + [1]=> + array(3) { + ["s"]=> + int(4) + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) + } +} + +[4] +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} +array(2) { + [0]=> + array(4) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + } + [1]=> + array(2) { + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(2) { + [0]=> + int(5) + [1]=> + int(6) + } +} + +[5] +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(1) { + [0]=> + int(6) + } +} +array(2) { + [0]=> + array(5) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + ["u"]=> + int(5) + } + [1]=> + array(1) { + ["v"]=> + int(6) + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [1]=> + array(1) { + [0]=> + int(6) + } +} + +[6] +array(1) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} +array(1) { + [0]=> + array(6) { + ["p"]=> + int(1) + ["q"]=> + int(2) + ["r"]=> + int(3) + ["s"]=> + int(4) + ["u"]=> + int(5) + ["v"]=> + int(6) + } +} +array(1) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation24.phpt b/ext/standard/tests/array/array_chunk_variation24.phpt new file mode 100644 index 0000000..e25f53f --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation24.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 24 +--FILE-- +<?php +$array = array ("a" => "A"); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + ["a"]=> + string(1) "A" +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } +} +array(1) { + [0]=> + array(1) { + ["a"]=> + string(1) "A" + } +} +array(1) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } +} diff --git a/ext/standard/tests/array/array_chunk_variation25.phpt b/ext/standard/tests/array/array_chunk_variation25.phpt new file mode 100644 index 0000000..eae89e9 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation25.phpt @@ -0,0 +1,441 @@ +--TEST-- +array_chunk() - variation 25 +--FILE-- +<?php +$array = array ("p" => "A", "q" => "B", "r" => "C", "s" => "D", "u" => "E", "v" => "F"); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(6) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" +} +[0] +NULL +NULL +NULL + +[1] +array(6) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } + [1]=> + array(1) { + [0]=> + string(1) "B" + } + [2]=> + array(1) { + [0]=> + string(1) "C" + } + [3]=> + array(1) { + [0]=> + string(1) "D" + } + [4]=> + array(1) { + [0]=> + string(1) "E" + } + [5]=> + array(1) { + [0]=> + string(1) "F" + } +} +array(6) { + [0]=> + array(1) { + ["p"]=> + string(1) "A" + } + [1]=> + array(1) { + ["q"]=> + string(1) "B" + } + [2]=> + array(1) { + ["r"]=> + string(1) "C" + } + [3]=> + array(1) { + ["s"]=> + string(1) "D" + } + [4]=> + array(1) { + ["u"]=> + string(1) "E" + } + [5]=> + array(1) { + ["v"]=> + string(1) "F" + } +} +array(6) { + [0]=> + array(1) { + [0]=> + string(1) "A" + } + [1]=> + array(1) { + [0]=> + string(1) "B" + } + [2]=> + array(1) { + [0]=> + string(1) "C" + } + [3]=> + array(1) { + [0]=> + string(1) "D" + } + [4]=> + array(1) { + [0]=> + string(1) "E" + } + [5]=> + array(1) { + [0]=> + string(1) "F" + } +} + +[2] +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } + [1]=> + array(2) { + [0]=> + string(1) "C" + [1]=> + string(1) "D" + } + [2]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} +array(3) { + [0]=> + array(2) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + } + [1]=> + array(2) { + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + } + [2]=> + array(2) { + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + } + [1]=> + array(2) { + [0]=> + string(1) "C" + [1]=> + string(1) "D" + } + [2]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} + +[3] +array(2) { + [0]=> + array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + } + [1]=> + array(3) { + [0]=> + string(1) "D" + [1]=> + string(1) "E" + [2]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(3) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + } + [1]=> + array(3) { + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + } + [1]=> + array(3) { + [0]=> + string(1) "D" + [1]=> + string(1) "E" + [2]=> + string(1) "F" + } +} + +[4] +array(2) { + [0]=> + array(4) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + } + [1]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(4) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + } + [1]=> + array(2) { + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(4) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + } + [1]=> + array(2) { + [0]=> + string(1) "E" + [1]=> + string(1) "F" + } +} + +[5] +array(2) { + [0]=> + array(5) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + } + [1]=> + array(1) { + [0]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(5) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + } + [1]=> + array(1) { + ["v"]=> + string(1) "F" + } +} +array(2) { + [0]=> + array(5) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + } + [1]=> + array(1) { + [0]=> + string(1) "F" + } +} + +[6] +array(1) { + [0]=> + array(6) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + [5]=> + string(1) "F" + } +} +array(1) { + [0]=> + array(6) { + ["p"]=> + string(1) "A" + ["q"]=> + string(1) "B" + ["r"]=> + string(1) "C" + ["s"]=> + string(1) "D" + ["u"]=> + string(1) "E" + ["v"]=> + string(1) "F" + } +} +array(1) { + [0]=> + array(6) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + string(1) "D" + [4]=> + string(1) "E" + [5]=> + string(1) "F" + } +} diff --git a/ext/standard/tests/array/array_chunk_variation26.phpt b/ext/standard/tests/array/array_chunk_variation26.phpt new file mode 100644 index 0000000..487f6b4 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation26.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 26 +--FILE-- +<?php +$array =array (0); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [0]=> + int(0) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation27.phpt b/ext/standard/tests/array/array_chunk_variation27.phpt new file mode 100644 index 0000000..a83a16b --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation27.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 27 +--FILE-- +<?php +$array = array (1); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [0]=> + int(1) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation28.phpt b/ext/standard/tests/array/array_chunk_variation28.phpt new file mode 100644 index 0000000..bdbaf45 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation28.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 28 +--FILE-- +<?php +$array = array (-1); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [0]=> + int(-1) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation29.phpt b/ext/standard/tests/array/array_chunk_variation29.phpt new file mode 100644 index 0000000..12f50c1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation29.phpt @@ -0,0 +1,92 @@ +--TEST-- +array_chunk() - variation 29 +--FILE-- +<?php +$array = array (0, 2); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + [0]=> + int(0) + [1]=> + int(2) +} +[0] +NULL +NULL +NULL + +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation3.phpt b/ext/standard/tests/array/array_chunk_variation3.phpt new file mode 100644 index 0000000..452006a --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation3.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'preserve_keys' +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'preserve_keys' +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input = array(1, 2); +$size = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // empty data +/*12*/ "", + '', + + // string data +/*14*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var + +); + +$count = 1; + +// loop through each element of the array for preserve_keys +foreach($values as $value) { + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input, $size, $value) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 3 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 4 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 5 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 6 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 7 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 8 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 9 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 10 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 11 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 12 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 13 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 14 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 15 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 16 -- + +Warning: array_chunk() expects parameter 3 to be boolean, object given in %s on line %d +NULL + +-- Iteration 17 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 18 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation30.phpt b/ext/standard/tests/array/array_chunk_variation30.phpt new file mode 100644 index 0000000..281537a --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation30.phpt @@ -0,0 +1,159 @@ +--TEST-- +array_chunk() - variation 30 +--FILE-- +<?php +$array = array (1, 2, 3); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +[0] +NULL +NULL +NULL + +[1] +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} + +[2] +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [2]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +[3] +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation31.phpt b/ext/standard/tests/array/array_chunk_variation31.phpt new file mode 100644 index 0000000..1592679 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation31.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 31 +--FILE-- +<?php +$array = array (1 => 0); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [1]=> + int(0) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [1]=> + int(0) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(0) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation32.phpt b/ext/standard/tests/array/array_chunk_variation32.phpt new file mode 100644 index 0000000..cf65993 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation32.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 32 +--FILE-- +<?php +$array = array (2 => 1); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [2]=> + int(1) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [2]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation4.phpt b/ext/standard/tests/array/array_chunk_variation4.phpt new file mode 100644 index 0000000..7f04f51 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation4.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_chunk() function : usage variations - array with diff. sub arrays +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function - input array containing different sub arrays +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +$size = 2; + +// input array +$input_array = array ( + "array1" => array(), + "array2" => array(1, 2, 3), + "array3" => array(1) +); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt --\n"; +var_dump( array_chunk($input_array, $size) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true --\n"; +var_dump( array_chunk($input_array, $size, true) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false --\n"; +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true -- +array(2) { + [0]=> + array(2) { + ["array1"]=> + array(0) { + } + ["array2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + ["array3"]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation5.phpt b/ext/standard/tests/array/array_chunk_variation5.phpt new file mode 100644 index 0000000..8d36092 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation5.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test array_chunk() function : usage variations - different 'size' values +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. -ve size value + * 2. size value is more than the no. of elements in the input array + * 3. size value is zero + * 4. Decimal size value +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input_array = array(1, 2, 3); + +// different magnitude's +$sizes = array(-1, count($input_array) + 1, 0, 1.5); + +// loop through the array for size argument +foreach ($sizes as $size){ + echo "\n-- Testing array_chunk() when size = $size --\n"; + var_dump( array_chunk($input_array, $size) ); + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); +} +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() when size = -1 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Testing array_chunk() when size = 4 -- +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Testing array_chunk() when size = 0 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Testing array_chunk() when size = 1.5 -- +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation6.phpt b/ext/standard/tests/array/array_chunk_variation6.phpt new file mode 100644 index 0000000..f44eb39 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation6.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test array_chunk() function : usage variations - different arrays +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. array without elements + * 2. associative array with duplicate keys + * 3. array with one element +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input_arrays = array ( + + // array without elements + "array1" => array(), + + // array with one element + "array2" => array(1), + + // associative array with duplicate keys + "array3" => array("a" => 1, "b" => 2, "c" => 3, "a" => 4, "d" => 5) + +); + +$size = 2; +$count = 1; + +echo "\n-- Testing array_chunk() by supplying various arrays --\n"; + +// loop through the array for 'array' argument +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying various arrays -- + +-- Iteration 1 -- +array(0) { +} +array(0) { +} +array(0) { +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + ["a"]=> + int(4) + ["b"]=> + int(2) + } + [1]=> + array(2) { + ["c"]=> + int(3) + ["d"]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation7.phpt b/ext/standard/tests/array/array_chunk_variation7.phpt new file mode 100644 index 0000000..c8a7196 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation7.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test array_chunk() function : usage variations - references +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. input array containing references +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +$size = 2; + +echo "\n-- Testing array_chunk(), input array containing references \n"; + +$numbers=array(1, 2, 3, 4); +// reference array +$input_array = array ( + "one" => &$numbers[0], + "two" => &$numbers[1], + "three" => &$numbers[2], + "four" => &$numbers[3] +); + +var_dump( array_chunk($input_array, $size) ); +var_dump( array_chunk($input_array, $size, true) ); +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk(), input array containing references +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + ["one"]=> + &int(1) + ["two"]=> + &int(2) + } + [1]=> + array(2) { + ["three"]=> + &int(3) + ["four"]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation8.phpt b/ext/standard/tests/array/array_chunk_variation8.phpt new file mode 100644 index 0000000..6a6e752 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation8.phpt @@ -0,0 +1,46 @@ +--TEST-- +array_chunk() - variation 8 +--FILE-- +<?php +$array = array (3 => -1); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(1) { + [3]=> + int(-1) +} +[0] +NULL +NULL +NULL + +[1] +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [3]=> + int(-1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(-1) + } +} diff --git a/ext/standard/tests/array/array_chunk_variation9.phpt b/ext/standard/tests/array/array_chunk_variation9.phpt new file mode 100644 index 0000000..ec57da4 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation9.phpt @@ -0,0 +1,92 @@ +--TEST-- +array_chunk() - variation 9 +--FILE-- +<?php +$array = array (1 => 0, 2 => 2); +var_dump ($array); +for ($i = 0; $i < (sizeof($array) + 1); $i++) { + echo "[$i]\n"; + var_dump (@array_chunk ($array, $i)); + var_dump (@array_chunk ($array, $i, TRUE)); + var_dump (@array_chunk ($array, $i, FALSE)); + echo "\n"; +} +?> +--EXPECT-- +array(2) { + [1]=> + int(0) + [2]=> + int(2) +} +[0] +NULL +NULL +NULL + +[1] +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [1]=> + int(0) + } + [1]=> + array(1) { + [2]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +[2] +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [1]=> + int(0) + [2]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(2) + } +} diff --git a/ext/standard/tests/array/array_combine.phpt b/ext/standard/tests/array/array_combine.phpt new file mode 100644 index 0000000..34d4ff8 --- /dev/null +++ b/ext/standard/tests/array/array_combine.phpt @@ -0,0 +1,122 @@ +--TEST-- +basic array_combine test +--FILE-- +<?php + $array1 = array('green', 'red', 'yellow'); + $array2 = array('1', '2', '3'); + $array3 = array(0, 1, 2); + $array4 = array(TRUE, FALSE, NULL); + $a = array_combine($array1, $array1); + $b = array_combine($array1, $array2); + $c = array_combine($array1, $array3); + $d = array_combine($array1, $array4); + $e = array_combine($array2, $array1); + $f = array_combine($array2, $array2); + $g = array_combine($array2, $array3); + $h = array_combine($array2, $array4); + $i = array_combine($array3, $array1); + $j = array_combine($array3, $array2); + $k = array_combine($array3, $array3); + $l = array_combine($array3, $array4); + $m = array_combine($array4, $array1); + $n = array_combine($array4, $array2); + $o = array_combine($array4, $array3); + $p = array_combine($array4, $array4); + for($letter = "a"; $letter <= "p"; $letter++) + { + print_r($$letter); + } +?> +--EXPECT-- +Array +( + [green] => green + [red] => red + [yellow] => yellow +) +Array +( + [green] => 1 + [red] => 2 + [yellow] => 3 +) +Array +( + [green] => 0 + [red] => 1 + [yellow] => 2 +) +Array +( + [green] => 1 + [red] => + [yellow] => +) +Array +( + [1] => green + [2] => red + [3] => yellow +) +Array +( + [1] => 1 + [2] => 2 + [3] => 3 +) +Array +( + [1] => 0 + [2] => 1 + [3] => 2 +) +Array +( + [1] => 1 + [2] => + [3] => +) +Array +( + [0] => green + [1] => red + [2] => yellow +) +Array +( + [0] => 1 + [1] => 2 + [2] => 3 +) +Array +( + [0] => 0 + [1] => 1 + [2] => 2 +) +Array +( + [0] => 1 + [1] => + [2] => +) +Array +( + [1] => green + [] => yellow +) +Array +( + [1] => 1 + [] => 3 +) +Array +( + [1] => 0 + [] => 2 +) +Array +( + [1] => 1 + [] => +)
\ No newline at end of file diff --git a/ext/standard/tests/array/array_combine_basic.phpt b/ext/standard/tests/array/array_combine_basic.phpt new file mode 100644 index 0000000..5d855cf --- /dev/null +++ b/ext/standard/tests/array/array_combine_basic.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_combine() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_combine() : basic functionality ***\n"; + +/* Different arrays for $keys and $values arguments */ + +// array with default keys for $keys and $values arguments +$keys_array = array(1, 2); +$values_array = array(3,4); +var_dump( array_combine($keys_array, $values_array) ); + +// associative arrays for $keys and $values arguments +$keys_array = array(1 => "a", 2 => 'b'); +$values_array = array(3 => 'c', 4 => "d"); +var_dump( array_combine($keys_array, $values_array) ); + +// mixed array for $keys and $values arguments +$keys_array = array(1, 2 => "b"); +$values_array = array(3 => 'c', 4); +var_dump( array_combine($keys_array, $values_array) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : basic functionality *** +array(2) { + [1]=> + int(3) + [2]=> + int(4) +} +array(2) { + ["a"]=> + string(1) "c" + ["b"]=> + string(1) "d" +} +array(2) { + [1]=> + string(1) "c" + ["b"]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/array_combine_error1.phpt b/ext/standard/tests/array/array_combine_error1.phpt new file mode 100644 index 0000000..aa5a1af --- /dev/null +++ b/ext/standard/tests/array/array_combine_error1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_combine() function : error conditions +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_combine() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_combine() function with Zero arguments --\n"; +var_dump( array_combine() ); + +//Test array_combine with one more than the expected number of arguments +echo "\n-- Testing array_combine() function with more than expected no. of arguments --\n"; +$keys = array(1, 2); +$values = array(1, 2); +$extra_arg = 10; +var_dump( array_combine($keys,$values, $extra_arg) ); + +// Testing array_combine with one less than the expected number of arguments +echo "\n-- Testing array_combine() function with less than expected no. of arguments --\n"; +$keys = array(1, 2); +var_dump( array_combine($keys) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : error conditions *** + +-- Testing array_combine() function with Zero arguments -- + +Warning: array_combine() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +-- Testing array_combine() function with more than expected no. of arguments -- + +Warning: array_combine() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +-- Testing array_combine() function with less than expected no. of arguments -- + +Warning: array_combine() expects exactly 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_combine_error2.phpt b/ext/standard/tests/array/array_combine_error2.phpt new file mode 100644 index 0000000..4224f1c --- /dev/null +++ b/ext/standard/tests/array/array_combine_error2.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_combine() function : error conditions - empty array +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_combine() : error conditions specific to array_combine() ***\n"; + +// Testing array_combine by passing empty arrays to $keys and $values arguments +echo "\n-- Testing array_combine() function with empty arrays --\n"; +var_dump( array_combine(array(), array()) ); + +// Testing array_combine by passing empty array to $keys +echo "\n-- Testing array_combine() function with empty array for \$keys argument --\n"; +var_dump( array_combine(array(), array(1, 2)) ); + +// Testing array_combine by passing empty array to $values +echo "\n-- Testing array_combine() function with empty array for \$values argument --\n"; +var_dump( array_combine(array(1, 2), array()) ); + +// Testing array_combine with arrays having unequal number of elements +echo "\n-- Testing array_combine() function by passing array with unequal number of elements --\n"; +var_dump( array_combine(array(1, 2), array(1, 2, 3)) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : error conditions specific to array_combine() *** + +-- Testing array_combine() function with empty arrays -- +array(0) { +} + +-- Testing array_combine() function with empty array for $keys argument -- + +Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d +bool(false) + +-- Testing array_combine() function with empty array for $values argument -- + +Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d +bool(false) + +-- Testing array_combine() function by passing array with unequal number of elements -- + +Warning: array_combine(): Both parameters should have an equal number of elements in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_combine_variation1.phpt b/ext/standard/tests/array/array_combine_variation1.phpt new file mode 100644 index 0000000..c69d4eb --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation1.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test array_combine() function : usage variations - unexpected values for 'keys' argument +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_combine() function by passing values to $keys argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $values argument passed is a fixed array. +*/ + +echo "*** Testing array_combine() : Passing non-array values to \$keys argument ***\n"; + +// Initialise $values argument +$values = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $keys argument +$keys_passed = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element within $keys_passed to check the behavior of array_combine() +$iterator = 1; +foreach($keys_passed as $keys) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($keys,$values) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : Passing non-array values to $keys argument *** +-- Iteration 1 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_combine() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_combine() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_combine() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_combine() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_combine() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_combine() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_combine() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_combine_variation2.phpt b/ext/standard/tests/array/array_combine_variation2.phpt new file mode 100644 index 0000000..e58893b --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation2.phpt @@ -0,0 +1,198 @@ +--TEST-- +Test array_combine() function : usage variations - unexpected values for 'values' argument +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_combine() function by passing values to $values argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $keys argument passed is a fixed array. +*/ + +echo "*** Testing array_combine() : Passing non-array values to \$values argument ***\n"; + +// Initialize $keys array +$keys = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $values argument +$values_passed = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element within $values_passed to check the behavior of array_combine() +$iterator = 1; +foreach($values_passed as $values) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($keys,$values) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : Passing non-array values to $values argument *** +-- Iteration 1 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_combine() expects parameter 2 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_combine() expects parameter 2 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_combine() expects parameter 2 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_combine() expects parameter 2 to be array, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_combine() expects parameter 2 to be array, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_combine() expects parameter 2 to be array, null given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_combine() expects parameter 2 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_combine_variation3.phpt b/ext/standard/tests/array/array_combine_variation3.phpt new file mode 100644 index 0000000..03de632 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation3.phpt @@ -0,0 +1,278 @@ +--TEST-- +Test array_combine() function : usage variations - different arrays(Bug#43424) +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of arrays to both $keys and $values arguments and testing whether +* array_combine() behaves in an expected way with the arguments passed to the function +*/ + +echo "*** Testing array_combine() : Passing different types of arrays to both \$keys and \$values argument ***\n"; +/* Different heredoc strings passed as argument to arrays */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $keys argument +$arrays = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrays to check the behavior of array_combine() +// same arrays are passed to both $keys and $values +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : Passing different types of arrays to both $keys and $values argument *** +-- Iteration 1 -- +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +-- Iteration 2 -- +array(2) { + ["1.1"]=> + float(1.1) + ["2.2"]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(1) { + [""]=> + NULL +} +-- Iteration 6 -- +array(6) { + ["a"]=> + string(3) "a" + ["aaaa
"]=> + string(5) "aaaa
" + ["b"]=> + string(1) "b" + ["b bbb"]=> + string(5) "b bbb" + ["c"]=> + string(1) "c" + ["\[\]\!\@\#$\%\^\&\*\(\)\{\}"]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + ["a\v\f"]=> + string(5) "a\v\f" + ["aaaa\r"]=> + string(6) "aaaa\r" + ["b"]=> + string(1) "b" + ["b\tbbb"]=> + string(6) "b\tbbb" + ["c"]=> + string(1) "c" + ["\[\]\!\@\#\$\%\^\&\*\(\)\{\}"]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(4) { + [" +"]=> + string(1) " +" + ["hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + ["11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +"]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + string(3) "one" + ["two"]=> + string(3) "two" + ["three"]=> + string(5) "three" +} +-- Iteration 10 -- +array(3) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +-- Iteration 11 -- +array(4) { + [10]=> + int(10) + [20]=> + int(20) + [40]=> + int(40) + [30]=> + int(30) +} +-- Iteration 12 -- +array(3) { + ["ten"]=> + string(3) "ten" + ["twenty"]=> + string(6) "twenty" + ["thirty"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(3) { + [1]=> + int(1) + ["two"]=> + string(3) "two" + ["four"]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + ["null"]=> + string(4) "null" + [""]=> + NULL +} +-- Iteration 15 -- +array(4) { + ["true"]=> + string(4) "true" + ["false"]=> + string(5) "false" + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + ["emptys"]=> + string(6) "emptys" + [""]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [""]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [4]=> + int(4) + [5]=> + int(5) + [6]=> + int(6) +} +-- Iteration 19 -- +array(3) { + [10]=> + int(10) + [20]=> + int(20) + [3]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_combine_variation4.phpt b/ext/standard/tests/array/array_combine_variation4.phpt new file mode 100644 index 0000000..bcd8428 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation4.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_combine() function : usage variations - associative array with different keys(Bug#43424) +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_combine() by passing different + * associative arrays having different possible keys to $keys argument and + * associative arrays having different possible keys to $values argument. +*/ + +echo "*** Testing array_combine() : assoc array with diff keys to both \$keys and \$values argument ***\n"; +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr1 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable +/*10*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed keys +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passsed to $arr2 argument +$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", + "\tHello" => 111, 2.2, 'color', "Hello world" => "string", + "pen\n" => 33, new classA() => 11, 133 => "int"); + +// loop through each sub-array within $arrays to check the behavior of array_combine() +// same arrays are passed to both $keys and $values +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : assoc array with diff keys to both $keys and $values argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(1) { + ["float"]=> + string(5) "float" +} +-- Iteration 6 -- +array(4) { + ["f1"]=> + string(2) "f1" + ["f2"]=> + string(2) "f2" + ["f3"]=> + string(2) "f3" + ["f4"]=> + string(2) "f4" +} +-- Iteration 7 -- +array(4) { + [111]=> + int(111) + ["color"]=> + string(5) "color" + ["2.2"]=> + float(2.2) + [33]=> + int(33) +} +-- Iteration 8 -- +array(4) { + [111]=> + int(111) + ["color"]=> + string(5) "color" + ["2.2"]=> + float(2.2) + [33]=> + int(33) +} +-- Iteration 9 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["string"]=> + string(6) "string" +} +-- Iteration 10 -- +array(1) { + ["hello"]=> + string(5) "hello" +} +-- Iteration 11 -- +array(6) { + [1]=> + int(1) + ["2.2"]=> + float(2.2) + ["int"]=> + string(3) "int" + ["float"]=> + string(5) "float" + ["unset"]=> + string(5) "unset" + ["heredoc"]=> + string(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_combine_variation5.phpt b/ext/standard/tests/array/array_combine_variation5.phpt new file mode 100644 index 0000000..4d9f185 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation5.phpt @@ -0,0 +1,185 @@ +--TEST-- +Test array_combine() function : usage variations - associative array with different values(Bug#43424) +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing the functionality of array_combine() by passing various +* associative arrays having different possible values to $keys argument and +* associative arrays having different possible values to $values argument. +*/ + +echo "*** Testing array_combine() : assoc array with diff values to both \$keys and \$values argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ +public function __toString(){ +return "Class A object"; +} +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable +/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + + +// loop through each sub-array within $arrays to check the behavior of array_combine() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + var_dump( array_combine($array, $array) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : assoc array with diff values to both $keys and $values argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["2.3333"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["1.2"]=> + float(1.2) + ["3.33"]=> + float(3.33) + ["4.8999992284"]=> + float(4.8999992284) + ["33333333.333"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(4) { + [" Hello"]=> + string(6) " Hello" + ["col or"]=> + string(6) "col or" + ["world"]=> + string(7) "world" + ["pen +"]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + ["\tHello"]=> + string(7) "\tHello" + ["col\tor"]=> + string(7) "col\tor" + ["\v\fworld"]=> + string(9) "\v\fworld" + ["pen\n"]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + ["hello"]=> + string(5) "hello" + ["Hello world"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + ["Class A object"]=> + object(classA)#%d (0) { + } + [""]=> + NULL + ["Resource id #%d"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + ["hello"]=> + string(5) "hello" + ["Class A object"]=> + object(classA)#%d (0) { + } + ["fruit"]=> + string(5) "fruit" + ["Resource id #%d"]=> + resource(%d) of type (stream) + [133]=> + int(133) + ["444.432"]=> + float(444.432) + [""]=> + NULL + ["Hello world"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_combine_variation6.phpt b/ext/standard/tests/array/array_combine_variation6.phpt new file mode 100644 index 0000000..94c7b4d --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_combine() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_combine(array $keys, array $values) + * Description: Creates an array by using the elements of the first parameter as keys + * and the elements of the second as the corresponding values + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_combine() by passing array with +* binary values for $keys and $values argument. +*/ + +echo "*** Testing array_combine() : binary safe checking ***\n"; + +// array with binary values +$arr_binary = array(b"hello", b"world"); +$arr_normal = array("hello", "world"); + +// array with binary value for $keys and $values argument +var_dump( array_combine($arr_binary, $arr_binary) ); + +// array with binary value for $values argument +var_dump( array_combine($arr_normal, $arr_binary) ); + +// array with binary value for $keys argument +var_dump( array_combine($arr_binary, $arr_normal) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_combine() : binary safe checking *** +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +array(2) { + ["hello"]=> + string(5) "hello" + ["world"]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_count_values.phpt b/ext/standard/tests/array/array_count_values.phpt new file mode 100644 index 0000000..a6424aa --- /dev/null +++ b/ext/standard/tests/array/array_count_values.phpt @@ -0,0 +1,94 @@ +--TEST-- +array_count_values() +--FILE-- +<?php +$arrays = array ( + array (), + array (0), + array (1), + array (-1), + array (0, 0), + array (0, 1), + array (1, 1), + array (1, "hello", 1, "world", "hello"), + array ("hello", "world", "hello"), + array ("", "world", "", "hello", "world", "hello", "hello", "world", "hello"), + array (0, array (1, "hello", 1, "world", "hello")), + array (1, array (1, "hello", 1, "world", "hello"), array (1, "hello", 1, "world", "hello"), array (1, "hello", 1, "world", "hello")), +); + +foreach ($arrays as $item) { + var_dump (@array_count_values ($item)); + echo "\n"; +} +?> +--EXPECT-- +array(0) { +} + +array(1) { + [0]=> + int(1) +} + +array(1) { + [1]=> + int(1) +} + +array(1) { + [-1]=> + int(1) +} + +array(1) { + [0]=> + int(2) +} + +array(2) { + [0]=> + int(1) + [1]=> + int(1) +} + +array(1) { + [1]=> + int(2) +} + +array(3) { + [1]=> + int(2) + ["hello"]=> + int(2) + ["world"]=> + int(1) +} + +array(2) { + ["hello"]=> + int(2) + ["world"]=> + int(1) +} + +array(3) { + [""]=> + int(2) + ["world"]=> + int(3) + ["hello"]=> + int(4) +} + +array(1) { + [0]=> + int(1) +} + +array(1) { + [1]=> + int(1) +} diff --git a/ext/standard/tests/array/array_count_values2.phpt b/ext/standard/tests/array/array_count_values2.phpt new file mode 100644 index 0000000..8dc9b23 --- /dev/null +++ b/ext/standard/tests/array/array_count_values2.phpt @@ -0,0 +1,43 @@ +--TEST-- +basic array_count_values test +--FILE-- +<?php +$array1 = array(1, + "hello", + 1, + "world", + "hello", + "", + "rabbit", + "foo", + "Foo", + TRUE, + FALSE, + NULL, + 0); +var_dump(array_count_values($array1)); +?> +--EXPECTF-- +Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %s + +Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %s + +Warning: array_count_values(): Can only count STRING and INTEGER values! in %s on line %s +array(8) { + [1]=> + int(2) + ["hello"]=> + int(2) + ["world"]=> + int(1) + [""]=> + int(1) + ["rabbit"]=> + int(1) + ["foo"]=> + int(1) + ["Foo"]=> + int(1) + [0]=> + int(1) +} diff --git a/ext/standard/tests/array/array_count_values_error.phpt b/ext/standard/tests/array/array_count_values_error.phpt new file mode 100644 index 0000000..843e34e --- /dev/null +++ b/ext/standard/tests/array/array_count_values_error.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_count_values() function : Invalid parameters +--FILE-- +<?php +/* Prototype : proto array array_count_values(array input) + * Description: Return the value as key and the frequency of that value in input as value + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* + * Test for handling of incorrect parameters. + */ + +echo "*** Testing array_count_values() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_count_values() function with Zero arguments --\n"; +var_dump( array_count_values() ); + +//Test array_count_values with one more than the expected number of arguments +echo "\n-- Testing array_count_values() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$extra_arg = 10; +var_dump( array_count_values($input, $extra_arg) ); + +//Test array_count_values with integer arguments +echo "\n-- Testing array_count_values() function integer arguments --\n"; +var_dump( array_count_values(1 )); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_count_values() : error conditions *** + +-- Testing array_count_values() function with Zero arguments -- + +Warning: array_count_values() expects exactly 1 parameter, 0 given in %sarray_count_values_error.php on line 16 +NULL + +-- Testing array_count_values() function with more than expected no. of arguments -- + +Warning: array_count_values() expects exactly 1 parameter, 2 given in %sarray_count_values_error.php on line 22 +NULL + +-- Testing array_count_values() function integer arguments -- + +Warning: array_count_values() expects parameter 1 to be array, integer given in %sarray_count_values_error.php on line 26 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_count_values_variation.phpt b/ext/standard/tests/array/array_count_values_variation.phpt new file mode 100644 index 0000000..89d7f37 --- /dev/null +++ b/ext/standard/tests/array/array_count_values_variation.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_count_values() function : Test all normal paramter variations +--FILE-- +<?php +/* Prototype : proto array array_count_values(array input) + * Description: Return the value as key and the frequency of that value in input as value + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* + * Test behaviour with paramter variations + */ + +echo "*** Testing array_count_values() : parameter variations ***\n"; + +class A { + static function hello() { + echo "Hello\n"; + } +} + +$ob = new A(); + +$fp = fopen("array_count_file", "w+"); + +$arrays = array ("bobk" => "bobv", "val", 6 => "val6", $fp, $ob); + +var_dump (@array_count_values ($arrays)); +echo "\n"; + + +echo "Done"; +?> + +--CLEAN-- +<?php +unlink("array_count_file"); +?> +--EXPECTF-- +*** Testing array_count_values() : parameter variations *** +array(3) { + ["bobv"]=> + int(1) + ["val"]=> + int(1) + ["val6"]=> + int(1) +} + +Done diff --git a/ext/standard/tests/array/array_diff_1.phpt b/ext/standard/tests/array/array_diff_1.phpt new file mode 100644 index 0000000..a25d19d --- /dev/null +++ b/ext/standard/tests/array/array_diff_1.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test array_diff when non-array is passed +--FILE-- +<?php +//-=-=-=-=- +$a = array(); +$b = 3; +$c = array(5); +array_diff($a, $b, $c); +//-=-=-=-=-=- +echo "OK!"; +?> +--EXPECTF-- +Warning: array_diff(): Argument #2 is not an array in %s +OK! diff --git a/ext/standard/tests/array/array_diff_assoc.phpt b/ext/standard/tests/array/array_diff_assoc.phpt new file mode 100644 index 0000000..29db107 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc.phpt @@ -0,0 +1,49 @@ +--TEST-- +basic array_diff_assoc test +--FILE-- +<?php +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red", ""); +$array2 = array("a" => "green", "yellow", "red", TRUE); +$array3 = array("red", "a"=>"brown", ""); +$result[] = array_diff_assoc($array1, $array2); +$result[] = array_diff_assoc($array1, $array3); +$result[] = array_diff_assoc($array2, $array3); +$result[] = array_diff_assoc($array1, $array2, $array3); +print_r($result) +?> +--EXPECT-- +Array +( + [0] => Array + ( + [b] => brown + [c] => blue + [0] => red + [1] => + ) + + [1] => Array + ( + [a] => green + [b] => brown + [c] => blue + ) + + [2] => Array + ( + [a] => green + [0] => yellow + [1] => red + [2] => 1 + ) + + [3] => Array + ( + [b] => brown + [c] => blue + ) + +) + + + diff --git a/ext/standard/tests/array/array_diff_assoc_basic.phpt b/ext/standard/tests/array/array_diff_assoc_basic.phpt new file mode 100644 index 0000000..c6b3aef --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_basic.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test array_diff_assoc() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_diff_assoc + */ + +echo "*** Testing array_diff_assoc() : basic functionality ***\n"; +$array_default_key = array('one', 2, 'three', '4'); +$array_numeric_key = array(1 => 'one', 2=> 'two', 3 => 4); +$array_string_key = array('one' => 1, 'two' => '2', '3' => 'three'); + + + +echo "-- Compare Default keys to numeric keys --\n"; +var_dump(array_diff_assoc($array_default_key, $array_numeric_key)); +var_dump(array_diff_assoc($array_numeric_key, $array_default_key)); + + +echo "\n-- Compare Default keys to string keys --\n"; +var_dump(array_diff_assoc($array_default_key, $array_numeric_key)); +var_dump(array_diff_assoc($array_numeric_key, $array_default_key)); + + +echo "\n-- Compare numeric keys to string keys --\n"; +var_dump(array_diff_assoc($array_numeric_key, $array_string_key)); +var_dump(array_diff_assoc($array_string_key, $array_numeric_key)); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : basic functionality *** +-- Compare Default keys to numeric keys -- +array(3) { + [0]=> + string(3) "one" + [1]=> + int(2) + [2]=> + string(5) "three" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} + +-- Compare Default keys to string keys -- +array(3) { + [0]=> + string(3) "one" + [1]=> + int(2) + [2]=> + string(5) "three" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} + +-- Compare numeric keys to string keys -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(4) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_error.phpt b/ext/standard/tests/array/array_diff_assoc_error.phpt new file mode 100644 index 0000000..211907c --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_diff_assoc() function : error conditions - pass array_diff_assoc() too few/zero arguments +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test errors for array_diff with too few\zero arguments + */ + +echo "*** Testing array_diff_assoc() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_diff_assoc() function with zero arguments --\n"; +var_dump( array_diff_assoc() ); + +// Testing array_diff_assoc with one less than the expected number of arguments +echo "\n-- Testing array_diff_assoc() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_diff_assoc($arr1) ); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : error conditions *** + +-- Testing array_diff_assoc() function with zero arguments -- + +Warning: array_diff_assoc(): at least 2 parameters are required, 0 given in %s on line %d +NULL + +-- Testing array_diff_assoc() function with less than expected no. of arguments -- + +Warning: array_diff_assoc(): at least 2 parameters are required, 1 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation1.phpt b/ext/standard/tests/array/array_diff_assoc_variation1.phpt new file mode 100644 index 0000000..b6c6379 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation1.phpt @@ -0,0 +1,234 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Pass array_diff_assoc arguments that are not arrays in place of $arr1 + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +//array of unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp, +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; +fclose($fp); +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 26 -- + +Warning: array_diff_assoc(): Argument #1 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation10.phpt b/ext/standard/tests/array/array_diff_assoc_variation10.phpt new file mode 100644 index 0000000..0687ed8 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation10.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - binary safe check +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not + * present in any of the others arguments but do additional checks whether + * the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() compares binary data + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array1 = array( b"1", + b"hello", + "world", + "str1" => "hello", + "str2" => "world"); + +$array2 = array( b"1" => 'hello', + b"world", + "hello", + 'test'); + +var_dump(array_diff_assoc($array1, $array2)); +var_dump(array_diff_assoc($array2, $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** +array(3) { + [0]=> + string(1) "1" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +array(2) { + [3]=> + string(5) "hello" + [4]=> + string(4) "test" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation2.phpt b/ext/standard/tests/array/array_diff_assoc_variation2.phpt new file mode 100644 index 0000000..5de9442 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation2.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * pass array_diff_assoc arguments which are not arrays in place of $arr2 + */ + +echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +//array of unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp, +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($array, $input)); + $iterator++; +}; +fclose($fp); +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 26 -- + +Warning: array_diff_assoc(): Argument #2 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation3.phpt b/ext/standard/tests/array/array_diff_assoc_variation3.phpt new file mode 100644 index 0000000..1d4aaf2 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation3.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test array_diff_assoc() function : variation - array containing different data types +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() compares indexed arrays containing different data types + */ + +echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of different data types to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ +'int' => array( + 0, + 1, + 12345, + -2345), + + // float data +/*2*/ +'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + + // null data +/*3*/ +'null' => array( + NULL, + null), + + // boolean data +/*4*/ +'bool' => array( + true, + false, + TRUE, + FALSE), + + // empty data +/*5*/ +'empty' => array( + "", + ''), + + // string data +/*6*/ +'string' => array( + "string", + 'string', + $heredoc), + + // binary data +/*7*/ +'binary' => array( + b"binary", + (binary)"binary"), + + // object data +/*8*/ +'object' => array( + new classA()), + + // undefined data +/*9*/ +'undefined' => array( + @$undefined_var), + + // unset data +/*10*/ +'unset' => array( + @$unset_var), +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; +echo "Done"; +?> +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) +} + +-- Iteration 2 -- +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + +-- Iteration 3 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4 -- +array(3) { + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6 -- +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(6) "binary" + [1]=> + string(6) "binary" +} + +-- Iteration 8 -- +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9 -- +array(1) { + [0]=> + NULL +} + +-- Iteration 10 -- +array(1) { + [0]=> + NULL +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation4.phpt b/ext/standard/tests/array/array_diff_assoc_variation4.phpt new file mode 100644 index 0000000..34e979a --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation4.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - arrays with different data types as keys +--FILE-- + +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() compares arrays containing different data types + * as keys + */ + +echo "\n*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//Different data types as keys to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ +'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative'), + + // float data +/*2*/ +'float' => array( + 10.5 => 'float 1', + -10.5 => 'float 2', + .5 => 'float 3'), + + // null data +/*3*/ +'null' => array( + NULL => 'null 1', + null => 'null 2'), + + // boolean data +/*4*/ +'bool' => array( + true => 'boolt', + false => 'boolf', + TRUE => 'boolT', + FALSE => 'boolF'), + + // empty data +/*5*/ +'empty' => array( + "" => 'emptyd', + '' => 'emptys'), + + // string data +/*6*/ +'string' => array( + "string" => 'stringd', + 'string' => 'strings', + $heredoc => 'stringh'), + + // binary data +/*7*/ +'binary' => array( + b"binary1" => 'binary 1', + (binary)"binary2" => 'binary 2'), + + // undefined data +/*8*/ +'undefined' => array( + @$undefined_var => 'undefined'), + + // unset data +/*9*/ +'unset' => array( + @$unset_var => 'unset'), + +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_diff_assoc($input, $array)); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} + +-- Iteration 2 -- +array(3) { + [10]=> + string(7) "float 1" + [-10]=> + string(7) "float 2" + [0]=> + string(7) "float 3" +} + +-- Iteration 3 -- +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 4 -- +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} + +-- Iteration 5 -- +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 6 -- +array(2) { + ["string"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 7 -- +array(2) { + ["binary1"]=> + string(8) "binary 1" + ["binary2"]=> + string(8) "binary 2" +} + +-- Iteration 8 -- +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 9 -- +array(1) { + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation5.phpt b/ext/standard/tests/array/array_diff_assoc_variation5.phpt new file mode 100644 index 0000000..c89c656 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation5.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - compare integers, floats and strings +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are not present + * in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc compares integers, floats and string + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; +$arr_default_int = array(1, 2, 3, 'a'); +$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00, 'b'); +$arr_string = array('1', '2', '3', 'c'); +$arr_string_float = array('0' => '1.00', '1.00' => '2.00', '2.00' => '3.00', 'd'); + +echo "-- Result of comparing integers and floating point numbers: --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_float)); +var_dump(array_diff_assoc($arr_float, $arr_default_int)); + +echo "-- Result of comparing integers and strings containing an integers : --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_string)); +var_dump(array_diff_assoc($arr_string, $arr_default_int)); + +echo "-- Result of comparing integers and strings containing floating points : --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_default_int)); + +echo "-- Result of comparing floating points and strings containing integers : --\n"; +var_dump(array_diff_assoc($arr_float, $arr_string)); +var_dump(array_diff_assoc($arr_string, $arr_float)); + +echo "-- Result of comparing floating points and strings containing floating point: --\n"; +var_dump(array_diff_assoc($arr_float, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_float)); + +echo "-- Result of comparing strings containing integers and strings containing floating points : --\n"; +var_dump(array_diff_assoc($arr_string, $arr_string_float)); +var_dump(array_diff_assoc($arr_string_float, $arr_string)); + +echo "-- Result of comparing more than two arrays: --\n"; +var_dump(array_diff_assoc($arr_default_int, $arr_float, $arr_string, $arr_string_float)); + +echo "Done"; +?> +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** +-- Result of comparing integers and floating point numbers: -- +array(1) { + [3]=> + string(1) "a" +} +array(1) { + [3]=> + string(1) "b" +} +-- Result of comparing integers and strings containing an integers : -- +array(1) { + [3]=> + string(1) "a" +} +array(1) { + [3]=> + string(1) "c" +} +-- Result of comparing integers and strings containing floating points : -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(1) "a" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing floating points and strings containing integers : -- +array(1) { + [3]=> + string(1) "b" +} +array(1) { + [3]=> + string(1) "c" +} +-- Result of comparing floating points and strings containing floating point: -- +array(4) { + [0]=> + float(1) + [1]=> + float(2) + [2]=> + float(3) + [3]=> + string(1) "b" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing strings containing integers and strings containing floating points : -- +array(4) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" + [3]=> + string(1) "c" +} +array(4) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" + ["2.00"]=> + string(4) "3.00" + [1]=> + string(1) "d" +} +-- Result of comparing more than two arrays: -- +array(1) { + [3]=> + string(1) "a" +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation6.phpt b/ext/standard/tests/array/array_diff_assoc_variation6.phpt new file mode 100644 index 0000000..d6190b6 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation6.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - strict string comparison check +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc behaves + * 1. When comparing an array that has similar elements + * but has been created in a different order + * 2. When doing a strict comparison of string representation + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array = array ('zero', + 1 => 1, + 'two' => 2.00000000000001); + +$inputs = array ( + +//default keys => string values +/*1*/ array('2.00000000000001', '1', 'zero', 'a'), + +//numeric keys => string values +/*2*/ array(2 => '2.00000000000001', + 1 => '1', + 0 => 'zero', + 3 => 'a'), + +//string keys => string values +/*3*/ array('2' => '2.00000000000001', + '1' => '1', + '0' => 'zero', + '3' => 'a') , + +//default keys => numeric values +/*4*/ array(2, 1, 0), + +//numeric keys => numeric values +/*5*/ array(2 => 2, + 1 => 1, + 0 => 0), + +//string keys => numeric values +/*6*/ array('two' => 2, + '1' => 1, + '0' => 0), + +//defualt keys => float values +/*7*/ array(2.00000000000001, 1.00, 0.01E-9), + +//numeric keys => float values +/*8*/ array(2 => 2.00000000000001, + 1 => 1.00, + 0 => 0.01E-9), + +//string keys => float values +/*9*/ array ('two' => 2.00000000000001, + '1' => 1.00, + '0' =>0.01E-9) +); + +// loop through each element of $inputs to check the behavior of array_diff_assoc +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump(array_diff_assoc($array, $input)); + var_dump(array_diff_assoc($input, $array)); + $iterator++; +}; +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** + +-- Iteration 1 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(3) { + [0]=> + string(16) "2.00000000000001" + [2]=> + string(4) "zero" + [3]=> + string(1) "a" +} + +-- Iteration 2 -- +array(1) { + ["two"]=> + float(2) +} +array(2) { + [2]=> + string(16) "2.00000000000001" + [3]=> + string(1) "a" +} + +-- Iteration 3 -- +array(1) { + ["two"]=> + float(2) +} +array(2) { + [2]=> + string(16) "2.00000000000001" + [3]=> + string(1) "a" +} + +-- Iteration 4 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [0]=> + int(2) + [2]=> + int(0) +} + +-- Iteration 5 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [2]=> + int(2) + [0]=> + int(0) +} + +-- Iteration 6 -- +array(1) { + [0]=> + string(4) "zero" +} +array(1) { + [0]=> + int(0) +} + +-- Iteration 7 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [0]=> + float(2) + [2]=> + float(1.0E-11) +} + +-- Iteration 8 -- +array(2) { + [0]=> + string(4) "zero" + ["two"]=> + float(2) +} +array(2) { + [2]=> + float(2) + [0]=> + float(1.0E-11) +} + +-- Iteration 9 -- +array(1) { + [0]=> + string(4) "zero" +} +array(1) { + [0]=> + float(1.0E-11) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation7.phpt b/ext/standard/tests/array/array_diff_assoc_variation7.phpt new file mode 100644 index 0000000..6fab0ae --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation7.phpt @@ -0,0 +1,101 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - arrays containing referenced variables +--FILE-- + +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Tests how array_diff_assoc compares + * 1. Referenced variables + * 2. Arrays that have been referenced to each other + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$a = 'a'; + +$arr1 = array('a', 'b', 'c', $a); +$arr2 = array('a' => 1, 'b' => 2, 'c' => 3, &$a); + +echo "-- Results when \$a = $a: --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$a = 4; + +echo "-- Results when \$a has been changed to $a: --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$arr2 = &$arr1; + +echo "-- Results when \$arr2 is referenced to \$arr1 --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +$arr1 = array('zero' => 'x', 'one' => 'y', 'two' => 'z'); + +echo "-- Results when \$arr1 is changed --\n"; +var_dump(array_diff_assoc($arr1, $arr2)); +var_dump(array_diff_assoc($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff_assoc() : usage variations *** +-- Results when $a = a: -- +array(3) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "a" +} +array(3) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +-- Results when $a has been changed to 4: -- +array(4) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "a" +} +array(4) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + &int(4) +} +-- Results when $arr2 is referenced to $arr1 -- +array(0) { +} +array(0) { +} +-- Results when $arr1 is changed -- +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_assoc_variation8.phpt b/ext/standard/tests/array/array_diff_assoc_variation8.phpt new file mode 100644 index 0000000..3189c11 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation8.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - array containing duplicate keys and values +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether + * the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc() behaves when comparing: + * 1. the order of the array + * 2. duplicate values + * 3. duplicate key names + */ + +echo "*** Testing array_diff_assoc() : variation ***\n"; + +$array_index = array('a', 'b', 'c', 0 => 'd', 'b'); //duplicate key (0), duplicate value (b) +$array_assoc = array ('2' => 'c', //same key=>value pair, different order + '1' => 'b', + '0' => 'a', + 'b' => '3', //key and value from array_index swapped + 'c' => 2); //same as above, using integer + +var_dump(array_diff_assoc($array_index, $array_assoc)); +var_dump(array_diff_assoc($array_assoc, $array_index)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : variation *** +array(2) { + [0]=> + string(1) "d" + [3]=> + string(1) "b" +} +array(3) { + [0]=> + string(1) "a" + ["b"]=> + string(1) "3" + ["c"]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_diff_assoc_variation9.phpt b/ext/standard/tests/array/array_diff_assoc_variation9.phpt new file mode 100644 index 0000000..5ab6232 --- /dev/null +++ b/ext/standard/tests/array/array_diff_assoc_variation9.phpt @@ -0,0 +1,141 @@ +--TEST-- +Test array_diff_assoc() function : usage variations - compare multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_diff_assoc(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments but do additional checks whether + * the keys are equal + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff_assoc behaves when comparing + * multi-dimensional arrays + */ + +echo "*** Testing array_diff_assoc() : usage variations ***\n"; + +$array1 = array('sub_array1' => array (1, 2, 3), + 'sub_array2' => array ('a', 'b', 'c')); +$array2 = array('sub_arraya' => array (1, 3, 5), + 'sub_arrayb' => array ('a', 'z', 'y')); + +echo "-- Compare two 2-D arrays --\n"; +var_dump(array_diff_assoc($array1, $array2)); +var_dump(array_diff_assoc($array2, $array1)); + +echo "\n-- Compare subarrays from two 2-D arrays --\n"; +var_dump(array_diff_assoc($array1['sub_array1'], $array2['sub_arraya'])); +var_dump(array_diff_assoc($array2['sub_arraya'], $array1['sub_array1'])); +var_dump(array_diff_assoc($array1['sub_array2'], $array2['sub_arrayb'])); +var_dump(array_diff_assoc($array2['sub_arrayb'], $array1['sub_array1'])); + +echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; +var_dump(array_diff_assoc($array1['sub_array1'], $array2)); +var_dump(array_diff_assoc($array1, $array2['sub_arraya'])); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff_assoc() : usage variations *** +-- Compare two 2-D arrays -- +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +array(2) { + ["sub_arraya"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(3) + [2]=> + int(5) + } + ["sub_arrayb"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" + } +} + +-- Compare subarrays from two 2-D arrays -- +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [1]=> + int(3) + [2]=> + int(5) +} +array(2) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" +} + +-- Compare a subarray from one 2-D array and one 2-D array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_basic.phpt b/ext/standard/tests/array/array_diff_basic.phpt new file mode 100644 index 0000000..30aead6 --- /dev/null +++ b/ext/standard/tests/array/array_diff_basic.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test array_diff() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not present + * in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_diff + */ + +echo "*** Testing array_diff() : basic functionality ***\n"; + +//Test indexed array with integers as elements +$array_int1 = array (1, 2, 3, 4); +$array_int2 = array (3, 4, 5, 6); + +echo "-- Test indexed array with integers as elements --\n"; +var_dump(array_diff($array_int1, $array_int2)); +var_dump(array_diff($array_int2, $array_int1)); + + +//Test indexed array with strings as elements +$array_string1 = array ('one', 'two', 'three', 'four'); +$array_string2 = array ('three', 'four', 'five', 'six'); + +echo "-- Test indexed array with strings as elements --\n"; +var_dump(array_diff($array_string1, $array_string2)); +var_dump(array_diff($array_string2, $array_string1)); + +//Test associative array with strings as keys and integers as elements +$array_assoc_int1 = array ('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4); +$array_assoc_int2 = array ('three' => 3, 'four' => 4, 'five' => 5, 'six' => 6); + +echo "-- Test associative array with strings as keys and integers as elements --\n"; +var_dump(array_diff($array_assoc_int1, $array_assoc_int2)); +var_dump(array_diff($array_assoc_int2, $array_assoc_int1)); + +//Test associative array with strings as keys and elements +$array_assoc_str1 = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois', 'four' => 'quatre'); +$array_assoc_str2 = array ('three' => 'trois', 'four' => 'quatre', 'five' => 'cinq', 'six' => 'six'); + +echo "-- Test associative array with strings as keys and integers as elements --\n"; +var_dump(array_diff($array_assoc_str1, $array_assoc_str2)); +var_dump(array_diff($array_assoc_str2, $array_assoc_str1)); + +echo "-- Test array_diff with more than 2 arguments --\n"; +var_dump(array_diff($array_int1, $array_int2, $array_string1, $array_string2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : basic functionality *** +-- Test indexed array with integers as elements -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [2]=> + int(5) + [3]=> + int(6) +} +-- Test indexed array with strings as elements -- +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [2]=> + string(4) "five" + [3]=> + string(3) "six" +} +-- Test associative array with strings as keys and integers as elements -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["five"]=> + int(5) + ["six"]=> + int(6) +} +-- Test associative array with strings as keys and integers as elements -- +array(2) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" +} +array(2) { + ["five"]=> + string(4) "cinq" + ["six"]=> + string(3) "six" +} +-- Test array_diff with more than 2 arguments -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_diff_error.phpt b/ext/standard/tests/array/array_diff_error.phpt new file mode 100644 index 0000000..019cffb --- /dev/null +++ b/ext/standard/tests/array/array_diff_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_diff() function : error conditions - too few arguments passed to function +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff with less than the expected number of arguments + */ + +echo "*** Testing array_diff() : error conditions ***\n"; +// Zero arguments +echo "\n-- Testing array_diff() function with zero arguments --\n"; +var_dump( array_diff() ); + + +// Testing array_diff with one less than the expected number of arguments +echo "\n-- Testing array_diff() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_diff($arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : error conditions *** + +-- Testing array_diff() function with zero arguments -- + +Warning: array_diff(): at least 2 parameters are required, 0 given in %s on line %d +NULL + +-- Testing array_diff() function with less than expected no. of arguments -- + +Warning: array_diff(): at least 2 parameters are required, 1 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key.phpt b/ext/standard/tests/array/array_diff_key.phpt new file mode 100644 index 0000000..765431f --- /dev/null +++ b/ext/standard/tests/array/array_diff_key.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test of the array_diff_key() and array_diff_ukey() +--FILE-- +<?php +$a = array(1, 6, 2, -20, 15, 1200, -2500); +$b = array(0, 7, 2, -20, 11, 1100, -2500); +$c = array(0, 6, 2, -20, 19, 1000, -2500); +$d = array(3, 8,-2, -20, 14, 900, -2600); +$a_f = array_flip($a); +$b_f = array_flip($b); +$c_f = array_flip($c); +$d_f = array_flip($d); +$i = 1; +/* give nicer values */ +foreach ($a_f as $k=> &$a_f_el) { $a_f_el =$k*2;} +foreach ($b_f as $k=> &$b_f_el) { $b_f_el =$k*2;} +foreach ($c_f as $k=> &$c_f_el) { $c_f_el =$k*2;} +foreach ($d_f as $k=> &$d_f_el) { $d_f_el =$k*2;} + +echo "------ Test $i --------\n";$i++;// 1 +var_dump(array_diff_key($a_f, $b_f));// keys -> 1, 6, 15, 1200 +var_dump(array_diff_ukey($a_f, $b_f, "comp_func"));// 1, 6, 15, 1200 + +echo "------ Test $i --------\n";$i++;// 2 +var_dump(array_diff_key($a_f, $c_f));// keys -> 1, 15, 1200 +var_dump(array_diff_ukey($a_f, $c_f, "comp_func"));// 1, 15, 1200 + +echo "------ Test $i --------\n";$i++;// 3 +var_dump(array_diff_key($a_f, $d_f));// 1, 6, 2, 15, 1200, -2500 +var_dump(array_diff_ukey($a_f, $d_f, "comp_func"));// 1, 6, 2, 15, 1200, -2500 + +echo "------ Test $i --------\n";$i++;// 4 +var_dump(array_diff_key($a_f, $b_f, $c_f));// 1, 15, 1200 +var_dump(array_diff_ukey($a_f, $b_f, $c_f, "comp_func"));// 1, 15, 1200 + +echo "------ Test $i --------\n";$i++;// 5 +var_dump(array_diff_key($a_f, $b_f, $d_f));// 1, 6, 15, 1200 +var_dump(array_diff_ukey($a_f, $b_f, $d_f, "comp_func"));// 1, 6, 15, 1200 + + +echo "------ Test $i --------\n";$i++;// 6 +var_dump(array_diff_key($a_f, $b_f, $c_f, $d_f));// 1, 15, 1200 +var_dump(array_diff_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));//1, 15, 1200 + + +echo "------ Test $i --------\n";$i++;// 7 +var_dump(array_diff_key($b_f, $c_f));// 7, 11, 1100 +var_dump(array_diff_ukey($b_f, $c_f, "comp_func"));//7, 11, 1100 + +echo "------ Test $i --------\n";$i++;// 8 +var_dump(array_diff_key($b_f, $d_f));//0, 7, 2, 11, 1100, -2500 +var_dump(array_diff_ukey($b_f, $d_f, "comp_func"));//0, 7, 2, 11, 1100, -2500 + + +echo "------ Test $i --------\n";$i++;// 9 +var_dump(array_diff_key($b_f, $c_f, $d_f));// 7, 11, 1100 +var_dump(array_diff_ukey($b_f, $c_f, $d_f, "comp_func"));// 7, 11, 1000 + +function comp_func($a, $b) { + if ($a === $b) return 0; + return ($a > $b)? 1:-1; + +} +?> +--EXPECTF-- +------ Test 1 -------- +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 2 -------- +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 3 -------- +array(6) { + [1]=> + int(2) + [6]=> + int(12) + [2]=> + int(4) + [15]=> + int(30) + [1200]=> + int(2400) + [-2500]=> + &int(-5000) +} +array(6) { + [1]=> + int(2) + [6]=> + int(12) + [2]=> + int(4) + [15]=> + int(30) + [1200]=> + int(2400) + [-2500]=> + &int(-5000) +} +------ Test 4 -------- +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 5 -------- +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(4) { + [1]=> + int(2) + [6]=> + int(12) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 6 -------- +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +array(3) { + [1]=> + int(2) + [15]=> + int(30) + [1200]=> + int(2400) +} +------ Test 7 -------- +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} +------ Test 8 -------- +array(6) { + [0]=> + int(0) + [7]=> + int(14) + [2]=> + int(4) + [11]=> + int(22) + [1100]=> + int(2200) + [-2500]=> + &int(-5000) +} +array(6) { + [0]=> + int(0) + [7]=> + int(14) + [2]=> + int(4) + [11]=> + int(22) + [1100]=> + int(2200) + [-2500]=> + &int(-5000) +} +------ Test 9 -------- +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} +array(3) { + [7]=> + int(14) + [11]=> + int(22) + [1100]=> + int(2200) +} diff --git a/ext/standard/tests/array/array_diff_key2.phpt b/ext/standard/tests/array/array_diff_key2.phpt new file mode 100644 index 0000000..b7ef7f3 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key2.phpt @@ -0,0 +1,44 @@ +--TEST-- +basic array_diff_key test +--FILE-- +<?php +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red", ""); +$array2 = array("a" => "green", "yellow", "red", TRUE); +$array3 = array("red", "a"=>"brown", ""); +$result[] = array_diff_key($array1, $array2); +$result[] = array_diff_key($array1, $array3); +$result[] = array_diff_key($array2, $array3); +$result[] = array_diff_key($array1, $array2, $array3); + +var_dump($result); + +?> +--EXPECT-- +array(4) { + [0]=> + array(2) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + } + [1]=> + array(2) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + } + [2]=> + array(1) { + [2]=> + bool(true) + } + [3]=> + array(2) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + } +} diff --git a/ext/standard/tests/array/array_diff_key_basic.phpt b/ext/standard/tests/array/array_diff_key_basic.phpt new file mode 100644 index 0000000..6f6fcb9 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +Test array_diff_key() : basic functionality +--FILE-- +<?php +/* +* proto array array_diff_key(array arr1, array arr2 [, array ...]) +* Function is implemented in ext/standard/array.c +*/ +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_error.phpt b/ext/standard/tests/array/array_diff_key_error.phpt new file mode 100644 index 0000000..90168f5 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_diff_key() function : error conditions +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : error conditions ***\n"; + +// Initialise the variables +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + +// Testing array_diff_key with one less than the expected number of arguments +echo "\n-- Testing array_diff_key() function with less than expected no. of arguments --\n"; +var_dump( array_diff_key($array1) ); + +// Testing array_diff_key with no arguments +echo "\n-- Testing array_diff_key() function with no arguments --\n"; +var_dump( array_diff_key() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : error conditions *** + +-- Testing array_diff_key() function with less than expected no. of arguments -- + +Warning: array_diff_key(): at least 2 parameters are required, 1 given in %s on line %d +NULL + +-- Testing array_diff_key() function with no arguments -- + +Warning: array_diff_key(): at least 2 parameters are required, 0 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_key_variation1.phpt b/ext/standard/tests/array/array_diff_key_variation1.phpt new file mode 100644 index 0000000..52b703f --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation1.phpt @@ -0,0 +1,310 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array(1, 2, 3, 4, 5); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_key($value, $array2) ); + var_dump( array_diff_key($value, $array2, $array3) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +--int 0-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation2.phpt b/ext/standard/tests/array/array_diff_key_variation2.phpt new file mode 100644 index 0000000..737ee2e --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation2.phpt @@ -0,0 +1,311 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array(1, 2, 3, 4, 5); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_key($array1, $value) ); + var_dump( array_diff_key($array1, $value, $array3) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +--int 0-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #2 is not an array in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation3.phpt b/ext/standard/tests/array/array_diff_key_variation3.phpt new file mode 100644 index 0000000..28f4c05 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation3.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing unexpected values to third optional argument +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_key($array1, $array2, $value) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +--int 0-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_key(): Argument #3 is not an array in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation4.phpt b/ext/standard/tests/array/array_diff_key_variation4.phpt new file mode 100644 index 0000000..d3ef45c --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation4.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing integer indexed array +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(-07 => '-07', 0xA => '0xA'); + +$input_arrays = array( + 'decimal indexed' => array(10 => '10', '-17' => '-17'), + 'octal indexed' => array(-011 => '-011', 012 => '012'), + 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ), +); + +// loop through each element of the array for arr1 +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_key($input_array, $value) ); + var_dump( array_diff_key($value, $input_array) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +--decimal indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-17]=> + string(3) "-17" +} + +--octal indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-9]=> + string(4) "-011" +} + +--hexa indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [18]=> + string(4) "0x12" +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation5.phpt b/ext/standard/tests/array/array_diff_key_variation5.phpt new file mode 100644 index 0000000..f777953 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation5.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing float indexed array +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 10 => '10', -10 => '-10', 20 =>'20', -20 => '-20'); +$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5', -10.5 => '-10.5', 0.5 => '0.5'); + +echo "\n-- Testing array_diff_key() function with float indexed array --\n"; +// loop through each element of the array for arr1 +var_dump( array_diff_key($input_array, $float_indx_array) ); +var_dump( array_diff_key($float_indx_array, $input_array) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +-- Testing array_diff_key() function with float indexed array -- +array(2) { + [20]=> + string(2) "20" + [-20]=> + string(3) "-20" +} +array(0) { +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation6.phpt b/ext/standard/tests/array/array_diff_key_variation6.phpt new file mode 100644 index 0000000..48334fc --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation6.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing boolean indexed array +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_diff_key() function with boolean indexed array --\n"; +// loop through each element of the array for arr1 +var_dump( array_diff_key($input_array, $boolean_indx_array) ); +var_dump( array_diff_key($boolean_indx_array, $input_array) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +-- Testing array_diff_key() function with boolean indexed array -- +array(3) { + [-10]=> + string(3) "-10" + ["true"]=> + int(1) + ["false"]=> + int(0) +} +array(0) { +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation7.phpt b/ext/standard/tests/array/array_diff_key_variation7.phpt new file mode 100644 index 0000000..c2e806c --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation7.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing null,unset and undefined variable indexed array +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(10 => '10', "" => 'empty'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + // loop through each element of the array for arr1 + var_dump( array_diff_key($input_array, $value) ); + var_dump( array_diff_key($value, $input_array) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +--null indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--undefined indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--unset indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_key_variation8.phpt b/ext/standard/tests/array/array_diff_key_variation8.phpt new file mode 100644 index 0000000..3242e69 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation8.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_diff_key() function : usage variation - Passing multi-dimensional array +--FILE-- +<?php +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array( + + 'first' => array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 => 'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); + +echo "\n-- Testing array_diff_key() function with multi dimensional array --\n"; +var_dump( array_diff_key($array1, $array2) ); +var_dump( array_diff_key($array2, $array1) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_key() : usage variation *** + +-- Testing array_diff_key() function with multi dimensional array -- +array(1) { + ["third"]=> + array(1) { + [0]=> + string(4) "zero" + } +} +array(1) { + ["fourth"]=> + array(1) { + [2]=> + string(3) "two" + } +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_uassoc_basic.phpt b/ext/standard/tests/array/array_diff_uassoc_basic.phpt new file mode 100644 index 0000000..6a96be6 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +array_diff_uassoc(): Basic test +--FILE-- +<?php +/* +* array array_diff_uassoc ( array $array1, array $array2 [, array $..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_diff_uassoc($array1, $array2, "key_compare_func"); +var_dump($result); +?> +--EXPECT-- +array(3) { + ["b"]=> + string(5) "brown" + ["c"]=> + string(4) "blue" + [0]=> + string(3) "red" +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_uassoc_error.phpt b/ext/standard/tests/array/array_diff_uassoc_error.phpt new file mode 100644 index 0000000..0f9f824 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_error.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test array_diff_uassoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : error conditions ***\n"; + +//Initialize array +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a" => "green", "red"); +$array4 = array(); +$extra_arg = array(1, 2, 3, 4); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +//Test array_diff_uassoc with one more than the expected number of arguments +echo "\n-- Testing array_diff_uassoc() function with more than expected no. of arguments --\n"; +var_dump( array_diff_uassoc($array1, $array2, "key_compare_func", $extra_arg) ); +var_dump( array_diff_uassoc($array1, $array2, $array3, $array4, "key_compare_func", $extra_arg) ); + +// Testing array_diff_uassoc with one less than the expected number of arguments +echo "\n-- Testing array_diff_uassoc() function with less than expected no. of arguments --\n"; +var_dump( array_diff_uassoc($array1, $array2) ); + +// Testing array_diff_uassoc with no arguments +echo "\n-- Testing array_diff_uassoc() function with no arguments --\n"; +var_dump( array_diff_uassoc() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : error conditions *** + +-- Testing array_diff_uassoc() function with more than expected no. of arguments -- + +Warning: array_diff_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_diff_uassoc() expects parameter 6 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +-- Testing array_diff_uassoc() function with less than expected no. of arguments -- + +Warning: array_diff_uassoc(): at least 3 parameters are required, 2 given in %s on line %d +NULL + +-- Testing array_diff_uassoc() function with no arguments -- + +Warning: array_diff_uassoc(): at least 3 parameters are required, 0 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation1.phpt b/ext/standard/tests/array/array_diff_uassoc_variation1.phpt new file mode 100644 index 0000000..75494c7 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation1.phpt @@ -0,0 +1,244 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$array2 = array("a" => "green", "yellow", "red"); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($value, $array2, "key_compare_func") ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_uassoc(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation10.phpt b/ext/standard/tests/array/array_diff_uassoc_variation10.phpt new file mode 100644 index 0000000..57b17d1 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation10.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing float indexed array +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 10 => '10', -10 => '-10', 20 =>'20', -20 => '-20'); +$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5', -10.5 => '-10.5', 0.5 => '0.5'); + +echo "\n-- Testing array_diff_key() function with float indexed array --\n"; +var_dump( array_diff_uassoc($input_array, $float_indx_array, "strcasecmp") ); +var_dump( array_diff_uassoc($float_indx_array, $input_array, "strcasecmp") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Testing array_diff_key() function with float indexed array -- +array(5) { + [0]=> + string(1) "0" + [10]=> + string(2) "10" + [-10]=> + string(3) "-10" + [20]=> + string(2) "20" + [-20]=> + string(3) "-20" +} +array(3) { + [0]=> + string(3) "0.5" + [10]=> + string(4) "10.5" + [-10]=> + string(5) "-10.5" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation11.phpt b/ext/standard/tests/array/array_diff_uassoc_variation11.phpt new file mode 100644 index 0000000..b77df32 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation11.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing boolean indexed array +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_diff_key() function with float indexed array --\n"; +var_dump( array_diff_uassoc($input_array, $boolean_indx_array, "strcasecmp") ); +var_dump( array_diff_uassoc($boolean_indx_array, $input_array, "strcasecmp") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Testing array_diff_key() function with float indexed array -- +array(5) { + [0]=> + string(1) "0" + [1]=> + string(1) "1" + [-10]=> + string(3) "-10" + ["true"]=> + int(1) + ["false"]=> + int(0) +} +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation12.phpt b/ext/standard/tests/array/array_diff_uassoc_variation12.phpt new file mode 100644 index 0000000..9d48231 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation12.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing null,unset and undefined variable indexed array +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(10 => '10', "" => ''); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => NULL, null => null), + 'undefined indexed' => array(@$undefined_var => @$undefined_var), + 'unset indexed' => array(@$unset_var => @$unset_var), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($input_array, $value, "strcasecmp") ); + var_dump( array_diff_uassoc($value, $input_array, "strcasecmp") ); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +--null indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--undefined indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} + +--unset indexed-- +array(1) { + [10]=> + string(2) "10" +} +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation13.phpt b/ext/standard/tests/array/array_diff_uassoc_variation13.phpt new file mode 100644 index 0000000..9219426 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation13.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test array_diff_uassoc() function : usage variations - arrays containing referenced variables +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$ref_var = 'a'; +$array1 = array('a', $ref_var); +$array2 = array('a' => 1, &$ref_var); + +echo "\n-- Testing array_diff_uassoc() function with referenced variable \$ref_var has value '$ref_var' --\n"; +var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") ); +var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") ); + +// re-assign reference variable to different value +$ref_var = 10.00; +echo "\n-- Testing array_diff_uassoc() function with referenced variable \$ref_var value changed to $ref_var --\n"; +var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") ); +var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") ); + +//When array are refenced +$array2 = &$array1; +echo "\n-- Testing array_diff_uassoc() function when \$array2 is referenced to \$array1 --\n"; +var_dump( array_diff_uassoc($array1, $array2, "strcasecmp") ); +var_dump( array_diff_uassoc($array2, $array1, "strcasecmp") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Testing array_diff_uassoc() function with referenced variable $ref_var has value 'a' -- +array(1) { + [1]=> + string(1) "a" +} +array(1) { + ["a"]=> + int(1) +} + +-- Testing array_diff_uassoc() function with referenced variable $ref_var value changed to 10 -- +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "a" +} +array(2) { + ["a"]=> + int(1) + [0]=> + &float(10) +} + +-- Testing array_diff_uassoc() function when $array2 is referenced to $array1 -- +array(0) { +} +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation14.phpt b/ext/standard/tests/array/array_diff_uassoc_variation14.phpt new file mode 100644 index 0000000..a98a280 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation14.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation -Passing classWithoutToString (handling fatal error) to callback +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize array +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +class classWithoutToString +{ +} + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +$value = new classWithoutToString(); +var_dump( array_diff_uassoc($array1, $array2, $value) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** +Error: 2 - array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given, %s(%d) +NULL +===DONE=== + diff --git a/ext/standard/tests/array/array_diff_uassoc_variation2.phpt b/ext/standard/tests/array/array_diff_uassoc_variation2.phpt new file mode 100644 index 0000000..1d3f6a4 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation2.phpt @@ -0,0 +1,244 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation -Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($array1, $value, "key_compare_func") ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_uassoc(): Argument #2 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation3.phpt b/ext/standard/tests/array/array_diff_uassoc_variation3.phpt new file mode 100644 index 0000000..3218dd3 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation3.phpt @@ -0,0 +1,263 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation -Passing unexpected values to callback argument +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize array +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for key_comp_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($array1, $array2, $value) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--empty array-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +--int indexed array-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +--associative array-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +--nested arrays-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +--resource-- + +Warning: array_diff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation4.phpt b/ext/standard/tests/array/array_diff_uassoc_variation4.phpt new file mode 100644 index 0000000..ab87449 --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation4.phpt @@ -0,0 +1,246 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation -Passing unexpected values as third optional argument +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($array1, $array2, $value, "key_compare_func") ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_uassoc(): Argument #3 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation5.phpt b/ext/standard/tests/array/array_diff_uassoc_variation5.phpt new file mode 100644 index 0000000..c35b2eb --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation5.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing integers and floating point numbers +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_default_int = array(1, 2, 3, 4); +$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00, 3.00 => 4.00); + + +function key_compare_func($key1, $key2) +{ + if ($key1 === $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of comparing integers and floating point numbers --\n"; +var_dump( array_diff_uassoc($arr_default_int, $arr_float, "key_compare_func") ); +var_dump( array_diff_uassoc($arr_float, $arr_default_int, "key_compare_func") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing integers and floating point numbers -- +array(0) { +} +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation6.phpt b/ext/standard/tests/array/array_diff_uassoc_variation6.phpt new file mode 100644 index 0000000..ad4e8ff --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation6.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing floating points with strings having integers and float +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_float = array(0 => 1.00, 1.00 => 2.00); +$arr_string_int = array('1', '2'); +$arr_string_float = array('0' => '1.00', '1.00' => '2.00'); + +function key_compare_func($key1, $key2) +{ + if ($key1 === $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of comparing floating points and strings containing integers --\n"; +var_dump( array_diff_uassoc($arr_float, $arr_string_int, "key_compare_func") ); +var_dump( array_diff_uassoc($arr_string_int, $arr_float, "key_compare_func") ); + +echo "\n-- Result of comparing floating points and strings containing floating point --\n"; +var_dump( array_diff_uassoc($arr_float, $arr_string_float, "key_compare_func") ); +var_dump( array_diff_uassoc($arr_string_float, $arr_float, "key_compare_func") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing floating points and strings containing integers -- +array(0) { +} +array(0) { +} + +-- Result of comparing floating points and strings containing floating point -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} +array(2) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation7.phpt b/ext/standard/tests/array/array_diff_uassoc_variation7.phpt new file mode 100644 index 0000000..da2030c --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation7.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing strings containing integers and float +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_string_int = array('1', '2'); +$arr_string_float = array('0' => '1.00', '1.00' => '2.00'); + +function key_compare_func($key1, $key2) +{ + if ($key1 === $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of comparing strings containing integers and strings containing floating points --\n"; +var_dump( array_diff_uassoc($arr_string_int, $arr_string_float, "key_compare_func") ); +var_dump( array_diff_uassoc($arr_string_float, $arr_string_int, "key_compare_func") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing strings containing integers and strings containing floating points -- +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} +array(2) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation8.phpt b/ext/standard/tests/array/array_diff_uassoc_variation8.phpt new file mode 100644 index 0000000..d450def --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation8.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Comparing integers with strings containing integers and float +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_default_int = array(1, 2, 3); +$arr_string_int = array('1', '2'); +$arr_string_float = array('0' => '1.00', '1.00' => '2.00'); + +function key_compare_func($key1, $key2) +{ + if ($key1 === $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of comparing integers and strings containing an integers --\n"; +var_dump( array_diff_uassoc($arr_default_int, $arr_string_int, "key_compare_func") ); +var_dump( array_diff_uassoc($arr_string_int, $arr_default_int, "key_compare_func") ); + +echo "\n-- Result of comparing integers and strings containing floating points --\n"; +var_dump( array_diff_uassoc($arr_default_int, $arr_string_float, "key_compare_func") ); +var_dump( array_diff_uassoc($arr_string_float, $arr_default_int, "key_compare_func") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +-- Result of comparing integers and strings containing an integers -- +array(1) { + [2]=> + int(3) +} +array(0) { +} + +-- Result of comparing integers and strings containing floating points -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [0]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_uassoc_variation9.phpt b/ext/standard/tests/array/array_diff_uassoc_variation9.phpt new file mode 100644 index 0000000..72746bb --- /dev/null +++ b/ext/standard/tests/array/array_diff_uassoc_variation9.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test array_diff_uassoc() function : usage variation - Passing integer indexed array +--FILE-- +<?php +/* Prototype : array array_diff_uassoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Computes the difference of arrays with additional index check which is performed by a + * user supplied callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(10 => 10, 12 => 12); + +$input_arrays = array( + 'decimal indexed' => array(10 => 10, -17 => -17), + 'octal indexed' => array( 012 => 10, -011 => -011,), + 'hexa indexed' => array(0xA => 10, -0x7 => -0x7 ), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_uassoc($input_array, $value, "strcasecmp") ); + var_dump( array_diff_uassoc($value, $input_array, "strcasecmp") ); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_uassoc() : usage variation *** + +--decimal indexed-- +array(1) { + [12]=> + int(12) +} +array(1) { + [-17]=> + int(-17) +} + +--octal indexed-- +array(1) { + [12]=> + int(12) +} +array(1) { + [-9]=> + int(-9) +} + +--hexa indexed-- +array(1) { + [12]=> + int(12) +} +array(1) { + [-7]=> + int(-7) +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_basic.phpt b/ext/standard/tests/array/array_diff_ukey_basic.phpt new file mode 100644 index 0000000..7ac309a --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_diff_ukey() : Basic test. +--FILE-- +<?php +/* +* proto array array_diff_ukey ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($key1, $key2) { + if ($key1 == $key2) return 0; + else if ($key1 > $key2) return 1; + else return -1; +} +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_diff_ukey($array1, $array2, 'key_compare_func')); +?> +--EXPECT-- +array(2) { + ["red"]=> + int(2) + ["purple"]=> + int(4) +} diff --git a/ext/standard/tests/array/array_diff_ukey_error.phpt b/ext/standard/tests/array/array_diff_ukey_error.phpt new file mode 100644 index 0000000..1a73bdf --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_error.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_diff_ukey() function : error conditions +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : error conditions ***\n"; + +// Initialize +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$extra_arg = 10; + +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +//Test array_diff_ukey with one more than the expected number of arguments +echo "\n-- Testing array_diff_ukey() function with more than expected no. of arguments --\n"; +var_dump( array_diff_ukey($array1, $array2, 'key_compare_func', $extra_arg) ); + +// Testing array_diff_ukey with one less than the expected number of arguments +echo "\n-- Testing array_diff_ukey() function with less than expected no. of arguments --\n"; +var_dump( array_diff_ukey($array1, $array2) ); + +// Testing array_diff_ukey with one less than the expected number of arguments +echo "\n-- Testing array_diff_ukey() function with no arguments --\n"; +var_dump( array_diff_ukey() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : error conditions *** + +-- Testing array_diff_ukey() function with more than expected no. of arguments -- + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Testing array_diff_ukey() function with less than expected no. of arguments -- + +Warning: array_diff_ukey(): at least 3 parameters are required, 2 given in %s on line %d +NULL + +-- Testing array_diff_ukey() function with no arguments -- + +Warning: array_diff_ukey(): at least 3 parameters are required, 0 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation1.phpt b/ext/standard/tests/array/array_diff_ukey_variation1.phpt new file mode 100644 index 0000000..9a849e0 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation1.phpt @@ -0,0 +1,318 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($value, $array2, 'key_compare_func') ); + var_dump( array_diff_ukey($value, $array2, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +--int 0-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation10.phpt b/ext/standard/tests/array/array_diff_ukey_variation10.phpt new file mode 100644 index 0000000..0d93928 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation10.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing non-existing function name to callback +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//function name within double quotes +var_dump( array_diff_ukey($array1, $array1, "unknown_function") ); + +//function name within single quotes +var_dump( array_diff_ukey($array1, $array1, 'unknown_function') ); + +//function name without quotes +var_dump( array_diff_ukey($array1, $array1, unknown_function) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Notice: Use of undefined constant unknown_function - assumed 'unknown_function' in %s on line %d + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation11.phpt b/ext/standard/tests/array/array_diff_ukey_variation11.phpt new file mode 100644 index 0000000..0ad3fba --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation11.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing class without string to callback (Handling fatal error) +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. User supplied function is used for comparing the keys. This function is like array_udiff() but works on the keys instead of the values. The associativity is preserved. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array2 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array(1, 2, 3, 4, 5); + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + +class classWithoutToString +{ +} + +$value = new classWithoutToString(); + +var_dump( array_diff_ukey($array1, $array2, $value) ); +var_dump( array_diff_ukey($array1, $array2, $array3, $value) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** +Error: 2 - array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given, %s(%d) +NULL +Error: 2 - array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given, %s(%d) +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_ukey_variation2.phpt b/ext/standard/tests/array/array_diff_ukey_variation2.phpt new file mode 100644 index 0000000..19eab4d --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation2.phpt @@ -0,0 +1,322 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialize function arguments not being substituted (if any) +$array1 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + + +//Initialize key_comp_func of type callback +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, + +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($array1, $value, 'key_compare_func') ); + var_dump( array_diff_ukey($array1, $value, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +--int 0-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_diff_ukey(): Argument #2 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation3.phpt b/ext/standard/tests/array/array_diff_ukey_variation3.phpt new file mode 100644 index 0000000..f7a2ea8 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation3.phpt @@ -0,0 +1,240 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing unexpected values to third optional argument +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array2 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) { + return 0; + } + return ($key1 > $key2)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for key_comp_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($array1, $array2, $value, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +--int 0-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_ukey(): Argument #3 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation4.phpt b/ext/standard/tests/array/array_diff_ukey_variation4.phpt new file mode 100644 index 0000000..a0399c2 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation4.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing unexpected values to callback argument +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array2 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array(1, 2, 3, 4, 5); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($array1, $array2, $value) ); + var_dump( array_diff_ukey($array1, $array2, $array3, $value) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +--int 0-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--resource-- + +Warning: array_diff_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_diff_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation5.phpt b/ext/standard/tests/array/array_diff_ukey_variation5.phpt new file mode 100644 index 0000000..fb0c97a --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation5.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing multi-dimensional array +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. User supplied function is used for comparing the keys. This function is like array_udiff() but works on the keys instead of the values. The associativity is preserved. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array( + + 'first' => array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 => 'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); + +echo "\n-- Testing array_diff_ukey() function with multi dimensional array --\n"; +var_dump( array_diff_ukey($array1, $array2, 'strcasecmp') ); +var_dump( array_diff_ukey($array2, $array1, 'strcasecmp') ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +-- Testing array_diff_ukey() function with multi dimensional array -- +array(1) { + ["third"]=> + array(1) { + [0]=> + string(4) "zero" + } +} +array(1) { + ["fourth"]=> + array(1) { + [2]=> + string(3) "two" + } +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation6.phpt b/ext/standard/tests/array/array_diff_ukey_variation6.phpt new file mode 100644 index 0000000..2188a88 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation6.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing integer indexed array +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(-07 => '-07', 0xA => '0xA'); + +$input_arrays = array( + 'decimal indexed' => array(10 => '10', '-17' => '-17'), + 'octal indexed' => array(-011 => '-011', 012 => '012'), + 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ), +); + +function key_compare_func($key1, $key2) +{ + return strcasecmp($key1, $key2); +} + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($value, $input_array, 'key_compare_func') ); + var_dump( array_diff_ukey($input_array, $value, 'key_compare_func') ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +--decimal indexed-- +array(1) { + [-17]=> + string(3) "-17" +} +array(1) { + [-7]=> + string(3) "-07" +} + +--octal indexed-- +array(1) { + [-9]=> + string(4) "-011" +} +array(1) { + [-7]=> + string(3) "-07" +} + +--hexa indexed-- +array(1) { + [18]=> + string(4) "0x12" +} +array(1) { + [10]=> + string(3) "0xA" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation7.phpt b/ext/standard/tests/array/array_diff_ukey_variation7.phpt new file mode 100644 index 0000000..88888d6 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation7.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing float indexed array +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 10 => '10', -10 => '-10', 20 =>'20'); +$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5', -30.5 => '-30.5'); + +function key_compare_func($key1, $key2) +{ + return strcasecmp($key1, $key2); +} + +echo "\n-- Testing array_diff_ukey() function with float indexed array --\n"; + +var_dump( array_diff_ukey($float_indx_array, $input_array, 'key_compare_func') ); +var_dump( array_diff_ukey($input_array, $float_indx_array, 'key_compare_func') ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +-- Testing array_diff_ukey() function with float indexed array -- +array(1) { + [-30]=> + string(5) "-30.5" +} +array(2) { + [-10]=> + string(3) "-10" + [20]=> + string(2) "20" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation8.phpt b/ext/standard/tests/array/array_diff_ukey_variation8.phpt new file mode 100644 index 0000000..9bb9498 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing boolean indexed array +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +function key_compare_func($key1, $key2) +{ + return strcasecmp($key1, $key2); +} + +echo "\n-- Testing array_diff_ukey() function with boolean indexed array --\n"; + +var_dump( array_diff_ukey($boolean_indx_array, $input_array, 'key_compare_func') ); +var_dump( array_diff_ukey($input_array, $boolean_indx_array, 'key_compare_func') ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +-- Testing array_diff_ukey() function with boolean indexed array -- +array(0) { +} +array(3) { + [-10]=> + string(3) "-10" + ["true"]=> + int(1) + ["false"]=> + int(0) +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_ukey_variation9.phpt b/ext/standard/tests/array/array_diff_ukey_variation9.phpt new file mode 100644 index 0000000..024f5f4 --- /dev/null +++ b/ext/standard/tests/array/array_diff_ukey_variation9.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_diff_ukey() function : usage variation - Passing null,unset and undefined variable indexed array +--FILE-- +<?php +/* Prototype : array array_diff_ukey(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_ukey() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(10 => '10', "" => 'empty'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_diff_ukey($value, $input_array, 'strcasecmp') ); + var_dump( array_diff_ukey($input_array, $value, 'strcasecmp') ); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing array_diff_ukey() : usage variation *** + +--null indexed-- +array(0) { +} +array(1) { + [10]=> + string(2) "10" +} + +--undefined indexed-- +array(0) { +} +array(1) { + [10]=> + string(2) "10" +} + +--unset indexed-- +array(0) { +} +array(1) { + [10]=> + string(2) "10" +} +===DONE=== diff --git a/ext/standard/tests/array/array_diff_variation1.phpt b/ext/standard/tests/array/array_diff_variation1.phpt new file mode 100644 index 0000000..f9a34b0 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation1.phpt @@ -0,0 +1,208 @@ +--TEST-- +Test array_diff() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff by passing non array values in place of $arr1 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_diff +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_diff($input, $array)); + $iterator++; +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + +-- Iteration 1 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 26 -- +Warning: array_diff(): Argument #1 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation10.phpt b/ext/standard/tests/array/array_diff_variation10.phpt new file mode 100644 index 0000000..9442b94 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation10.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_diff() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test behaviour of array_diff() function with binary input + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + + +$array1 = array( b"1", + b"hello", + "world", + "str1" => "hello", + "str2" => "world"); + +$array2 = array( b"1" => 'hello', + b"world", + "hello", + 'test'); + +var_dump(array_diff($array1, $array2)); +var_dump(array_diff($array2, $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +array(1) { + [0]=> + string(1) "1" +} +array(1) { + [4]=> + string(4) "test" +} +Done diff --git a/ext/standard/tests/array/array_diff_variation2.phpt b/ext/standard/tests/array/array_diff_variation2.phpt new file mode 100644 index 0000000..be68c40 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation2.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_diff() function : usage variations - unexpected values for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff by passing non array values in place of $arr2 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array = array(1, 2, 3); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // binary data +/*21*/ b"binary", + (binary)"binary", + + // object data +/*23*/ new classA(), + + // undefined data +/*24*/ @$undefined_var, + + // unset data +/*25*/ @$unset_var, + + // resource variable +/*26*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_diff +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_diff($array, $input)); + $iterator++; +}; +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + +-- Iteration 1 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 26 -- +Warning: array_diff(): Argument #2 is not an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation3.phpt b/ext/standard/tests/array/array_diff_variation3.phpt new file mode 100644 index 0000000..84f73fd --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation3.phpt @@ -0,0 +1,190 @@ +--TEST-- +Test array_diff() function : usage variations - array with different data types as values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff() compares indexed arrays containing different + * data types as values in place of $arr1 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$array = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get heredoc +$heredoc = <<<END +This is a heredoc +END; + +//array of values to iterate over +$values = array( + +/*1*/"empty array" => array(), + +/*2*/ +"int" => array( + // int data + 0, + 1, + 12345, + -2345), + +/*3*/ +"float" => array( + // float data + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + +/*4*/ +"null" => array( + // null data + NULL, + null), + +/*5*/ +"boolean" => array( + // boolean data + true, + false, + TRUE, + FALSE), + +/*6*/ +"empty" => array( + // empty data + "", + ''), + +/*7*/ +"string" => array( + // string data + "string", + 'string', + $heredoc), + +/*8*/ +"binary" => array( + // binary data + b"binary", + (binary)"binary"), + +/*9*/ +"undefined" => array( + // undefined data + @$undefined_var), + +/*10*/ +"unset" => array( + // unset data + @$unset_var) +); + +// loop through each element of the array for arr1 +$iterator = 1; +foreach($values as $value) { + echo "\n Iteration: $iterator \n"; + var_dump( array_diff($value, $array) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + + Iteration: 1 +array(0) { +} + + Iteration: 2 +array(3) { + [0]=> + int(0) + [2]=> + int(12345) + [3]=> + int(-2345) +} + + Iteration: 3 +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + + Iteration: 4 +array(2) { + [0]=> + NULL + [1]=> + NULL +} + + Iteration: 5 +array(2) { + [1]=> + bool(false) + [3]=> + bool(false) +} + + Iteration: 6 +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + + Iteration: 7 +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(17) "This is a heredoc" +} + + Iteration: 8 +array(2) { + [0]=> + string(6) "binary" + [1]=> + string(6) "binary" +} + + Iteration: 9 +array(1) { + [0]=> + NULL +} + + Iteration: 10 +array(1) { + [0]=> + NULL +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation4.phpt b/ext/standard/tests/array/array_diff_variation4.phpt new file mode 100644 index 0000000..75b01ad --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation4.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test array_diff() function : usage variations - array with different data types as values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff() compares indexed arrays containing different + * data types as values in place of $arr2 + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +// Initialise function arguments not being substituted (if any) +$array = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get heredoc +$heredoc = <<<END +This is a heredoc +END; + +//array of values to iterate over +$values = array( + +/*1*/"empty array" => array(), + +/*2*/ +"int" => array( + // int data + 0, + 1, + 12345, + -2345), + +/*3*/ +"float" => array( + // float data + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5), + +/*4*/ +"null" => array( + // null data + NULL, + null), + +/*5*/ +"boolean" => array( + // boolean data + true, + false, + TRUE, + FALSE), + +/*6*/ +"empty" => array( + // empty data + "", + ''), + +/*7*/ +"string" => array( + // string data + "string", + 'string', + $heredoc), + +/*8*/ +"binary" => array( + // binary data + b"binary", + (binary)"binary"), + +/*9*/ +"undefined" => array( + // undefined data + @$undefined_var), + +/*10*/ +"unset" => array( + // unset data + @$unset_var) +); + +// loop through each element of the array for $arr2 +$iterator = 1; +foreach($values as $value) { + echo "\n Iteration: $iterator \n"; + var_dump( array_diff($array, $value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** + + Iteration: 1 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 2 +array(1) { + [1]=> + int(2) +} + + Iteration: 3 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 4 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 5 +array(1) { + [1]=> + int(2) +} + + Iteration: 6 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 7 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 8 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 9 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + + Iteration: 10 +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation5.phpt b/ext/standard/tests/array/array_diff_variation5.phpt new file mode 100644 index 0000000..cb6b5d3 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation5.phpt @@ -0,0 +1,119 @@ +--TEST-- +Test array_diff() function : usage variations - comparing integers, float +and string array values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff compares integers, floats and strings + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$arr_int = array(1, 2, 3); +$arr_float = array(1.00, 2.00, 3.00); +$arr_int_str = array('1', '2', '3'); +$arr_float_str = array('1.00', '2.00', '3.00'); + +print "-- Compare integers and floats: --\n"; +var_dump(array_diff($arr_int, $arr_float)); +var_dump(array_diff($arr_float, $arr_int)); + + +print "-- Compare integers and strings containing an integers: --\n"; +var_dump(array_diff($arr_int, $arr_int_str)); +var_dump(array_diff($arr_int_str, $arr_int)); + +print "-- Compare integers and strings containing floats: --\n"; +var_dump(array_diff($arr_int, $arr_float_str)); +var_dump(array_diff($arr_float_str, $arr_int)); + +print "-- Compare floats and strings containing integers: --\n"; + +var_dump(array_diff($arr_float, $arr_int_str)); +var_dump(array_diff($arr_int_str, $arr_float)); + +print "-- Compare floats and strings containing floats: --\n"; +var_dump(array_diff($arr_float, $arr_float_str)); +var_dump(array_diff($arr_float_str, $arr_float)); + +print "-- Compare strings containing integers and strings containing floats: --\n"; +var_dump(array_diff($arr_int_str, $arr_float_str)); +var_dump(array_diff($arr_float_str, $arr_int_str)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Compare integers and floats: -- +array(0) { +} +array(0) { +} +-- Compare integers and strings containing an integers: -- +array(0) { +} +array(0) { +} +-- Compare integers and strings containing floats: -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +-- Compare floats and strings containing integers: -- +array(0) { +} +array(0) { +} +-- Compare floats and strings containing floats: -- +array(3) { + [0]=> + float(1) + [1]=> + float(2) + [2]=> + float(3) +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +-- Compare strings containing integers and strings containing floats: -- +array(3) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" + [2]=> + string(1) "3" +} +array(3) { + [0]=> + string(4) "1.00" + [1]=> + string(4) "2.00" + [2]=> + string(4) "3.00" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation6.phpt b/ext/standard/tests/array/array_diff_variation6.phpt new file mode 100644 index 0000000..8ea84bb --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation6.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_diff() function : usage variations - array containing duplicate keys and values +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test that array_diff behaves as expected for comparing: + * 1. the order of the array + * 2. duplicate values + * 3. duplicate key names + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array_index = array('a', 'b', 'c', 0 => 'd', 'b'); //duplicate key (0), duplicate value (b) +$array_assoc = array ('2' => 'c', //same key=>value pair, different order + '1' => 'b', + '0' => 'a', + 'b' => '3', //key and value from array_index swapped + 'c' => 2); //same as above, using integer + +var_dump(array_diff($array_index, $array_assoc)); +var_dump(array_diff($array_assoc, $array_index)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +array(1) { + [0]=> + string(1) "d" +} +array(3) { + [0]=> + string(1) "a" + ["b"]=> + string(1) "3" + ["c"]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation7.phpt b/ext/standard/tests/array/array_diff_variation7.phpt new file mode 100644 index 0000000..c53cbb3 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation7.phpt @@ -0,0 +1,95 @@ +--TEST-- +Test array_diff() function : usage variations - arrays containing referenced variables +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are not + * present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff compares arrays that + * 1. Contain referenced variables + * 2. Have been referenced to each other + */ + +echo "*** Testing array_diff() : usage variations ***\n"; +$a = 'a'; + +$arr1 = array ("&$a", 'b', 'c'); +$arr2 = array (1, 2, 3); +echo "-- Basic Comparison --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + +$a = 1; + +echo "-- \$a changed --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + + +$arr2 = &$arr1; +echo "-- Arrays referenced to each other --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + + +$arr1 = array('x', 'y', 'z'); +echo "-- \$arr1 changed --\n"; +var_dump(array_diff($arr1, $arr2)); +var_dump(array_diff($arr2, $arr1)); + + +echo "Done"; +?> + +--EXPECTF-- + +*** Testing array_diff() : usage variations *** +-- Basic Comparison -- +array(3) { + [0]=> + string(2) "&a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- $a changed -- +array(3) { + [0]=> + string(2) "&a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- Arrays referenced to each other -- +array(0) { +} +array(0) { +} +-- $arr1 changed -- +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_diff_variation8.phpt b/ext/standard/tests/array/array_diff_variation8.phpt new file mode 100644 index 0000000..99f9614 --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation8.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_diff() function : usage variations - associative arrays contianing different data types +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of $arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test array_diff() with associative arrays containing different data types as values + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array = array('a' => '1', 'b' => '2', 'c' => '3'); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// associative arrays with different values +$inputs = array ( + // arrays with integer values +/*1*/ array('0' => 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("float1" => 2.3333, "float2" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), + + // arrays with string values +/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_diff($array, $input) ); + var_dump( array_diff($input, $array) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Iteration 1 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- Iteration 2 -- +array(1) { + ["c"]=> + string(1) "3" +} +array(0) { +} +-- Iteration 3 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(2) { + ["float1"]=> + float(2.3333) + ["float2"]=> + float(2.3333) +} +-- Iteration 4 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(1.2) +} +-- Iteration 5 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" + [3]=> + string(6) " Hello" +} +-- Iteration 6 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(7) "\tHello" +} +-- Iteration 7 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(3) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" + [2]=> + string(11) "Hello world" +} +-- Iteration 8 -- +array(3) { + ["a"]=> + string(1) "1" + ["b"]=> + string(1) "2" + ["c"]=> + string(1) "3" +} +array(5) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) + [12]=> + object(classA)#%d (0) { + } + [13]=> + resource(%d) of type (stream) +} +Done diff --git a/ext/standard/tests/array/array_diff_variation9.phpt b/ext/standard/tests/array/array_diff_variation9.phpt new file mode 100644 index 0000000..1bf1f1c --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation9.phpt @@ -0,0 +1,156 @@ +--TEST-- +Test array_diff() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_diff(array $arr1, array $arr2 [, array ...]) + * Description: Returns the entries of arr1 that have values which are + * not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +/* + * Test how array_diff() compares multidimensional arrays + */ + +echo "*** Testing array_diff() : usage variations ***\n"; + +$array1 = array('sub_array1' => array (1, 2, 3), + 'sub_array2' => array ('a', 'b', 'c')); +$array2 = array('sub_arraya' => array (1, 3, 5), + 'sub_arrayb' => array ('a', 'z', 'y')); + +echo "-- Compare two 2-D arrays --\n"; +var_dump(array_diff($array1, $array2)); +var_dump(array_diff($array2, $array1)); + +echo "\n-- Compare subarrays from two 2-D arrays --\n"; +var_dump(array_diff($array1['sub_array1'], $array2['sub_arraya'])); +var_dump(array_diff($array2['sub_arraya'], $array1['sub_array1'])); + +var_dump(array_diff($array1['sub_array2'], $array2['sub_arrayb'])); +var_dump(array_diff($array2['sub_arrayb'], $array1['sub_array1'])); + +echo "\n-- Compare a subarray from one 2-D array and one 2-D array --\n"; +var_dump(array_diff($array1['sub_array1'], $array2)); +var_dump(array_diff($array1, $array2['sub_arraya'])); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_diff() : usage variations *** +-- Compare two 2-D arrays -- + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d +array(0) { +} + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d +array(0) { +} + +-- Compare subarrays from two 2-D arrays -- +array(1) { + [1]=> + int(2) +} +array(1) { + [2]=> + int(5) +} +array(2) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" +} +array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "z" + [2]=> + string(1) "y" +} + +-- Compare a subarray from one 2-D array and one 2-D array -- + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d + +Notice: Array to string conversion in %sarray_diff_variation9.php on line %d +array(2) { + ["sub_array1"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["sub_array2"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill.phpt b/ext/standard/tests/array/array_fill.phpt new file mode 100644 index 0000000..1de7c31 --- /dev/null +++ b/ext/standard/tests/array/array_fill.phpt @@ -0,0 +1,366 @@ +--TEST-- +basic array_fill test +--FILE-- +<?php +$array1 = array(0.0, 1, 2.5); +$array2 = array(TRUE, FALSE, NULL, "d", "e", "f"); +foreach($array1 as $start) +{ + foreach($array1 as $num) + { + foreach($array2 as $value) + { + echo '==========================='."\n"; + echo 'start: '.$start.' num: '.$num.' value: '.$value."\n"; + $output = array_fill($start, $num, $value); + var_dump($output); + } + } +} +echo '== Done =='; +?> +===============Done==================== +--EXPECTF-- +=========================== +start: 0 num: 0 value: 1 + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 0 num: 0 value: + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 0 num: 0 value: + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 0 num: 0 value: d + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 0 num: 0 value: e + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 0 num: 0 value: f + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 0 num: 1 value: 1 +array(1) { + [0]=> + bool(true) +} +=========================== +start: 0 num: 1 value: +array(1) { + [0]=> + bool(false) +} +=========================== +start: 0 num: 1 value: +array(1) { + [0]=> + NULL +} +=========================== +start: 0 num: 1 value: d +array(1) { + [0]=> + string(1) "d" +} +=========================== +start: 0 num: 1 value: e +array(1) { + [0]=> + string(1) "e" +} +=========================== +start: 0 num: 1 value: f +array(1) { + [0]=> + string(1) "f" +} +=========================== +start: 0 num: 2.5 value: 1 +array(2) { + [0]=> + bool(true) + [1]=> + bool(true) +} +=========================== +start: 0 num: 2.5 value: +array(2) { + [0]=> + bool(false) + [1]=> + bool(false) +} +=========================== +start: 0 num: 2.5 value: +array(2) { + [0]=> + NULL + [1]=> + NULL +} +=========================== +start: 0 num: 2.5 value: d +array(2) { + [0]=> + string(1) "d" + [1]=> + string(1) "d" +} +=========================== +start: 0 num: 2.5 value: e +array(2) { + [0]=> + string(1) "e" + [1]=> + string(1) "e" +} +=========================== +start: 0 num: 2.5 value: f +array(2) { + [0]=> + string(1) "f" + [1]=> + string(1) "f" +} +=========================== +start: 1 num: 0 value: 1 + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 1 num: 0 value: + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 1 num: 0 value: + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 1 num: 0 value: d + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 1 num: 0 value: e + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 1 num: 0 value: f + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 1 num: 1 value: 1 +array(1) { + [1]=> + bool(true) +} +=========================== +start: 1 num: 1 value: +array(1) { + [1]=> + bool(false) +} +=========================== +start: 1 num: 1 value: +array(1) { + [1]=> + NULL +} +=========================== +start: 1 num: 1 value: d +array(1) { + [1]=> + string(1) "d" +} +=========================== +start: 1 num: 1 value: e +array(1) { + [1]=> + string(1) "e" +} +=========================== +start: 1 num: 1 value: f +array(1) { + [1]=> + string(1) "f" +} +=========================== +start: 1 num: 2.5 value: 1 +array(2) { + [1]=> + bool(true) + [2]=> + bool(true) +} +=========================== +start: 1 num: 2.5 value: +array(2) { + [1]=> + bool(false) + [2]=> + bool(false) +} +=========================== +start: 1 num: 2.5 value: +array(2) { + [1]=> + NULL + [2]=> + NULL +} +=========================== +start: 1 num: 2.5 value: d +array(2) { + [1]=> + string(1) "d" + [2]=> + string(1) "d" +} +=========================== +start: 1 num: 2.5 value: e +array(2) { + [1]=> + string(1) "e" + [2]=> + string(1) "e" +} +=========================== +start: 1 num: 2.5 value: f +array(2) { + [1]=> + string(1) "f" + [2]=> + string(1) "f" +} +=========================== +start: 2.5 num: 0 value: 1 + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 2.5 num: 0 value: + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 2.5 num: 0 value: + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 2.5 num: 0 value: d + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 2.5 num: 0 value: e + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 2.5 num: 0 value: f + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +=========================== +start: 2.5 num: 1 value: 1 +array(1) { + [2]=> + bool(true) +} +=========================== +start: 2.5 num: 1 value: +array(1) { + [2]=> + bool(false) +} +=========================== +start: 2.5 num: 1 value: +array(1) { + [2]=> + NULL +} +=========================== +start: 2.5 num: 1 value: d +array(1) { + [2]=> + string(1) "d" +} +=========================== +start: 2.5 num: 1 value: e +array(1) { + [2]=> + string(1) "e" +} +=========================== +start: 2.5 num: 1 value: f +array(1) { + [2]=> + string(1) "f" +} +=========================== +start: 2.5 num: 2.5 value: 1 +array(2) { + [2]=> + bool(true) + [3]=> + bool(true) +} +=========================== +start: 2.5 num: 2.5 value: +array(2) { + [2]=> + bool(false) + [3]=> + bool(false) +} +=========================== +start: 2.5 num: 2.5 value: +array(2) { + [2]=> + NULL + [3]=> + NULL +} +=========================== +start: 2.5 num: 2.5 value: d +array(2) { + [2]=> + string(1) "d" + [3]=> + string(1) "d" +} +=========================== +start: 2.5 num: 2.5 value: e +array(2) { + [2]=> + string(1) "e" + [3]=> + string(1) "e" +} +=========================== +start: 2.5 num: 2.5 value: f +array(2) { + [2]=> + string(1) "f" + [3]=> + string(1) "f" +} +== Done =================Done==================== diff --git a/ext/standard/tests/array/array_fill_basic.phpt b/ext/standard/tests/array/array_fill_basic.phpt new file mode 100644 index 0000000..8623f8e --- /dev/null +++ b/ext/standard/tests/array/array_fill_basic.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test array_fill() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array array_fill(int start_key, int num, mixed val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_fill() : basic functionality ***\n"; + +// calling the array_fill with all possible valid values for 'val' argument +$start_key = 0 ; +$num = 2; +$heredoc = <<<HERE_DOC +Hello +HERE_DOC; + +// array of possible valid values for 'val' arugment +$values = array ( + + /* 1 */ NULL, + 0, + 1, + /* 4 */ 1.5, + 'hi', + "hi", + /* 7 */ $heredoc + +); + +$counter = 1; +for($i = 0; $i < count($values); $i ++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$i]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : basic functionality *** +-- Iteration 1 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} +-- Iteration 2 -- +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- Iteration 3 -- +array(2) { + [0]=> + int(1) + [1]=> + int(1) +} +-- Iteration 4 -- +array(2) { + [0]=> + float(1.5) + [1]=> + float(1.5) +} +-- Iteration 5 -- +array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" +} +-- Iteration 6 -- +array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" +} +-- Iteration 7 -- +array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "Hello" +} +Done diff --git a/ext/standard/tests/array/array_fill_error.phpt b/ext/standard/tests/array/array_fill_error.phpt new file mode 100644 index 0000000..1671632 --- /dev/null +++ b/ext/standard/tests/array/array_fill_error.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_fill() function : error conditions +--FILE-- +<?php +/* Prototype : proto array array_fill(int start_key, int num, mixed val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c +*/ + + +echo "*** Testing array_fill() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_fill() function with Zero arguments --\n"; +var_dump( array_fill() ); + +// More than expected number of arguments +echo "-- Testing array_fill() function with more than expected no. of arguments --\n"; +$start_key = 0; +$num = 2; +$val = 1; +$extra_arg = 10; +var_dump( array_fill($start_key,$num,$val, $extra_arg) ); + +// Less than the expected number of arguments +echo "-- Testing array_fill() function with less than expected no. of arguments --\n"; +$start_key = 0; +$num = 2; +var_dump( array_fill($start_key,$num) ); + +//calling array_fill with negative values for 'num' parameter +$num = -1; +var_dump( array_fill($start_key,$num,$val) ); + +//callin array_fill with 'num' equal to zero value +$num = 0; +var_dump( array_fill($start_key,$num,$val) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : error conditions *** +-- Testing array_fill() function with Zero arguments -- + +Warning: array_fill() expects exactly 3 parameters, 0 given in %s on line %d +NULL +-- Testing array_fill() function with more than expected no. of arguments -- + +Warning: array_fill() expects exactly 3 parameters, 4 given in %s on line %d +NULL +-- Testing array_fill() function with less than expected no. of arguments -- + +Warning: array_fill() expects exactly 3 parameters, 2 given in %s on line %d +NULL + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_fill_keys.phpt b/ext/standard/tests/array/array_fill_keys.phpt new file mode 100644 index 0000000..b4d5168 --- /dev/null +++ b/ext/standard/tests/array/array_fill_keys.phpt @@ -0,0 +1,44 @@ +--TEST-- +basic array_fill_keys test +--INI-- +precision=14 +--FILE-- +<?php + var_dump(array_fill_keys('test', 1)); + var_dump(array_fill_keys(array(), 1)); + var_dump(array_fill_keys(array('foo', 'bar'), NULL)); + var_dump(array_fill_keys(array('5', 'foo', 10, 1.23), 123)); + var_dump(array_fill_keys(array('test', TRUE, 10, 100), '')); +?> +--EXPECTF-- + +Warning: array_fill_keys() expects parameter 1 to be array, string given in %s on line %d +NULL +array(0) { +} +array(2) { + ["foo"]=> + NULL + ["bar"]=> + NULL +} +array(4) { + [5]=> + int(123) + ["foo"]=> + int(123) + [10]=> + int(123) + ["1.23"]=> + int(123) +} +array(4) { + ["test"]=> + string(0) "" + [1]=> + string(0) "" + [10]=> + string(0) "" + [100]=> + string(0) "" +} diff --git a/ext/standard/tests/array/array_fill_keys_error.phpt b/ext/standard/tests/array/array_fill_keys_error.phpt new file mode 100644 index 0000000..31a03e7 --- /dev/null +++ b/ext/standard/tests/array/array_fill_keys_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_fill_keys() function : error conditions +--FILE-- +<?php +/* Prototype : proto array array_fill_keys(array keys, mixed val) + * Description: Create an array using the elements of the first parameter as keys each initialized to val + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_fill_keys() : error conditions ***\n"; + +$keys = array(1, 2); +$val = 1; +$extra_arg = 10; + +echo "\n-- Testing array_fill_keys() function with more than expected no. of arguments --\n"; +var_dump( array_fill_keys($keys, $val, $extra_arg) ); + +echo "\n-- Testing array_fill_keys() function with less than expected no. of arguments --\n"; +var_dump( array_fill_keys($keys) ); + +echo "\n-- Testing array_fill_keys() function with no argumets --\n"; +var_dump( array_fill_keys() ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill_keys() : error conditions *** + +-- Testing array_fill_keys() function with more than expected no. of arguments -- + +Warning: array_fill_keys() expects exactly 2 parameters, 3 given in %sarray_fill_keys_error.php on line %d +NULL + +-- Testing array_fill_keys() function with less than expected no. of arguments -- + +Warning: array_fill_keys() expects exactly 2 parameters, 1 given in %sarray_fill_keys_error.php on line %d +NULL + +-- Testing array_fill_keys() function with no argumets -- + +Warning: array_fill_keys() expects exactly 2 parameters, 0 given in %sarray_fill_keys_error.php on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_fill_keys_variation1.phpt b/ext/standard/tests/array/array_fill_keys_variation1.phpt new file mode 100644 index 0000000..9fab89d --- /dev/null +++ b/ext/standard/tests/array/array_fill_keys_variation1.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--FILE-- +<?php +/* Prototype : proto array array_fill_keys(array keys, mixed val) + * Description: Create an array using the elements of the first parameter as keys each initialized to val + * Source code: ext/standard/array.c + * Alias to functions: + */ + + +echo "*** Testing array_fill_keys() : parameter variations ***\n"; + +$nullVal = null; +$simpleStr = "simple"; +$fp = fopen(__FILE__, "r"); +$emptyArr = array(); +$bool = false; +$float = 2.4; + +class classA { + public function __toString() { return "Class A object"; } +} +$obj = new classA(); + + +echo "\n-- Testing array_fill_keys() function with empty arguments --\n"; +var_dump( array_fill_keys($emptyArr, $nullVal) ); + +echo "\n-- Testing array_fill_keys() function with keyed array --\n"; +$keyedArray = array("two" => 2, "strk1" => "strv1", 4, $simpleStr); +var_dump( array_fill_keys($keyedArray, $simpleStr) ); + +echo "\n-- Testing array_fill_keys() function with mixed array --\n"; +$mixedArray = array($fp, $obj, $simpleStr, $emptyArr, 2, $bool, $float); +var_dump( array_fill_keys($mixedArray, $simpleStr) ); + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with empty arguments -- +array(0) { +} + +-- Testing array_fill_keys() function with keyed array -- +array(4) { + [2]=> + string(6) "simple" + ["strv1"]=> + string(6) "simple" + [4]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" +} + +-- Testing array_fill_keys() function with mixed array -- + +Notice: Array to string conversion in %sarray_fill_keys_variation1.php on line %d +array(7) { + ["Resource id #%d"]=> + string(6) "simple" + ["Class A object"]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" + ["Array"]=> + string(6) "simple" + [2]=> + string(6) "simple" + [""]=> + string(6) "simple" + ["2.4"]=> + string(6) "simple" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill_keys_variation2.phpt b/ext/standard/tests/array/array_fill_keys_variation2.phpt new file mode 100644 index 0000000..4f3681a --- /dev/null +++ b/ext/standard/tests/array/array_fill_keys_variation2.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--FILE-- +<?php +/* Prototype : proto array array_fill_keys(array keys, mixed val) + * Description: Create an array using the elements of the first parameter as keys each initialized to val + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* Testing with reference types for the arguments */ + +echo "*** Testing array_fill_keys() : parameter variations ***\n"; + +$nullVal = null; +$simpleStr = "simple"; +$refString = &$simpleStr; +$fp = fopen(__FILE__, "r"); +$emptyArr = array(); +$bool = false; +$float = 2.4; + +class classA { + public function __toString() { return "Class A object"; } +} +$obj = new classA(); + + +echo "\n-- Testing array_fill_keys() function with reference value --\n"; +$keyedArray = array("one", "two"); +var_dump(array_fill_keys($keyedArray, $refString)); + +echo "\n-- Testing array_fill_keys() function with reference keys --\n"; +$refKeys = array("one", &$simpleStr); +$res = array_fill_keys($refKeys, $simpleStr); +var_dump($res); +$simpleStr = "bob"; +var_dump($res); + + +echo "\n-- Testing array_fill_keys() function with reference array input --\n"; +$newArray = array("one", "two"); +$refArray = &$newArray; +var_dump(array_fill_keys($refArray, $simpleStr)); + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with reference value -- +array(2) { + ["one"]=> + string(6) "simple" + ["two"]=> + string(6) "simple" +} + +-- Testing array_fill_keys() function with reference keys -- +array(2) { + ["one"]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" +} +array(2) { + ["one"]=> + string(6) "simple" + ["simple"]=> + string(6) "simple" +} + +-- Testing array_fill_keys() function with reference array input -- +array(2) { + ["one"]=> + string(3) "bob" + ["two"]=> + string(3) "bob" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill_keys_variation3.phpt b/ext/standard/tests/array/array_fill_keys_variation3.phpt new file mode 100644 index 0000000..5c57823 --- /dev/null +++ b/ext/standard/tests/array/array_fill_keys_variation3.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--FILE-- +<?php +/* Prototype : proto array array_fill_keys(array keys, mixed val) + * Description: Create an array using the elements of the first parameter as keys each initialized to val + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* Testing with unexpected argument types */ + +echo "*** Testing array_fill_keys() : parameter variations ***\n"; + +$simpleStr = "simple"; +$fp = fopen(__FILE__, "r"); +$bool = false; +$float = 2.4; +$array = array("one", "two"); +$nullVal = null; + +echo "\n-- Testing array_fill_keys() function with both wrong arguments --\n"; +var_dump( array_fill_keys($bool, $float) ); + +echo "\n-- Testing array_fill_keys() function with unusual second arguments --\n"; +var_dump( array_fill_keys($array, $fp) ); + +echo "\n-- Testing array_fill_keys() function with mixed array --\n"; +var_dump( array_fill_keys($nullVal, $simpleStr) ); + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with both wrong arguments -- + +Warning: array_fill_keys() expects parameter 1 to be array, boolean given in %sarray_fill_keys_variation3.php on line %d +NULL + +-- Testing array_fill_keys() function with unusual second arguments -- +array(2) { + ["one"]=> + resource(%d) of type (stream) + ["two"]=> + resource(%d) of type (stream) +} + +-- Testing array_fill_keys() function with mixed array -- + +Warning: array_fill_keys() expects parameter 1 to be array, null given in %sarray_fill_keys_variation3.php on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill_keys_variation4.phpt b/ext/standard/tests/array/array_fill_keys_variation4.phpt new file mode 100644 index 0000000..209443d --- /dev/null +++ b/ext/standard/tests/array/array_fill_keys_variation4.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_fill_keys() function : variation of parameter +--FILE-- +<?php +/* Prototype : proto array array_fill_keys(array keys, mixed val) + * Description: Create an array using the elements of the first parameter as keys each initialized to val + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* Testing with unexpected argument types */ + +echo "*** Testing array_fill_keys() : parameter variations ***\n"; + +$fp = fopen(__FILE__, "r"); +$bool = false; +$float = 2.4; +$array = array("one"); +$nullVal = null; +$unset_var = 10; +unset ($unset_var); + + +class classA { + public function __toString() { return "Class A object"; } +} +$obj = new classA(); + +echo "\n-- Testing array_fill_keys() function with float --\n"; +var_dump( array_fill_keys($array, $float) ); + +echo "\n-- Testing array_fill_keys() function with null --\n"; +var_dump( array_fill_keys($array, $nullVal) ); + +echo "\n-- Testing array_fill_keys() function with object --\n"; +var_dump( array_fill_keys($array, $obj) ); + +echo "\n-- Testing array_fill_keys() function with boolean --\n"; +var_dump( array_fill_keys($array, $bool) ); + +echo "\n-- Testing array_fill_keys() function with resource --\n"; +var_dump( array_fill_keys($array, $fp) ); + +echo "\n-- Testing array_fill_keys() function with unset var --\n"; +var_dump( array_fill_keys($array, $unset_var) ); + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill_keys() : parameter variations *** + +-- Testing array_fill_keys() function with float -- +array(1) { + ["one"]=> + float(2.4) +} + +-- Testing array_fill_keys() function with null -- +array(1) { + ["one"]=> + NULL +} + +-- Testing array_fill_keys() function with object -- +array(1) { + ["one"]=> + object(classA)#%d (0) { + } +} + +-- Testing array_fill_keys() function with boolean -- +array(1) { + ["one"]=> + bool(false) +} + +-- Testing array_fill_keys() function with resource -- +array(1) { + ["one"]=> + resource(%d) of type (stream) +} + +-- Testing array_fill_keys() function with unset var -- + +Notice: Undefined variable: unset_var in %sarray_fill_keys_variation4.php on line %d +array(1) { + ["one"]=> + NULL +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_fill_object.phpt b/ext/standard/tests/array/array_fill_object.phpt new file mode 100644 index 0000000..86773b1 --- /dev/null +++ b/ext/standard/tests/array/array_fill_object.phpt @@ -0,0 +1,434 @@ +--TEST-- +Test array_fill() function : usage variations - various object values for 'val' argument +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.4.0', '>=')) die('skip ZendEngine 2.3 or below needed'); ?> +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing various object values for 'val' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$num = 2; + +// class without a member +class Test +{ +} + +//class with public member, static member , constant and consturctor to initialize the public member +class Test1 +{ + const test1_constant = "test1"; + public static $test1_static = 0; + public $member1; + var $var1 = 30; + var $var2; + + function __construct($value1 , $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} + +// child class which inherits parent class test1 +class Child_test1 extends Test1 +{ + public $member2; + + function __construct($value1 , $value2 , $value3) + { + parent::__construct($value1 , $value2); + $this->member2 = $value3; + } +} + +//class with private member, static member, constant and constructor to initialize the private member +class Test2 +{ + const test2_constant = "test2"; + public static $test2_static = 0; + private $member1; + var $var1 = 30; + var $var2; + + function __construct($value1 , $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} + +// child class which inherits parent class test2 +class Child_test2 extends Test2 +{ + private $member1; + + function __construct($value1 , $value2 , $value3) + { + parent::__construct($value1 , $value2); + $this->member1 = $value3; + } +} + +// class with protected member, static member, constant and consturctor to initialize the protected member +class Test3 +{ + const test3_constant = "test3"; + public static $test3_static = 0; + protected $member1; + var $var1 = 30; + var $var2; + + function __construct($value1 , $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} + +// child class which inherits parent class test3 +class Child_test3 extends Test3 +{ + protected $member1; + + function __construct($value1 , $value2 , $value3) + { + parent::__construct($value1 , $value2); + $this->member1 = $value3; + } +} + +// class with public, private, protected members, static, constant members and constructor to initialize all the members +class Test4 +{ + const test4_constant = "test4"; + public static $test4_static = 0; + public $member1; + private $member2; + protected $member3; + + function __construct($value1 , $value2 , $value3) + { + $this->member1 = $value1; + $this->member2 = $value2; + $this->member3 = $value3; + } +} + +// child class which inherits parent class test4 +class Child_test4 extends Test4 +{ + var $var1; + + function __construct($value1 , $value2 , $value3 , $value4) + { + parent::__construct($value1 , $value2 , $value3); + $this->var1 = $value4; + } +} + +// abstract class with public, private, protected members +abstract class AbstractClass +{ + public $member1; + private $member2; + protected $member3; + var $var1 = 30; + + abstract protected function display(); +} + +// implement abstract 'AbstractClass' class +class ConcreteClass1 extends AbstractClass +{ + protected function display() + { + echo "class name is ConcreteClass1 \n"; + } +} + + +// declarationn of the interface 'iTemplate' +interface iTemplate +{ + public function display(); +} + +// implement the interface 'iTemplate' +class Template1 implements iTemplate +{ + public function display() + { + echo "class name is Template1\n"; + } +} + +//array of object values for 'val' argument +$objects = array( + + /* 1 */ new Test(), + new Test1(100 , 101), + new Child_test1(100 , 101 , 102), + new Test2(100 , 101), + /* 5 */ new Child_test2(100 , 101 , 102), + new Test3(100 , 101), + new Child_test3(100 , 101 , 102), + new Test4( 100 , 101 , 102), + new Child_test4(100 , 101 , 102 , 103), + new ConcreteClass1(), + /* 11 */ new Template1() +); + +// loop through each element of the array for 'val' argument +// check the working of array_fill() +echo "--- Testing array_fill() with different object values for 'val' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($objects); $index ++) +{ + echo "-- Iteration $counter --\n"; + $val = $objects[$index]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different object values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + object(Test)#%d (0) { + } + [1]=> + object(Test)#%d (0) { + } +} +-- Iteration 2 -- +array(2) { + [0]=> + object(Test1)#%d (3) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test1)#%d (3) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + object(Child_test1)#%d (4) { + ["member2"]=> + int(102) + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test1)#%d (4) { + ["member2"]=> + int(102) + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + object(Test2)#%d (3) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test2)#%d (3) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 5 -- +array(2) { + [0]=> + object(Child_test2)#%d (4) { + ["member1":"Child_test2":private]=> + int(102) + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test2)#%d (4) { + ["member1":"Child_test2":private]=> + int(102) + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 6 -- +array(2) { + [0]=> + object(Test3)#%d (3) { + ["member1":protected]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test3)#%d (3) { + ["member1":protected]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 7 -- +array(2) { + [0]=> + object(Child_test3)#%d (3) { + ["member1":protected]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test3)#%d (3) { + ["member1":protected]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 8 -- +array(2) { + [0]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } + [1]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } +} +-- Iteration 9 -- +array(2) { + [0]=> + object(Child_test4)#%d (4) { + ["var1"]=> + int(103) + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } + [1]=> + object(Child_test4)#%d (4) { + ["var1"]=> + int(103) + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } +} +-- Iteration 10 -- +array(2) { + [0]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2":"AbstractClass":private]=> + NULL + ["member3":protected]=> + NULL + ["var1"]=> + int(30) + } + [1]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2":"AbstractClass":private]=> + NULL + ["member3":protected]=> + NULL + ["var1"]=> + int(30) + } +} +-- Iteration 11 -- +array(2) { + [0]=> + object(Template1)#%d (0) { + } + [1]=> + object(Template1)#%d (0) { + } +} +Done diff --git a/ext/standard/tests/array/array_fill_object_2_4.phpt b/ext/standard/tests/array/array_fill_object_2_4.phpt new file mode 100644 index 0000000..fb81797 --- /dev/null +++ b/ext/standard/tests/array/array_fill_object_2_4.phpt @@ -0,0 +1,434 @@ +--TEST-- +Test array_fill() function : usage variations - various object values for 'val' argument +--SKIPIF-- +<?php if (version_compare(zend_version(), '2.4.0', '<')) die('skip ZendEngine 2.4 needed'); ?> +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing various object values for 'val' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$num = 2; + +// class without a member +class Test +{ +} + +//class with public member, static member , constant and consturctor to initialize the public member +class Test1 +{ + const test1_constant = "test1"; + public static $test1_static = 0; + public $member1; + var $var1 = 30; + var $var2; + + function __construct($value1 , $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} + +// child class which inherits parent class test1 +class Child_test1 extends Test1 +{ + public $member2; + + function __construct($value1 , $value2 , $value3) + { + parent::__construct($value1 , $value2); + $this->member2 = $value3; + } +} + +//class with private member, static member, constant and constructor to initialize the private member +class Test2 +{ + const test2_constant = "test2"; + public static $test2_static = 0; + private $member1; + var $var1 = 30; + var $var2; + + function __construct($value1 , $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} + +// child class which inherits parent class test2 +class Child_test2 extends Test2 +{ + private $member1; + + function __construct($value1 , $value2 , $value3) + { + parent::__construct($value1 , $value2); + $this->member1 = $value3; + } +} + +// class with protected member, static member, constant and consturctor to initialize the protected member +class Test3 +{ + const test3_constant = "test3"; + public static $test3_static = 0; + protected $member1; + var $var1 = 30; + var $var2; + + function __construct($value1 , $value2) + { + $this->member1 = $value1; + $this->var2 = $value2; + } +} + +// child class which inherits parent class test3 +class Child_test3 extends Test3 +{ + protected $member1; + + function __construct($value1 , $value2 , $value3) + { + parent::__construct($value1 , $value2); + $this->member1 = $value3; + } +} + +// class with public, private, protected members, static, constant members and constructor to initialize all the members +class Test4 +{ + const test4_constant = "test4"; + public static $test4_static = 0; + public $member1; + private $member2; + protected $member3; + + function __construct($value1 , $value2 , $value3) + { + $this->member1 = $value1; + $this->member2 = $value2; + $this->member3 = $value3; + } +} + +// child class which inherits parent class test4 +class Child_test4 extends Test4 +{ + var $var1; + + function __construct($value1 , $value2 , $value3 , $value4) + { + parent::__construct($value1 , $value2 , $value3); + $this->var1 = $value4; + } +} + +// abstract class with public, private, protected members +abstract class AbstractClass +{ + public $member1; + private $member2; + protected $member3; + var $var1 = 30; + + abstract protected function display(); +} + +// implement abstract 'AbstractClass' class +class ConcreteClass1 extends AbstractClass +{ + protected function display() + { + echo "class name is ConcreteClass1 \n"; + } +} + + +// declarationn of the interface 'iTemplate' +interface iTemplate +{ + public function display(); +} + +// implement the interface 'iTemplate' +class Template1 implements iTemplate +{ + public function display() + { + echo "class name is Template1\n"; + } +} + +//array of object values for 'val' argument +$objects = array( + + /* 1 */ new Test(), + new Test1(100 , 101), + new Child_test1(100 , 101 , 102), + new Test2(100 , 101), + /* 5 */ new Child_test2(100 , 101 , 102), + new Test3(100 , 101), + new Child_test3(100 , 101 , 102), + new Test4( 100 , 101 , 102), + new Child_test4(100 , 101 , 102 , 103), + new ConcreteClass1(), + /* 11 */ new Template1() +); + +// loop through each element of the array for 'val' argument +// check the working of array_fill() +echo "--- Testing array_fill() with different object values for 'val' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($objects); $index ++) +{ + echo "-- Iteration $counter --\n"; + $val = $objects[$index]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different object values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + object(Test)#%d (0) { + } + [1]=> + object(Test)#%d (0) { + } +} +-- Iteration 2 -- +array(2) { + [0]=> + object(Test1)#%d (3) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test1)#%d (3) { + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + object(Child_test1)#%d (4) { + ["member2"]=> + int(102) + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test1)#%d (4) { + ["member2"]=> + int(102) + ["member1"]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + object(Test2)#%d (3) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test2)#%d (3) { + ["member1":"Test2":private]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 5 -- +array(2) { + [0]=> + object(Child_test2)#%d (4) { + ["member1":"Child_test2":private]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + ["member1":"Test2":private]=> + int(100) + } + [1]=> + object(Child_test2)#%d (4) { + ["member1":"Child_test2":private]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + ["member1":"Test2":private]=> + int(100) + } +} +-- Iteration 6 -- +array(2) { + [0]=> + object(Test3)#%d (3) { + ["member1":protected]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Test3)#%d (3) { + ["member1":protected]=> + int(100) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 7 -- +array(2) { + [0]=> + object(Child_test3)#%d (3) { + ["member1":protected]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } + [1]=> + object(Child_test3)#%d (3) { + ["member1":protected]=> + int(102) + ["var1"]=> + int(30) + ["var2"]=> + int(101) + } +} +-- Iteration 8 -- +array(2) { + [0]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } + [1]=> + object(Test4)#%d (3) { + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } +} +-- Iteration 9 -- +array(2) { + [0]=> + object(Child_test4)#%d (4) { + ["var1"]=> + int(103) + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } + [1]=> + object(Child_test4)#%d (4) { + ["var1"]=> + int(103) + ["member1"]=> + int(100) + ["member2":"Test4":private]=> + int(101) + ["member3":protected]=> + int(102) + } +} +-- Iteration 10 -- +array(2) { + [0]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2":"AbstractClass":private]=> + NULL + ["member3":protected]=> + NULL + ["var1"]=> + int(30) + } + [1]=> + object(ConcreteClass1)#%d (4) { + ["member1"]=> + NULL + ["member2":"AbstractClass":private]=> + NULL + ["member3":protected]=> + NULL + ["var1"]=> + int(30) + } +} +-- Iteration 11 -- +array(2) { + [0]=> + object(Template1)#%d (0) { + } + [1]=> + object(Template1)#%d (0) { + } +} +Done diff --git a/ext/standard/tests/array/array_fill_variation1.phpt b/ext/standard/tests/array/array_fill_variation1.phpt new file mode 100644 index 0000000..e2d0b6f --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation1.phpt @@ -0,0 +1,247 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'start_key' argument +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : proto array array_fill(int start_key, int num, mixed val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected value for 'start_key' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$num = 2; +$val = 100; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'start_key' argument +$values = array( + + // float values + /* 1 */ 10.5, + -10.5, + 12.3456789000e10, + 12.34567890006E-10, + .5, + + // array values + /* 6 */ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null values + /* 11 */ NULL, + null, + + // boolean values + /* 13 */ true, + false, + TRUE, + FALSE, + + // empty string + /* 17 */ "", + '', + + // string values + /* 19 */ "string", + 'string', + + // objects + /* 21 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var, + + // resource variable + /* 24 */ $fp +); + +// loop through each element of the array for start_key +// check the working of array_fill() +echo "--- Testing array_fill() with different values for 'start_key' arg ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $start_key = $values[$index]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter ++; +} + +// close the resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'start_key' arg --- +-- Iteration 1 -- +array(2) { + [10]=> + int(100) + [11]=> + int(100) +} +-- Iteration 2 -- +array(2) { + [-10]=> + int(100) + [0]=> + int(100) +} +-- Iteration 3 -- +array(2) { + [-1097262584]=> + int(100) + [0]=> + int(100) +} +-- Iteration 4 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 5 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 6 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 7 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 8 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 9 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 10 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 11 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 12 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 13 -- +array(2) { + [1]=> + int(100) + [2]=> + int(100) +} +-- Iteration 14 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 15 -- +array(2) { + [1]=> + int(100) + [2]=> + int(100) +} +-- Iteration 16 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 17 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 18 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 19 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 20 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 21 -- + +Warning: array_fill() expects parameter 1 to be long, object given in %sarray_fill_variation1.php on line %d +NULL +-- Iteration 22 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 23 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 24 -- + +Warning: array_fill() expects parameter 1 to be long, resource given in %sarray_fill_variation1.php on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_fill_variation1_64bit.phpt b/ext/standard/tests/array/array_fill_variation1_64bit.phpt new file mode 100644 index 0000000..650e97d --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation1_64bit.phpt @@ -0,0 +1,247 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'start_key' argument +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php +/* Prototype : proto array array_fill(int start_key, int num, mixed val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected value for 'start_key' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$num = 2; +$val = 100; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'start_key' argument +$values = array( + + // float values + /* 1 */ 10.5, + -10.5, + 12.3456789000e10, + 12.34567890006E-10, + .5, + + // array values + /* 6 */ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null values + /* 11 */ NULL, + null, + + // boolean values + /* 13 */ true, + false, + TRUE, + FALSE, + + // empty string + /* 17 */ "", + '', + + // string values + /* 19 */ "string", + 'string', + + // objects + /* 21 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + @$unset_var, + + // resource variable + /* 24 */ $fp +); + +// loop through each element of the array for start_key +// check the working of array_fill() +echo "--- Testing array_fill() with different values for 'start_key' arg ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $start_key = $values[$index]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter ++; +} + +// close the resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'start_key' arg --- +-- Iteration 1 -- +array(2) { + [10]=> + int(100) + [11]=> + int(100) +} +-- Iteration 2 -- +array(2) { + [-10]=> + int(100) + [0]=> + int(100) +} +-- Iteration 3 -- +array(2) { + [123456789000]=> + int(100) + [123456789001]=> + int(100) +} +-- Iteration 4 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 5 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 6 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_fill() expects parameter 1 to be long, array given in %s on line %d +NULL +-- Iteration 11 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 12 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 13 -- +array(2) { + [1]=> + int(100) + [2]=> + int(100) +} +-- Iteration 14 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 15 -- +array(2) { + [1]=> + int(100) + [2]=> + int(100) +} +-- Iteration 16 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 17 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_fill() expects parameter 1 to be long, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_fill() expects parameter 1 to be long, object given in %s on line %d +NULL +-- Iteration 22 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 23 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 24 -- + +Warning: array_fill() expects parameter 1 to be long, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_fill_variation2.phpt b/ext/standard/tests/array/array_fill_variation2.phpt new file mode 100644 index 0000000..9e9df29 --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation2.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'num' argument +--FILE-- +<?php +/* Prototype : proto array array_fill(int start_key, int num, mixed val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected values for 'num' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$val = 100; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'num' argument +$values = array( + + // float values + /* 1 */ 2.5, + -2.5, + 0.5e1, + 0.5E-1, + .5, + + // array values + /* 6 */ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null values + /* 11 */ NULL, + null, + + // boolean values + /* 13 */ true, + false, + TRUE, + FALSE, + + // empty string + /* 17 */ "", + '', + + // string values + /* 19 */ "string", + 'string', + + // objects + /* 21 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + /* 24 */ @$unset_var, + +); + +// loop through each element of the array for num +// check the working of array_fill +echo "--- Testing array_fill() with different values for 'num' arg ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $num = $values[$index]; + + var_dump( array_fill($start_key,$num,$val) ); + + $counter ++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'num' arg --- +-- Iteration 1 -- +array(2) { + [0]=> + int(100) + [1]=> + int(100) +} +-- Iteration 2 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 3 -- +array(5) { + [0]=> + int(100) + [1]=> + int(100) + [2]=> + int(100) + [3]=> + int(100) + [4]=> + int(100) +} +-- Iteration 4 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_fill() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 13 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 14 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 15 -- +array(1) { + [0]=> + int(100) +} +-- Iteration 16 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_fill() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_fill() expects parameter 2 to be long, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_fill(): Number of elements must be positive in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_fill_variation3.phpt b/ext/standard/tests/array/array_fill_variation3.phpt new file mode 100644 index 0000000..4a463a9 --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation3.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test array_fill() function : usage variations - unexpected values for 'val' argument +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different unexpected values for 'val' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$num = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define a class +class test +{ + var $t = 10; + function __toString() + { + return "testObject"; + } +} + + +//array of different values for 'val' argument +$values = array( + // empty string + /* 1 */ "", + '', + // objects + /* 3 */ new test(), + + // undefined variable + @$undefined_var, + + // unset variable + /* 5 */ @$unset_var, +); + +// loop through each element of the array for 'val' argument +// check the working of array_fill() +echo "--- Testing array_fill() with different values for 'val' argument ---\n"; +$counter = 1; +for($index = 0; $index < count($values); $index ++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$index]; + + var_dump( array_fill($start_key , $num , $val) ); + + $counter++; +} + +echo"Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +-- Iteration 2 -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} +-- Iteration 3 -- +array(2) { + [0]=> + object(test)#%d (1) { + ["t"]=> + int(10) + } + [1]=> + object(test)#%d (1) { + ["t"]=> + int(10) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} +-- Iteration 5 -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} +Done diff --git a/ext/standard/tests/array/array_fill_variation4.phpt b/ext/standard/tests/array/array_fill_variation4.phpt new file mode 100644 index 0000000..9e1f50c --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation4.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test array_fill() function : usage variations - using return value of array_fill for 'val' argument +--FILE-- +<?php +/* Prototype : proto array array_fill(int start_key, int num, mixed val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* passing array_fill() as the 'val' argument in array_fill() function */ + +echo "*** Testing array_fill() : variation ***\n"; + +$start_key = 0; +$num = 2; +$heredoc = <<<HERE_DOC +Hello +HERE_DOC; + +// array of possible valid values for 'val' arugment +$values = array ( + + /* 1 */ NULL, + 0, + 1, + /* 4 */ 1.0, + 'hi', + "hi", + /* 7 */ $heredoc +); + +echo "*** Filling 2 dimensional array with all basic valid values ***\n"; +$counter = 1; +for($i =0; $i < count($values); $i ++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$i]; + + var_dump( array_fill($start_key,$num,array_fill($start_key,$num,$val)) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : variation *** +*** Filling 2 dimensional array with all basic valid values *** +-- Iteration 1 -- +array(2) { + [0]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } +} +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(0) + [1]=> + int(0) + } + [1]=> + array(2) { + [0]=> + int(0) + [1]=> + int(0) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(1) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(1) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [0]=> + float(1) + [1]=> + float(1) + } + [1]=> + array(2) { + [0]=> + float(1) + [1]=> + float(1) + } +} +-- Iteration 5 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } + [1]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } +} +-- Iteration 6 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } + [1]=> + array(2) { + [0]=> + string(2) "hi" + [1]=> + string(2) "hi" + } +} +-- Iteration 7 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "Hello" + } + [1]=> + array(2) { + [0]=> + string(5) "Hello" + [1]=> + string(5) "Hello" + } +} +Done diff --git a/ext/standard/tests/array/array_fill_variation5.phpt b/ext/standard/tests/array/array_fill_variation5.phpt new file mode 100644 index 0000000..10fcc9c --- /dev/null +++ b/ext/standard/tests/array/array_fill_variation5.phpt @@ -0,0 +1,291 @@ +--TEST-- +Test array_fill() function : usage variations - different types of array values for 'val' argument +--FILE-- +<?php +/* Prototype : array array_fill(int $start_key, int $num, mixed $val) + * Description: Create an array containing num elements starting with index start_key each initialized to val + * Source code: ext/standard/array.c + */ + +/* + * testing array_fill() by passing different types of array values for 'val' argument + */ + +echo "*** Testing array_fill() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$start_key = 0; +$num = 2; + + +//array of different types of array values for 'val' argument +$values = array( + + /* 1 */ array(), + array(1 , 2 , 3 , 4), + array(1 => "Hi" , 2 => "Hello"), + array("Saffron" , "White" , "Green"), + /* 5 */ array('color' => 'red' , 'item' => 'pen'), + array( 'color' => 'red' , 2 => 'green ' ), + array("colour" => "red" , "item" => "pen"), + array( TRUE => "red" , FALSE => "green" ), + array( true => "red" , FALSE => "green" ), + /* 10 */ array( 1 => "Hi" , "color" => "red" , 'item' => 'pen'), + array( NULL => "Hi", '1' => "Hello" , "1" => "Green"), + array( ""=>1, "color" => "green"), + /* 13 */ array('Saffron' , 'White' , 'Green') +); + +// loop through each element of the values array for 'val' argument +// check the working of array_fill() +echo "--- Testing array_fill() with different types of array values for 'val' argument ---\n"; +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + $val = $values[$i]; + + var_dump( array_fill($start_key , $num , $val) ); + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_fill() : usage variations *** +--- Testing array_fill() with different types of array values for 'val' argument --- +-- Iteration 1 -- +array(2) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } +} +-- Iteration 2 -- +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(2) "Hi" + [2]=> + string(5) "Hello" + } + [1]=> + array(2) { + [1]=> + string(2) "Hi" + [2]=> + string(5) "Hello" + } +} +-- Iteration 4 -- +array(2) { + [0]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } + [1]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } +} +-- Iteration 5 -- +array(2) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +-- Iteration 6 -- +array(2) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + [2]=> + string(6) "green " + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + [2]=> + string(6) "green " + } +} +-- Iteration 7 -- +array(2) { + [0]=> + array(2) { + ["colour"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["colour"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +-- Iteration 8 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } + [1]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } +} +-- Iteration 9 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } + [1]=> + array(2) { + [1]=> + string(3) "red" + [0]=> + string(5) "green" + } +} +-- Iteration 10 -- +array(2) { + [0]=> + array(3) { + [1]=> + string(2) "Hi" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(3) { + [1]=> + string(2) "Hi" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +-- Iteration 11 -- +array(2) { + [0]=> + array(2) { + [""]=> + string(2) "Hi" + [1]=> + string(5) "Green" + } + [1]=> + array(2) { + [""]=> + string(2) "Hi" + [1]=> + string(5) "Green" + } +} +-- Iteration 12 -- +array(2) { + [0]=> + array(2) { + [""]=> + int(1) + ["color"]=> + string(5) "green" + } + [1]=> + array(2) { + [""]=> + int(1) + ["color"]=> + string(5) "green" + } +} +-- Iteration 13 -- +array(2) { + [0]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } + [1]=> + array(3) { + [0]=> + string(7) "Saffron" + [1]=> + string(5) "White" + [2]=> + string(5) "Green" + } +} +Done diff --git a/ext/standard/tests/array/array_filter.phpt b/ext/standard/tests/array/array_filter.phpt new file mode 100644 index 0000000..94f8e39 --- /dev/null +++ b/ext/standard/tests/array/array_filter.phpt @@ -0,0 +1,93 @@ +--TEST-- +basic array_filter test +--FILE-- +<?php +function odd($var) +{ + return($var & 1); +} + +function even($var) +{ + return(!($var & 1)); +} + +$array1 = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5); +$array2 = array(6, 7, 8, 9, 10, 11, 12, 0); +$array3 = array(TRUE, FALSE, NULL); + +echo "Odd :\n"; +var_dump(array_filter($array1, "odd")); +var_dump(array_filter($array2, "odd")); +var_dump(array_filter($array3, "odd")); +echo "Even:\n"; +var_dump(array_filter($array1, "even")); +var_dump(array_filter($array2, "even")); +var_dump(array_filter($array3, "even")); + +var_dump(array_filter(array())); +var_dump(array_filter(array(), array())); +var_dump(array_filter("", null)); +var_dump(array_filter($array1, 1)); + +echo '== DONE =='; +?> +--EXPECTF-- +Odd : +array(3) { + ["a"]=> + int(1) + ["c"]=> + int(3) + ["e"]=> + int(5) +} +array(3) { + [1]=> + int(7) + [3]=> + int(9) + [5]=> + int(11) +} +array(1) { + [0]=> + bool(true) +} +Even: +array(2) { + ["b"]=> + int(2) + ["d"]=> + int(4) +} +array(5) { + [0]=> + int(6) + [2]=> + int(8) + [4]=> + int(10) + [6]=> + int(12) + [7]=> + int(0) +} +array(2) { + [1]=> + bool(false) + [2]=> + NULL +} +array(0) { +} + +Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_filter() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +== DONE == diff --git a/ext/standard/tests/array/array_filter_basic.phpt b/ext/standard/tests/array/array_filter_basic.phpt new file mode 100644 index 0000000..daec07b --- /dev/null +++ b/ext/standard/tests/array/array_filter_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_filter() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + + +echo "*** Testing array_filter() : basic functionality ***\n"; + + +// Initialise all required variables +$input = array(1, 2, 3, 0, -1); // 0 will be considered as FALSE and removed in default callback + +/* Callback function + * Prototype : bool even(array $input) + * Parameters : $input - input array each element of which will be checked in function even() + * Return type : boolean - true if element is even and false otherwise + * Description : This function takes array as parameter and checks for each element of array. + * It returns true if the element is even number else returns false + */ +function even($input) +{ + return ($input % 2 == 0); +} + +// with all possible arguments +var_dump( array_filter($input,"even") ); + +// with default arguments +var_dump( array_filter($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : basic functionality *** +array(2) { + [1]=> + int(2) + [3]=> + int(0) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [4]=> + int(-1) +} +Done diff --git a/ext/standard/tests/array/array_filter_error.phpt b/ext/standard/tests/array/array_filter_error.phpt new file mode 100644 index 0000000..20e89aa --- /dev/null +++ b/ext/standard/tests/array/array_filter_error.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_filter() function : error conditions +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_filter() : error conditions ***\n"; + +// zero arguments +echo "-- Testing array_filter() function with Zero arguments --"; +var_dump( array_filter() ); + +$input = array(0, 1, 2, 3, 5); +/* callback function + * Prototype : bool odd(array $input) + * Parameters : $input - array for which each elements should be checked into the function + * Return Type : bool - true if element is odd and returns false otherwise + * Description : Function takes array as input and checks for its each elements. +*/ +function odd($input) +{ + return ($input % 2 != 0); +} +$extra_arg = 10; + +// with one more than the expected number of arguments +echo "-- Testing array_filter() function with more than expected no. of arguments --"; +var_dump( array_filter($input, "odd", $extra_arg) ); + +// with incorrect callback function +echo "-- Testing array_filter() function with incorrect callback --"; +var_dump( array_filter($input, "even") ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : error conditions *** +-- Testing array_filter() function with Zero arguments -- +Warning: array_filter() expects at least 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_filter() function with more than expected no. of arguments -- +Warning: array_filter() expects at most 2 parameters, 3 given in %s on line %d +NULL +-- Testing array_filter() function with incorrect callback -- +Warning: array_filter() expects parameter 2 to be a valid callback, function 'even' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_filter_object.phpt b/ext/standard/tests/array/array_filter_object.phpt new file mode 100644 index 0000000..de782fe --- /dev/null +++ b/ext/standard/tests/array/array_filter_object.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test array_filter() function : object functionality +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* This file uses 'input' array with different types of objects and passes + * it to array_filter() to test object functionality + * i.e. object of simple class with members and functions + * object of empty class + * object of child class extending abstract class + * object of class containing static member + */ + +echo "*** Testing array_filter() : object functionality ***\n"; + +// simple class with members - variable and method +class SimpleClass +{ + public $var1 = 10; + public function check() { + return $var1; + } +} + +// class without members +class EmptyClass +{ +} + +// abstract class +abstract class AbstractClass +{ + protected $var2 = 5; + abstract function emptyMethod(); +} + +// class deriving above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public function emptyMethod() { + echo "defined in child"; + } +} + +// class with final method +class FinalClass +{ + private $var4; + final function finalMethod() { + echo 'This can not be overloaded'; + } +} + +// class with static members +class StaticClass +{ + static $var5 = 5; + public static function staticMethod() { + echo 'this is static method'; + } +} + +// Callback function which returns always true +function always_true($input) +{ + return true; +} + +// Callback function which returns always false +function always_false($input) +{ + return false; +} + +// 'input' array containing objects as elements +$input = array( + new SimpleClass(), + new EmptyClass(), + new ChildClass(), + new FinalClass(), + new StaticClass() +); + + +// with default callback +var_dump( array_filter($input) ); + +// with always_true callback function +var_dump( array_filter($input, "always_true") ); + +// with always_false callback function +var_dump( array_filter($input, "always_false") ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : object functionality *** +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + [3]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(10) + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + [3]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [4]=> + object(StaticClass)#%d (0) { + } +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation1.phpt b/ext/standard/tests/array/array_filter_variation1.phpt new file mode 100644 index 0000000..108b3dc --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation1.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test array_filter() function : usage variations - Unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* Passing different scalar and nonscalar values for 'input' argument +*/ +echo "*** Testing array_filter() : usage variations - unexpected values for 'input'***\n"; + +/* Callback function + * Prototype : bool always_true(array $input) + * Parameters : array for which each elements needs to be used in function + * Return value : Returns true for each element + * Discription : function applied to each element of the passed array and returns true + */ +function always_true($input) +{ + return true; +} + + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// class definition for object variable +class MyClass +{ + public function __toString() + { + return "object"; + } +} + +// resource variable +$fp = fopen(__FILE__, 'r'); + +// different values for 'input' argument +$input_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of the array for input +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_filter($input_values[$count],"always_true") ); +}; + +// closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - unexpected values for 'input'*** +-- Iteration 1 -- + +Warning: array_filter() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_filter() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_filter() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_filter() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_filter() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_filter() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_filter() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_filter() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_filter() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_filter() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_filter() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_filter() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_filter() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_filter() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_filter() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_filter() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_filter() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_filter() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_filter() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_filter() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_filter() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_filter() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_filter() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_filter_variation2.phpt b/ext/standard/tests/array/array_filter_variation2.phpt new file mode 100644 index 0000000..1aa262b --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation2.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test array_filter() function : usage variations - Unexpected values for 'callback' function argument +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* Passing different scalar and nonscalar values in place of 'callback' argument +*/ +echo "*** Testing array_filter() : usage variations - unexpected values for 'callback' function***\n"; + +// Initialise variables +$input = array('value1', 'value2', 'value3', 'value4'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// class definition for object variable +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +// resource variable +$fp = fopen(__FILE__, 'r'); + +// different scalar and nonscalar values in place of callback function +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + + // object data +/*25*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*28*/ @$unset_var, +); + +// loop through each element of the 'values' for callback +for($count = 0; $count < count($values); $count++) { + echo "-- Iteration ".($count + 1)." --"; + var_dump( array_filter($input, $values[$count]) ); +}; + +// closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - unexpected values for 'callback' function*** +-- Iteration 1 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 2 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 3 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 4 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 5 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 6 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 7 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 8 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 9 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 10 -- +Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 11 -- +Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 12 -- +Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 13 -- +Warning: array_filter() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL +-- Iteration 14 -- +Warning: array_filter() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL +-- Iteration 15 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 16 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 17 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 18 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 19 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 20 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 21 -- +Warning: array_filter() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 22 -- +Warning: array_filter() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 23 -- +Warning: array_filter() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL +-- Iteration 24 -- +Warning: array_filter() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL +-- Iteration 25 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 26 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 27 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 28 -- +Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_filter_variation3.phpt b/ext/standard/tests/array/array_filter_variation3.phpt new file mode 100644 index 0000000..e22697a --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation3.phpt @@ -0,0 +1,216 @@ +--TEST-- +Test array_filter() function : usage variations - Different types of array for 'input' argument +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of array as 'input' argument. +*/ + +// callback function returning always false +function always_false($input) +{ + return false; +} + +// callback function returning always true +function always_true($input) +{ + return true; +} + +echo "*** Testing array_filter() : usage variations - different types of array for 'input' argument***\n"; + +// different types of 'input' array +$input_values = array( + array(0, 1, 2, -1, 034, 0X4A), // integer values + array(0.0, 1.2, 1.2e3, 1.2e-3), // float values + array('value1', "value2", '', " ", ""), // string values + array(true, false, TRUE, FALSE), // bool values + array(null, NULL), // null values + array(1 => 'one', 'zero' => 0, -2 => "value"), //associative array + array("one" => 1, null => 'null', 5.2 => "float", true => 1, "" => 'empty'), // associative array with different keys + array(1 => 'one', 2, "key" => 'value') // combinition of associative and non-associative array + +); + +// loop through each element of 'input' with default callback +for($count = 0; $count < count($input_values); $count++) +{ + echo "-- Iteration ".($count + 1). " --\n"; + var_dump( array_filter($input_values[$count]) ); + var_dump( array_filter($input_values[$count], 'always_true') ); + var_dump( array_filter($input_values[$count], 'always_false') ); +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - different types of array for 'input' argument*** +-- Iteration 1 -- +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(-1) + [4]=> + int(28) + [5]=> + int(74) +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(-1) + [4]=> + int(28) + [5]=> + int(74) +} +array(0) { +} +-- Iteration 2 -- +array(3) { + [1]=> + float(1.2) + [2]=> + float(1200) + [3]=> + float(0.0012) +} +array(4) { + [0]=> + float(0) + [1]=> + float(1.2) + [2]=> + float(1200) + [3]=> + float(0.0012) +} +array(0) { +} +-- Iteration 3 -- +array(3) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + [3]=> + string(1) " " +} +array(5) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + [2]=> + string(0) "" + [3]=> + string(1) " " + [4]=> + string(0) "" +} +array(0) { +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(true) + [2]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(2) { + [0]=> + NULL + [1]=> + NULL +} +array(0) { +} +-- Iteration 6 -- +array(2) { + [1]=> + string(3) "one" + [-2]=> + string(5) "value" +} +array(3) { + [1]=> + string(3) "one" + ["zero"]=> + int(0) + [-2]=> + string(5) "value" +} +array(0) { +} +-- Iteration 7 -- +array(4) { + ["one"]=> + int(1) + [""]=> + string(5) "empty" + [5]=> + string(5) "float" + [1]=> + int(1) +} +array(4) { + ["one"]=> + int(1) + [""]=> + string(5) "empty" + [5]=> + string(5) "float" + [1]=> + int(1) +} +array(0) { +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + int(2) + ["key"]=> + string(5) "value" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + int(2) + ["key"]=> + string(5) "value" +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation4.phpt b/ext/standard/tests/array/array_filter_variation4.phpt new file mode 100644 index 0000000..7f028b1 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation4.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_filter() function : usage variations - Different types of 'callback' function +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of callback functions to array_filter() +* with parameters and return +* without parameter and with return +* with parameter and without return +* without parameter and without return +*/ + +echo "*** Testing array_filter() : usage variation - different 'callback' functions***\n"; + +// Initialize variables +$input = array(0, -1, 2, 3.4E-3, 'hello', "value", "key" => 4, 'null' => NULL); + +// callback function without parameters and with return value +function callback1() +{ + return 1; +} +echo "-- Callback function without parameter and with return --\n"; +var_dump( array_filter($input, "callback1") ); + +// callback function with parameter and without return value +function callback2($input) +{ +} +echo "-- Callback funciton with parameter and without return --\n"; +var_dump( array_filter($input, "callback2") ); + + +// callback function without parameter and without return value +function callback3() +{ +} +echo "-- Callback function without parameter and return --\n"; +var_dump( array_filter($input, "callback3") ); + +// callback function with parameter and with return value +function callback4($input) +{ + if($input > 0 ) { + return true; + } + else { + return false; + } +} +echo "-- Callback function with parameter and return --\n"; +var_dump( array_filter($input, "callback4") ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variation - different 'callback' functions*** +-- Callback function without parameter and with return -- +array(8) { + [0]=> + int(0) + [1]=> + int(-1) + [2]=> + int(2) + [3]=> + float(0.0034) + [4]=> + string(5) "hello" + [5]=> + string(5) "value" + ["key"]=> + int(4) + ["null"]=> + NULL +} +-- Callback funciton with parameter and without return -- +array(0) { +} +-- Callback function without parameter and return -- +array(0) { +} +-- Callback function with parameter and return -- +array(3) { + [2]=> + int(2) + [3]=> + float(0.0034) + ["key"]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/array_filter_variation5.phpt b/ext/standard/tests/array/array_filter_variation5.phpt new file mode 100644 index 0000000..66b140a --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation5.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_filter() function : usage variations - 'input' argument with different false entries +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* With default callback function argument, array_filter() removes elements which are interpreted as false +* Here Testing all the false array element possibilities +*/ + +// callback function always_true +function always_true($input) +{ + return true; +} + +// callback function always_false +function always_false($input) +{ + return false; +} + +echo "*** Testing array_filter() : usage variations - different false elements in 'input' ***\n"; + +// unset variable +$unset_var = 10; +unset($unset_var); + +// empty heredoc string +$empty_heredoc =<<<EOT +EOT; + +// input array with different false elements +$input = array( + false, + False, + '', + "", + 0, + 0.0, + null, + NULL, + "0", + '0', + array(), + !1, + 1==2, + $empty_heredoc, + @$unset_var, + @$undefined_var, +); + +// With default callback function +var_dump( array_filter($input) ); + +// With callback function which returns always true +var_dump( array_filter($input, 'always_true') ); + +// With callback function which returns always false +var_dump( array_filter($input, 'always_false') ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - different false elements in 'input' *** +array(0) { +} +array(16) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + int(0) + [5]=> + float(0) + [6]=> + NULL + [7]=> + NULL + [8]=> + string(1) "0" + [9]=> + string(1) "0" + [10]=> + array(0) { + } + [11]=> + bool(false) + [12]=> + bool(false) + [13]=> + string(0) "" + [14]=> + NULL + [15]=> + NULL +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation6.phpt b/ext/standard/tests/array/array_filter_variation6.phpt new file mode 100644 index 0000000..1020c28 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation6.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test array_filter() function : usage variations - 'input' array containing references +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* Passing 'input' array which contains elements as reference to other data +*/ + +echo "*** Testing array_filter() : usage variations - 'input' containing references ***\n"; + +// Callback function +/* Prototype : bool callback(array $input) + * Parameter : $input - array of which each element need to be checked in function + * Return Type : returns true or false + * Description : This function checks each element of an input array if element > 5 then + * returns true else returns false + */ +function callback($input) +{ + if($input > 5) { + return true; + } + else { + return false; + } +} + +// initializing variables +$value1 = array(1, 2, 8); +$value2 = array(5, 6, 4); +$input = array(&$value1, 10, &$value2, 'value'); + +// with 'callback' argument +var_dump( array_filter($input, 'callback') ); + +// with default 'callback' argument +var_dump( array_filter($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - 'input' containing references *** +array(3) { + [0]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) + } + [1]=> + int(10) + [2]=> + &array(3) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(4) + } +} +array(4) { + [0]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) + } + [1]=> + int(10) + [2]=> + &array(3) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(4) + } + [3]=> + string(5) "value" +} +Done diff --git a/ext/standard/tests/array/array_filter_variation7.phpt b/ext/standard/tests/array/array_filter_variation7.phpt new file mode 100644 index 0000000..cb856f7 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation7.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_filter() function : usage variations - anonymous callback functions +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* Passing different anonymous callback functions with passed by value and reference arguments +*/ + +echo "*** Testing array_filter() : usage variations - Anonymous callback functions ***\n"; + +$input = array(0, 1, -1, 10, 100, 1000, 'Hello', null); + +// anonymous callback function +echo "Anonymous callback function with regular parameter and statement\n"; +var_dump( array_filter($input, create_function('$input', 'return ($input > 1);') ) ); + +// anonymous callback function with reference +echo "Anonymous callback function with reference parameter\n"; +var_dump( array_filter($input, create_function('&$input', 'return ($input < 1);') ) ); + +// anonymous callback function with null argument +echo "Anonymous callback funciton with null argument\n"; +var_dump( array_filter($input, create_function(null, 'return true;') ) ); + +// anonymous callback function with argument and null statement +echo "Anonymous callback function with regular argument and null statement\n"; +var_dump( array_filter($input, create_function('$input', null) ) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - Anonymous callback functions *** +Anonymous callback function with regular parameter and statement +array(3) { + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) +} +Anonymous callback function with reference parameter +array(4) { + [0]=> + int(0) + [2]=> + int(-1) + [6]=> + string(5) "Hello" + [7]=> + NULL +} +Anonymous callback funciton with null argument +array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL +} +Anonymous callback function with regular argument and null statement +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation8.phpt b/ext/standard/tests/array/array_filter_variation8.phpt new file mode 100644 index 0000000..4440b33 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation8.phpt @@ -0,0 +1,151 @@ +--TEST-- +Test array_filter() function : usage variations - Callback function with different return values +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* callback functions are expected to return bool value for array_filter() +* here testing callback functions for return values other than bool +*/ + +echo "*** Testing array_filter() : usage variations - callback function with different return values***\n"; + +$input = array(0, 1, -1, 10, 100, 1000, 'Hello', null, true); + +// callback functions +// int as return value +function callback1($input) +{ + return 5; +} +echo "callback function with int return value\n"; +var_dump( array_filter($input, 'callback1') ); + +// float as return value +function callback2($input) +{ + return 3.4; +} +echo "callback function with float return value\n"; +var_dump( array_filter($input, 'callback2') ); + +// string as return value +function callback3($input) +{ + return 'value'; +} +echo "callback function with string return value\n"; +var_dump( array_filter($input, 'callback3') ); + +// null as return value +function callback4($input) +{ + return null; +} +echo "callback function with null return value\n"; +var_dump( array_filter($input, 'callback4') ); + +// array as return value +function callback5($input) +{ + return array(8); +} +echo "callback function with array as return value\n"; +var_dump( array_filter($input, 'callback5') ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - callback function with different return values*** +callback function with int return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with float return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with string return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with null return value +array(0) { +} +callback function with array as return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +Done diff --git a/ext/standard/tests/array/array_filter_variation9.phpt b/ext/standard/tests/array/array_filter_variation9.phpt new file mode 100644 index 0000000..81554f1 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation9.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_filter() function : usage variations - built-in functions as 'callback' argument +--FILE-- +<?php +/* Prototype : array array_filter(array $input [, callback $callback]) + * Description: Filters elements from the array via the callback. + * Source code: ext/standard/array.c +*/ + +/* +* Passing built-in functions and different language constructs as 'callback' argument +*/ + +echo "*** Testing array_filter() : usage variations - built-in functions as 'callback' argument ***\n"; + +$input = array(0, 1, -1, 10, 100, 1000, 'Hello', null); + +// using built-in function 'is_int' as 'callback' +var_dump( array_filter($input, 'is_int') ); + +// using built-in function 'chr' as 'callback' +var_dump( array_filter($input, 'chr') ); + +// using language construct 'echo' as 'callback' +var_dump( array_filter($input, 'echo') ); + +// using language construct 'exit' as 'callback' +var_dump( array_filter($input, 'exit') ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - built-in functions as 'callback' argument *** +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) +} +array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL +} + +Warning: array_filter() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL + +Warning: array_filter() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_flip.phpt b/ext/standard/tests/array/array_flip.phpt new file mode 100644 index 0000000..c268f5a --- /dev/null +++ b/ext/standard/tests/array/array_flip.phpt @@ -0,0 +1,37 @@ +--TEST-- +basic array_flip test +--FILE-- +<?php +$trans = array("a" => 1, + "b" => 1, + "c" => 2, + "z" => 0, + "d" => TRUE, + "E" => FALSE, + "F" => NULL, + 0 => "G", + 1 => "h", + 2 => "i"); +$trans = array_flip($trans); +var_dump($trans); +?> +--EXPECTF-- +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d +array(6) { + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [0]=> + string(1) "z" + ["G"]=> + int(0) + ["h"]=> + int(1) + ["i"]=> + int(2) +} diff --git a/ext/standard/tests/array/array_flip_basic.phpt b/ext/standard/tests/array/array_flip_basic.phpt new file mode 100644 index 0000000..08a63fb --- /dev/null +++ b/ext/standard/tests/array/array_flip_basic.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test array_flip() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_flip(array $input) + * Description: Return array with key <-> value flipped + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_flip() : basic functionality ***\n"; + +// array with default keys - numeric values +$input = array(1, 2); +var_dump( array_flip($input) ); + +// array with default keys - string values +$input = array('value1', "value2"); +var_dump( array_flip($input) ); + +// associative arrays - key as string +$input = array('key1' => 1, "key2" => 2); +var_dump( array_flip($input) ); + +// associative arrays - key as numeric +$input = array(1 => 'one', 2 => "two"); +var_dump( array_flip($input) ); + +// combination of associative and non-associative array +$input = array(1 => 'one','two', 3 => 'three', 4, "five" => 5); +var_dump( array_flip($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : basic functionality *** +array(2) { + [1]=> + int(0) + [2]=> + int(1) +} +array(2) { + ["value1"]=> + int(0) + ["value2"]=> + int(1) +} +array(2) { + [1]=> + string(4) "key1" + [2]=> + string(4) "key2" +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) + [5]=> + string(4) "five" +} +Done diff --git a/ext/standard/tests/array/array_flip_error.phpt b/ext/standard/tests/array/array_flip_error.phpt new file mode 100644 index 0000000..3aa0f98 --- /dev/null +++ b/ext/standard/tests/array/array_flip_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_flip() function : error conditions +--FILE-- +<?php +/* Prototype : array array_flip(array $input) + * Description: Return array with key <-> value flipped + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_flip() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_flip() function with Zero arguments --\n"; +var_dump( array_flip() ); + +//one more than the expected number of arguments +echo "-- Testing array_flip() function with more than expected no. of arguments --\n"; +$input = array(1 => 'one', 2 => 'two'); +$extra_arg = 10; +var_dump( array_flip($input, $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : error conditions *** +-- Testing array_flip() function with Zero arguments -- + +Warning: array_flip() expects exactly 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_flip() function with more than expected no. of arguments -- + +Warning: array_flip() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_flip_variation1.phpt b/ext/standard/tests/array/array_flip_variation1.phpt new file mode 100644 index 0000000..6ba558f --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation1.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_flip() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_flip(array $input) + * Description: Return array with key <-> value flipped + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_flip() : usage variations - unexpected values for 'input' ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//class definition for object variable +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +//resource variable +$fp = fopen(__FILE__,'r'); + +//array of values for 'input' argument +$values = array( + // int data + /*1*/ 0, + 1, + 12345, + -2345, + + // float data + /*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data + /*10*/ NULL, + null, + + // boolean data + /*12*/ true, + false, + TRUE, + /*15*/ FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + /*20*/ new MyClass(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + //resource data + /*23*/ $fp +); + +// loop through each element of $values for 'input' argument +for($count = 0; $count < count($values); $count++) { + echo "-- Iteration ".($count + 1). " --\n"; + var_dump( array_flip($values[$count]) ); +}; + +//closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : usage variations - unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_flip() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_flip() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_flip_variation2.phpt b/ext/standard/tests/array/array_flip_variation2.phpt Binary files differnew file mode 100644 index 0000000..997c391 --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation2.phpt diff --git a/ext/standard/tests/array/array_flip_variation3.phpt b/ext/standard/tests/array/array_flip_variation3.phpt Binary files differnew file mode 100644 index 0000000..1d56dfa --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation3.phpt diff --git a/ext/standard/tests/array/array_flip_variation4.phpt b/ext/standard/tests/array/array_flip_variation4.phpt new file mode 100644 index 0000000..2420c7e --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation4.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' argument with different invalid values for keys +--FILE-- +<?php +/* Prototype : array array_flip(array $input) + * Description: Return array with key <-> value flipped + * Source code: ext/standard/array.c +*/ + +/* +* Trying different invalid values for 'input' array argument +*/ + +echo "*** Testing array_flip() : different invalid values in 'input' array argument ***\n"; + +// class definition for object data +class MyClass +{ + public function __toString() + { + return 'object'; + } +} +$obj = new MyClass(); + +// resource data +$fp = fopen(__FILE__, 'r'); + +$input = array( + // float values + 'float_value1' => 1.2, + 'float_value2' => 0.5, + 'flaot_value3' => 3.4E3, + 'flaot_value4' => 5.6E-6, + + // bool values + 'bool_value1' => true, + 'bool_value2' => false, + 'bool_value3' => TRUE, + 'bool_value4' => FALSE, + + // null values + 'null_value1' => null, + + // array value + 'array_value' => array(1), + + // object value + 'obj_value' => $obj, + + // resource value + 'resource_value' => $fp, +); + +var_dump( array_flip($input) ); + +// closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : different invalid values in 'input' array argument *** + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_flip_variation5.phpt b/ext/standard/tests/array/array_flip_variation5.phpt new file mode 100644 index 0000000..29222a1 --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation5.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' argument with repeatitive keys and values +--FILE-- +<?php +/* Prototype : array array_flip(array $input) + * Description: Return array with key <-> value flipped + * Source code: ext/standard/array.c +*/ + +/* +* Using different types of repeatitive keys as well as values for 'input' array +*/ + +echo "*** Testing array_flip() : 'input' array with repeatitive keys/values ***\n"; + +// array with numeric key repeatition +$input = array(1 => 'value', 2 => 'VALUE', 1 => "VaLuE", 3.4 => 4, 3.4 => 5); +var_dump( array_flip($input) ); + +// array with string key repeatition +$input = array("key" => 1, "two" => 'TWO', 'three' => 3, 'key' => "FOUR"); +var_dump( array_flip($input) ); + +// array with bool key repeatition +$input = array(true => 1, false => 0, TRUE => -1); +var_dump( array_flip($input) ); + +// array with null key repeatition +$input = array(null => "Hello", NULL => 0); +var_dump( array_flip($input) ); + +// array with numeric value repeatition +$input = array('one' => 1, 'two' => 2, 3 => 1, "index" => 1); +var_dump( array_flip($input) ); + +//array with string value repeatition +$input = array('key1' => "value1", "key2" => '2', 'key3' => 'value1'); +var_dump( array_flip($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : 'input' array with repeatitive keys/values *** +array(3) { + ["VaLuE"]=> + int(1) + ["VALUE"]=> + int(2) + [5]=> + int(3) +} +array(3) { + ["FOUR"]=> + string(3) "key" + ["TWO"]=> + string(3) "two" + [3]=> + string(5) "three" +} +array(2) { + [-1]=> + int(1) + [0]=> + int(0) +} +array(1) { + [0]=> + string(0) "" +} +array(2) { + [1]=> + string(5) "index" + [2]=> + string(3) "two" +} +array(2) { + ["value1"]=> + string(4) "key3" + [2]=> + string(4) "key2" +} +Done diff --git a/ext/standard/tests/array/array_intersect_1.phpt b/ext/standard/tests/array/array_intersect_1.phpt new file mode 100644 index 0000000..41f2033 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_1.phpt @@ -0,0 +1,364 @@ +--TEST-- +Test of the *intersect* bunch of functions (both assoc and non-assoc) +--FILE-- +<?php +error_reporting(E_ALL); +class cr { + private $priv_member; + public $public_member; + function cr($val) { + $this->priv_member = $val; + $this->public_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member)? 1:-1; + } +} + +function comp_func($a, $b) { + if ($a === $b) return 0; + return ($a > $b)? 1:-1; + +} + +function comp_func_cr($a, $b) { + if ($a->public_member === $b->public_member) return 0; + return ($a->public_member > $b->public_member)? 1:-1; +} + +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1=> new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr( 3), 1=> new cr(4), 2 => new cr(-15),); + +/* array_uintersect() */ +echo "begin ------------ array_uintersect() ---------------------------\n"; +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_uintersect($a, $b, "comp_func_cr"));'."\n"; +var_dump(array_uintersect($a, $b, "comp_func_cr")); +echo "end ------------ array_uintersect() ---------------------------\n"; + +/* array_uintersect_assoc() */ +echo "begin ------------ array_uintersect_assoc() ---------------------\n"; +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_uintersect_assoc($a, $b, "comp_func_cr"));'."\n"; +var_dump(array_uintersect_assoc($a, $b, "comp_func_cr")); +echo "end ------------ array_uintersect_assoc() ---------------------\n"; + +/* array_uintersect_uassoc() - with ordinary function */ +echo "begin ------------ array_uintersect_uassoc() with ordinary func -\n"; +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func"));'."\n"; +var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func")); +echo "end ------------ array_uintersect_uassoc() with ordinary func -\n"; + +/* array_uintersect_uassoc() - by method call */ +echo "begin ------------ array_uintersect_uassoc() with method --------\n"; +echo '$a='.var_export($a,TRUE).";\n"; +echo '$b='.var_export($b,TRUE).";\n"; +echo 'var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func"));'."\n"; +var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); +echo "end ------------ array_uintersect_uassoc() with method --------\n"; +?> +--EXPECTF-- +begin ------------ array_uintersect() --------------------------- +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect($a, $b, "comp_func_cr")); +array(3) { + ["0.1"]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(9) + ["public_member"]=> + int(9) + } + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect() --------------------------- +begin ------------ array_uintersect_assoc() --------------------- +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect_assoc($a, $b, "comp_func_cr")); +array(2) { + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect_assoc() --------------------- +begin ------------ array_uintersect_uassoc() with ordinary func - +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect_uassoc($a, $b, "comp_func_cr", "comp_func")); +array(2) { + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect_uassoc() with ordinary func - +begin ------------ array_uintersect_uassoc() with method -------- +$a=array ( + '0.1' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 12, + 'public_member' => 12, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 23, + 'public_member' => 23, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +$b=array ( + '0.2' => + cr::__set_state(array( + 'priv_member' => 9, + 'public_member' => 9, + )), + '0.5' => + cr::__set_state(array( + 'priv_member' => 22, + 'public_member' => 22, + )), + 0 => + cr::__set_state(array( + 'priv_member' => 3, + 'public_member' => 3, + )), + 1 => + cr::__set_state(array( + 'priv_member' => 4, + 'public_member' => 4, + )), + 2 => + cr::__set_state(array( + 'priv_member' => -15, + 'public_member' => -15, + )), +); +var_dump(array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), "comp_func")); +array(2) { + [1]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(4) + ["public_member"]=> + int(4) + } + [2]=> + object(cr)#%d (2) { + ["priv_member":"cr":private]=> + int(-15) + ["public_member"]=> + int(-15) + } +} +end ------------ array_uintersect_uassoc() with method -------- diff --git a/ext/standard/tests/array/array_intersect_assoc_basic.phpt b/ext/standard/tests/array/array_intersect_assoc_basic.phpt new file mode 100644 index 0000000..bf0f219 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_basic.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test array_intersect_assoc() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_intersect_assoc() by passing different arrays for the arguments. +* Function is tested by passing associative array as well as array with default keys. +*/ + +echo "*** Testing array_intersect_assoc() : basic functionality ***\n"; + +// array with default keys +$arr_default_keys = array(1, 2, "hello", 'world'); + +// associative array +$arr_associative = array("one" => 1, "two" => 2); + +// default key array for both $arr1 and $arr2 argument +var_dump( array_intersect_assoc($arr_default_keys, $arr_default_keys) ); + +// default key array for $arr1 and associative array for $arr2 argument +var_dump( array_intersect_assoc($arr_default_keys, $arr_associative) ); + +// associative array for $arr1 and default key array for $arr2 +var_dump( array_intersect_assoc($arr_associative, $arr_default_keys) ); + +// associative array for both $arr1 and $arr2 argument +var_dump( array_intersect_assoc($arr_associative, $arr_associative) ); + +// more arrays to be intersected +$arr3 = array(2, 3, 4); +var_dump( array_intersect_assoc($arr_default_keys, $arr_associative, $arr3) ); +var_dump( array_intersect_assoc($arr_associative, $arr_default_keys, $arr3, $arr_associative) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : basic functionality *** +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +array(0) { +} +array(0) { +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_assoc_error.phpt b/ext/standard/tests/array/array_intersect_assoc_error.phpt new file mode 100644 index 0000000..c371071 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_intersect_assoc() function : error conditions(Bug#43197) +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_intersect_assoc() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_intersect_assoc() function with Zero arguments --\n"; +var_dump( array_intersect_assoc() ); + +// Testing array_intersect_assoc with one less than the expected number of arguments +echo "\n-- Testing array_intersect_assoc() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_intersect_assoc($arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : error conditions *** + +-- Testing array_intersect_assoc() function with Zero arguments -- + +Warning: array_intersect_assoc(): at least 2 parameters are required, 0 given in %s on line %d +NULL + +-- Testing array_intersect_assoc() function with less than expected no. of arguments -- + +Warning: array_intersect_assoc(): at least 2 parameters are required, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation1.phpt b/ext/standard/tests/array/array_intersect_assoc_variation1.phpt new file mode 100644 index 0000000..713ed82 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation1.phpt @@ -0,0 +1,281 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - unexpected values for 'arr1' argument(Bug#43196) +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_intersect_assoc() function by passing values to $arr1 argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $arr2 argument passed is a fixed array. +*/ + +echo "*** Testing array_intersect_assoc() : Passing non-array values to \$arr1 argument ***\n"; + +// array to be passsed to $arr2 as default argument +$arr2 = array(1, 2); + +// additional array to be passed for intersection +$arr3 = array(1, 2, "one" => 1, "two" => 2); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$arrays = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $unexpected_value) { + echo "\n-- Iteration $iterator --"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($unexpected_value, $arr2) ); + + // Calling array_intersect_assoc() with more arguments + var_dump( array_intersect_assoc($unexpected_value, $arr2, $arr3) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : Passing non-array values to $arr1 argument *** + +-- Iteration 1 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation10.phpt b/ext/standard/tests/array/array_intersect_assoc_variation10.phpt new file mode 100644 index 0000000..9bce974 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation10.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_intersect_assoc() by passing array with +* binary values for $arr1 and $arr2 argument. +*/ + +echo "*** Testing array_intersect_assoc() : binary safe checking ***\n"; + +// array with binary values +$arr_binary = array(b"hello", b"world"); +// simple array +$arr_normal = array("hello", "world"); + +// array with binary value for $arr1 argument +var_dump( array_intersect_assoc($arr_binary, $arr_normal) ); + +// array with binary value for $arr2 argument +var_dump( array_intersect_assoc($arr_normal, $arr_binary) ); + +// array with binary value for both $arr1 and $arr2 argument +var_dump( array_intersect_assoc($arr_binary, $arr_binary) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : binary safe checking *** +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_assoc_variation2.phpt b/ext/standard/tests/array/array_intersect_assoc_variation2.phpt new file mode 100644 index 0000000..e82e7cf --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation2.phpt @@ -0,0 +1,282 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - unexpected values for 'arr2' argument(Bug#43196) +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_intersect_assoc() function by passing values to $arr2 argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $arr1 argument passed is a fixed array. +*/ + +echo "*** Testing array_intersect_assoc() : Passing non-array values to \$arr2 argument ***\n"; + +// array to be passsed to $arr1 as default argument +$arr1 = array(1, 2); + +// additional array to be passed for intersection +$arr3 = array(1, 2, "one" => 1, "two" => 2); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$arrays = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $unexpected_value) { + echo "\n-- Iteration $iterator --"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1,$unexpected_value) ); + + // Calling array_intersect_assoc() with more arguments + var_dump( array_intersect_assoc($arr1, $unexpected_value, $arr3) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : Passing non-array values to $arr2 argument *** + +-- Iteration 1 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_assoc(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation3.phpt b/ext/standard/tests/array/array_intersect_assoc_variation3.phpt new file mode 100644 index 0000000..50be080 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation3.phpt @@ -0,0 +1,243 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - different arrays for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of arrays to $arr1 argument and testing whether +* array_intersect_assoc() behaves in an expected way with the other arguments passed to the function +* The $arr2 argument passed is a fixed array. +*/ + +echo "*** Testing array_intersect_assoc() : Passing different types of arrays to \$arr1 argument ***\n"; + +/* Different heredoc strings passed as argument to $arr1 */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays to be passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + + +// array to be passsed to $arr2 argument +$arr2 = array ( + 1, 1.1, 2.2, "hello", "one", NULL, 2, + 'world', true,5 => false, 1 => 'aaaa\r', "aaaa\r", + 'h3' => $diff_whitespaces, $numeric_string, + "one" => "ten", 4 => "four", "two" => 2, + '', null => "null", '' => 'emptys', "emptyd" => "", +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : Passing different types of arrays to $arr1 argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iteration 2 -- +array(0) { +} +array(0) { +} +-- Iteration 3 -- +array(0) { +} +array(0) { +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(0) { +} +-- Iteration 6 -- +array(0) { +} +array(0) { +} +-- Iteration 7 -- +array(1) { + [1]=> + string(6) "aaaa\r" +} +array(1) { + [1]=> + string(6) "aaaa\r" +} +-- Iteration 8 -- +array(1) { + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +array(1) { + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- Iteration 9 -- +array(0) { +} +array(0) { +} +-- Iteration 10 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(0) { +} +array(0) { +} +-- Iteration 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iteration 13 -- +array(1) { + [4]=> + string(4) "four" +} +array(1) { + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(0) { +} +array(0) { +} +-- Iteration 15 -- +array(0) { +} +array(0) { +} +-- Iteration 16 -- +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +-- Iteration 17 -- +array(1) { + [5]=> + bool(false) +} +array(1) { + [5]=> + bool(false) +} +-- Iteration 18 -- +array(0) { +} +array(0) { +} +-- Iteration 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation4.phpt b/ext/standard/tests/array/array_intersect_assoc_variation4.phpt new file mode 100644 index 0000000..ed2e3d9 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation4.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - different arrays for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of arrays to $arr2 argument and testing whether +* array_intersect_assoc() behaves in an expected way with the other arguments passed to the function. +* The $arr1 argument passed is a fixed array. +*/ + +echo "*** Testing array_intersect_assoc() : Passing different types of arrays to \$arr2 argument ***\n"; + +/* Different heredoc strings passed as argument to $arr2 */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// array to be passsed to $arr1 argument +$arr1 = array ( + 1, 1.1, 1.3, 1 => true, "hello", "one", NULL, 2, + 'world', true, false, 3 => "b\tbbb", "aaaa\r", + $numeric_string, "h3" => $diff_whitespaces, "true" => true, + "one" => "ten", 4 => "four", "two" => 2, 6 => "six", + '', null => "null", '' => 'emptys' +); + +// arrays to be passed to $arr2 argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 1.2, 1.3), // array with default keys & float values + array(false,true), // array with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // array with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings + array($blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // array with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 6 => "six"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : Passing different types of arrays to $arr2 argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iteration 2 -- +array(1) { + [2]=> + float(1.3) +} +array(1) { + [2]=> + float(1.3) +} +-- Iteration 3 -- +array(1) { + [1]=> + bool(true) +} +array(1) { + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(0) { +} +-- Iteration 6 -- +array(1) { + [3]=> + string(5) "b bbb" +} +array(1) { + [3]=> + string(5) "b bbb" +} +-- Iteration 7 -- +array(0) { +} +array(0) { +} +-- Iteration 8 -- +array(1) { + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +array(1) { + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- Iteration 9 -- +array(1) { + [6]=> + string(3) "six" +} +array(1) { + [6]=> + string(3) "six" +} +-- Iteration 10 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(0) { +} +array(0) { +} +-- Iteration 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iteration 13 -- +array(1) { + [4]=> + string(4) "four" +} +array(1) { + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(0) { +} +array(0) { +} +-- Iteration 15 -- +array(1) { + ["true"]=> + bool(true) +} +array(1) { + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(1) { + [""]=> + string(6) "emptys" +} +array(1) { + [""]=> + string(6) "emptys" +} +-- Iteration 17 -- +array(1) { + [5]=> + NULL +} +array(1) { + [5]=> + NULL +} +-- Iteration 18 -- +array(0) { +} +array(0) { +} +-- Iteration 19 -- +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_assoc_variation5.phpt b/ext/standard/tests/array/array_intersect_assoc_variation5.phpt new file mode 100644 index 0000000..7d8e09e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation5.phpt @@ -0,0 +1,173 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect_assoc() by passing different + * associative arrays having different possible keys to $arr1 argument. + * The $arr2 argument passed is a fixed array +*/ + +echo "*** Testing array_intersect_assoc() : assoc array with diff keys to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr1 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable +/*10*/ array(@$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passsed to $arr2 argument +$arr2 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", + "\tHello" => 111, 2.2, 'color', "Hello world" => "string", + "pen\n" => 33, 133 => "int"); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : assoc array with diff keys to $arr1 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(0) { +} +array(0) { +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(1) { + [2]=> + string(5) "float" +} +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 6 -- +array(2) { + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +array(2) { + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +-- Iteration 7 -- +array(0) { +} +array(0) { +} +-- Iteration 8 -- +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +array(1) { + ["Hello world"]=> + string(6) "string" +} +array(1) { + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +array(0) { +} +array(0) { +} +-- Iteration 11 -- +array(1) { + [133]=> + string(3) "int" +} +array(1) { + [133]=> + string(3) "int" +} +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation6.phpt b/ext/standard/tests/array/array_intersect_assoc_variation6.phpt new file mode 100644 index 0000000..7580622 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation6.phpt @@ -0,0 +1,173 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff keys for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect_assoc() by passing different + * associative arrays having different possible keys to $arr2 argument. + * The $arr1 argument passed is a fixed array. +*/ + +echo "*** Testing array_intersect_assoc() : assoc array with diff keys to \$arr2 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr2 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with unset variable +/*10*/ array( @$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passsed to $arr1 argument +$arr1 = array(0 => 0, 2 => "float", 4 => "f3", 33333333 => "f4", + "\tHello" => 111, 2.2, 'color', "Hello world" => "string", + "pen\n" => 33, 133 => "int"); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : assoc array with diff keys to $arr2 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(0) { +} +array(0) { +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(1) { + [2]=> + string(5) "float" +} +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 6 -- +array(2) { + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +array(2) { + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +-- Iteration 7 -- +array(0) { +} +array(0) { +} +-- Iteration 8 -- +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +array(2) { + [" Hello"]=> + int(111) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +array(1) { + ["Hello world"]=> + string(6) "string" +} +array(1) { + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +array(0) { +} +array(0) { +} +-- Iteration 11 -- +array(1) { + [133]=> + string(3) "int" +} +array(1) { + [133]=> + string(3) "int" +} +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation7.phpt b/ext/standard/tests/array/array_intersect_assoc_variation7.phpt new file mode 100644 index 0000000..ba2f79a --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation7.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect_assoc() by passing different + * associative arrays having different possible values to $arr1 argument. + * The $arr2 argument passed is a fixed array +*/ + +echo "*** Testing array_intersect_assoc() : assoc array with diff values to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr1 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable +/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// array to be passsed to $arr2 argument +$arr2 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2, + "f4" => 33333333.333, 111 => "\tHello", 3.3 => 'pen\n', '\v\fworld', + "heredoc" => "Hello world", 11 => new classA(), "resource" => $fp, + "int" => 133, 222 => "fruit"); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : assoc array with diff values to $arr1 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(1) { + [111]=> + string(6) " Hello" +} +array(1) { + [111]=> + string(6) " Hello" +} +-- Iteration 8 -- +array(1) { + [3]=> + string(5) "pen\n" +} +array(1) { + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(4) { + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["heredoc"]=> + string(11) "Hello world" +} +array(4) { + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation8.phpt b/ext/standard/tests/array/array_intersect_assoc_variation8.phpt new file mode 100644 index 0000000..6ec8fb0 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation8.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - assoc array with diff values for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect_assoc() by passing different + * associative arrays having different possible values to $arr2 argument. + * The $arr1 argument passed is a fixed array. +*/ + +echo "*** Testing array_intersect_assoc() : assoc array with diff values to \$arr2 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr2 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable +/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// array to be passsed to $arr1 argument +$arr1 = array(0 => "0", 1, "two" => 2, "float" => 2.3333, "f1" => 1.2, + "f4" => 33333333.333, 111 => "\tHello", 3.3 => 'pen\n', '\v\fworld', + "heredoc" => "Hello world", 11 => new classA(), "resource" => $fp, + "int" => 133, 222 => "fruit"); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect_assoc() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect_assoc() with default arguments + var_dump( array_intersect_assoc($arr1, $arr2) ); + + // Calling array_intersect_assoc() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : assoc array with diff values to $arr2 argument *** +-- Iteration 1 -- +array(0) { +} +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(1) { + ["two"]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +array(2) { + ["f1"]=> + float(1.2) + ["f4"]=> + float(33333333.333) +} +-- Iteration 7 -- +array(1) { + [111]=> + string(6) " Hello" +} +array(1) { + [111]=> + string(6) " Hello" +} +-- Iteration 8 -- +array(1) { + [3]=> + string(5) "pen\n" +} +array(1) { + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(4) { + ["heredoc"]=> + string(11) "Hello world" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + [222]=> + string(5) "fruit" +} +array(4) { + ["heredoc"]=> + string(11) "Hello world" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + [222]=> + string(5) "fruit" +} +Done diff --git a/ext/standard/tests/array/array_intersect_assoc_variation9.phpt b/ext/standard/tests/array/array_intersect_assoc_variation9.phpt new file mode 100644 index 0000000..338d409 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_assoc_variation9.phpt @@ -0,0 +1,152 @@ +--TEST-- +Test array_intersect_assoc() function : usage variations - two dimensional arrays for $arr1 and $arr2 arguments +--FILE-- +<?php +/* Prototype : array array_intersect_assoc(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. + * Keys are used to do more restrictive check + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_intersect_assoc() by passing 2-D arrays +* to both $arr1 and $arr2 argument. +* Optional argument takes the same value as that of $arr1 +*/ + +echo "*** Testing array_intersect_assoc() : passing two dimensional array to both \$arr1 and \$arr2 arguments ***\n"; + +// two dimensional arrays for $arr1 and $arr2 argument +$arr1 = array ( + + // arrays with default keys + array(1, 2, "hello", 'world'), + array(1, 2, 3, 4), + + // arrays with explicit keys + array(1 => "one", 2 => "two", 3 => "three"), + array("ten" => 10, "twenty" => 20.00, "thirty" => 30) +); + +$arr2 = array ( + array(1, 2, 3, 4), + array(1 => "one", 2 => "two", 3 => "three") +); + +/* Passing the entire array as argument to $arr1 and $arr2 */ +// Calling array_intersect_assoc() with default arguments +echo "-- Passing the entire 2-D array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect_assoc($arr1, $arr2) ); + +// Calling array_intersect_assoc() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect_assoc($arr1, $arr2, $arr1) ); + +/* Passing the sub-array as argument to $arr1 and $arr2 */ +// Calling array_intersect_assoc() with default arguments +echo "-- Passing the sub-array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect_assoc($arr1[0], $arr2[0]) ); + +// Calling array_intersect_assoc() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect_assoc($arr1[0], $arr2[0], $arr1[0]) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect_assoc() : passing two dimensional array to both $arr1 and $arr2 arguments *** +-- Passing the entire 2-D array to $arr1 and $arr2 -- +- With default arguments - + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +- With more arguments - + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_assoc_variation9.php on line %d +array(2) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } +} +-- Passing the sub-array to $arr1 and $arr2 -- +- With default arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +- With more arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_intersect_basic.phpt b/ext/standard/tests/array/array_intersect_basic.phpt new file mode 100644 index 0000000..fde5782 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_basic.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_intersect() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_intersect() by passing different arrays for the arguments. +* Function is tested by passing associative array as well as array with default keys. +*/ + +echo "*** Testing array_intersect() : basic functionality ***\n"; + +// array with default keys +$arr_default_keys = array(1, 2, "hello", 'world'); + +// associative array +$arr_associative = array("one" => 1, "two" => 2); + +// default key array for both $arr1 and $arr2 argument +var_dump( array_intersect($arr_default_keys, $arr_default_keys) ); + +// default key array for $arr1 and associative array for $arr2 argument +var_dump( array_intersect($arr_default_keys, $arr_associative) ); + +// associative array for $arr1 and default key array for $arr2 +var_dump( array_intersect($arr_associative, $arr_default_keys) ); + +// associative array for both $arr1 and $arr2 argument +var_dump( array_intersect($arr_associative, $arr_associative) ); + +// more arrays to be intersected +$arr3 = array(2, 3, 4); +var_dump( array_intersect($arr_default_keys, $arr_associative, $arr3) ); +var_dump( array_intersect($arr_associative, $arr_default_keys, $arr3, $arr_associative) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : basic functionality *** +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(1) { + [1]=> + int(2) +} +array(1) { + ["two"]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_intersect_error.phpt b/ext/standard/tests/array/array_intersect_error.phpt new file mode 100644 index 0000000..46f77ac --- /dev/null +++ b/ext/standard/tests/array/array_intersect_error.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test array_intersect() function : error conditions +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_intersect() : error conditions ***\n"; + +// Testing array_intersect() with zero arguments +echo "\n-- Testing array_intersect() function with Zero arguments --\n"; +var_dump( array_intersect() ); + +// Testing array_intersect() with one less than the expected number of arguments +echo "\n-- Testing array_intersect() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_intersect($arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : error conditions *** + +-- Testing array_intersect() function with Zero arguments -- + +Warning: array_intersect(): at least 2 parameters are required, 0 given in %s on line %d +NULL + +-- Testing array_intersect() function with less than expected no. of arguments -- + +Warning: array_intersect(): at least 2 parameters are required, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_intersect_key.phpt b/ext/standard/tests/array/array_intersect_key.phpt new file mode 100644 index 0000000..6d27839 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test of the array_intersect_key() and array_intersect_ukey() +--FILE-- +<?php +$a = array(1, 6, 2, -20, 15, 1200, -2500); +$b = array(0, 7, 2, -20, 11, 1100, -2500); +$c = array(0, 6, 2, -20, 19, 1000, -2500); +$d = array(3, 8,-2, -20, 14, 900, -2600); + +$a_f = array_flip($a); +$b_f = array_flip($b); +$c_f = array_flip($c); +$d_f = array_flip($d); + +/* give nicer values */ +foreach ($a_f as $k=> &$a_f_el) { $a_f_el =$k*2;} +foreach ($b_f as $k=> &$b_f_el) { $b_f_el =$k*2;} +foreach ($c_f as $k=> &$c_f_el) { $c_f_el =$k*2;} +foreach ($d_f as $k=> &$d_f_el) { $d_f_el =$k*2;} + +var_dump(array_intersect_key($a_f, $b_f));// keys -> 2, -20, -2500 +var_dump(array_intersect_ukey($a_f, $b_f, "comp_func"));// 2, 20, -2500 +var_dump(array_intersect_key($a_f, $c_f));// keys -> 6, 2, -20, -2500 +var_dump(array_intersect_ukey($a_f, $c_f, "comp_func"));// 6, 2, -20, -2500 +var_dump(array_intersect_key($a_f, $d_f));// -20 +var_dump(array_intersect_ukey($a_f, $d_f, "comp_func"));// -20 + +var_dump(array_intersect_key($a_f, $b_f, $c_f));// 2, -20, -2500 +var_dump(array_intersect_ukey($a_f, $b_f, $c_f, "comp_func"));// 2, -20, -2500 +var_dump(array_intersect_key($a_f, $b_f, $d_f));// -20 +var_dump(array_intersect_ukey($a_f, $b_f, $d_f, "comp_func"));// -20 + +var_dump(array_intersect_key($a_f, $b_f, $c_f, $d_f));// -20 +var_dump(array_intersect_ukey($a_f, $b_f, $c_f, $d_f, "comp_func"));//-20 + + +var_dump(array_intersect_key($b_f, $c_f));// 0, 2, -20, -2500 +var_dump(array_intersect_ukey($b_f, $c_f, "comp_func"));//0, 2, -20, 2500 + +var_dump(array_intersect_key($b_f, $d_f));// -20 +var_dump(array_intersect_ukey($b_f, $d_f, "comp_func"));// -20 + +var_dump(array_intersect_key($b_f, $c_f, $d_f));// -20 +var_dump(array_intersect_ukey($b_f, $c_f, $d_f, "comp_func"));// -20 + + +echo "----- Now testing array_intersect() ------- \n"; +var_dump(array_intersect($a, $b_f)); +var_dump(array_uintersect($a, $b, "comp_func")); +var_dump(array_intersect($a, $b, $c)); +var_dump(array_uintersect($a, $b, $c, "comp_func")); +var_dump(array_intersect($a, $b, $c, $d)); +var_dump(array_uintersect($a, $b, $c, $d, "comp_func")); + +/////////////////////////////////////////////////////////////////////// +function comp_func($a, $b) { + if ($a === $b) return 0; + return ($a > $b)? 1:-1; + +} +?> +--EXPECTF-- +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(4) { + [6]=> + int(12) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(4) { + [6]=> + int(12) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(3) { + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(4) { + [0]=> + int(0) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(4) { + [0]=> + int(0) + [2]=> + int(4) + [-20]=> + int(-40) + [-2500]=> + &int(-5000) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +array(1) { + [-20]=> + int(-40) +} +----- Now testing array_intersect() ------- +array(0) { +} +array(3) { + [2]=> + int(2) + [3]=> + int(-20) + [6]=> + int(-2500) +} +array(3) { + [2]=> + int(2) + [3]=> + int(-20) + [6]=> + int(-2500) +} +array(3) { + [2]=> + int(2) + [3]=> + int(-20) + [6]=> + int(-2500) +} +array(1) { + [3]=> + int(-20) +} +array(1) { + [3]=> + int(-20) +} diff --git a/ext/standard/tests/array/array_intersect_key_basic.phpt b/ext/standard/tests/array/array_intersect_key_basic.phpt new file mode 100644 index 0000000..fc6e177 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_basic.phpt @@ -0,0 +1,19 @@ +--TEST-- +array_intersect_key(): Basic Test +--FILE-- +<?php +/* +* proto array array_intersect_key(array arr1, array arr2 [, array ...]) +* Function is implemented in ext/standard/array.c +*/ +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_key($array1, $array2)); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_key_error.phpt b/ext/standard/tests/array/array_intersect_key_error.phpt new file mode 100644 index 0000000..9509e97 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_intersect_key() function : error conditions +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : error conditions ***\n"; + +//Initialise function arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + +// Testing array_intersect_key with one less than the expected number of arguments +echo "\n-- Testing array_intersect_key() function with less than expected no. of arguments --\n"; +var_dump( array_intersect_key($array1) ); + +// Testing array_intersect_key with one less than the expected number of arguments +echo "\n-- Testing array_intersect_key() function with no arguments --\n"; +var_dump( array_intersect_key() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : error conditions *** + +-- Testing array_intersect_key() function with less than expected no. of arguments -- + +Warning: array_intersect_key(): at least 2 parameters are required, 1 given in %s on line %d +NULL + +-- Testing array_intersect_key() function with no arguments -- + +Warning: array_intersect_key(): at least 2 parameters are required, 0 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation1.phpt b/ext/standard/tests/array/array_intersect_key_variation1.phpt new file mode 100644 index 0000000..8c245e4 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation1.phpt @@ -0,0 +1,314 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array2 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($value, $array2) ); + var_dump( array_intersect_key($value, $array2, $array3) ); +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation2.phpt b/ext/standard/tests/array/array_intersect_key_variation2.phpt new file mode 100644 index 0000000..3c33deb --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation2.phpt @@ -0,0 +1,315 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($array1, $value) ); + var_dump( array_intersect_key($array1, $value, $array3) ); +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation3.phpt b/ext/standard/tests/array/array_intersect_key_variation3.phpt new file mode 100644 index 0000000..8fd3d3c --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation3.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to optional argument +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr2 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($array1, $array2, $value) ); +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation4.phpt b/ext/standard/tests/array/array_intersect_key_variation4.phpt new file mode 100644 index 0000000..1d3d976 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation4.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing integer indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', -1 => '-1' , 02 => 'two', -07 => '-07', 0xA => '0xA', -0xC => '-0xc'); + +$input_arrays = array( + 'decimal indexed' => array(10 => '10', '-17' => '-17'), + 'octal indexed' => array(-011 => '-011', 012 => '012'), + 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($input_array, $value) ); + var_dump( array_intersect_key($value,$input_array ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--decimal indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [10]=> + string(2) "10" +} + +--octal indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [10]=> + string(3) "012" +} + +--hexa indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-7]=> + string(4) "-0x7" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation5.phpt b/ext/standard/tests/array/array_intersect_key_variation5.phpt new file mode 100644 index 0000000..c286de6 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation5.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing float indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 10 => '10' , -10 => '-10'); +$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5' , -10.5 => '-10.5', 0.5 => '0.5'); + +echo "\n-- Testing array_intersect_key() function with float indexed array --\n"; +var_dump( array_intersect_key($input_array, $float_indx_array) ); +var_dump( array_intersect_key($float_indx_array,$input_array ) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +-- Testing array_intersect_key() function with float indexed array -- +array(3) { + [0]=> + string(1) "0" + [10]=> + string(2) "10" + [-10]=> + string(3) "-10" +} +array(3) { + [0]=> + string(3) "0.5" + [10]=> + string(4) "10.5" + [-10]=> + string(5) "-10.5" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation6.phpt b/ext/standard/tests/array/array_intersect_key_variation6.phpt new file mode 100644 index 0000000..823b070 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation6.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing boolean indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1' , -10 => '-10'); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_intersect_key() function with boolean indexed array --\n"; +var_dump( array_intersect_key($input_array, $boolean_indx_array) ); +var_dump( array_intersect_key($boolean_indx_array,$input_array ) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +-- Testing array_intersect_key() function with boolean indexed array -- +array(2) { + [0]=> + string(1) "0" + [1]=> + string(1) "1" +} +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation7.phpt b/ext/standard/tests/array/array_intersect_key_variation7.phpt new file mode 100644 index 0000000..fe4446a --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation7.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing null,unset and undefeined variable indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1' , -10 => '-10' , null => 'null'); +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($input_array, $value) ); + var_dump( array_intersect_key($value,$input_array ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--null indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(6) "null 2" +} + +--undefined indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(9) "undefined" +} + +--unset indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(5) "unset" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation8.phpt b/ext/standard/tests/array/array_intersect_key_variation8.phpt new file mode 100644 index 0000000..2b889b5 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation8.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing Multi dimensional array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +/// Initialise function arguments not being substituted (if any) +$array1 = array( + + 'first' => array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 =>'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); +var_dump( array_intersect_key($array1, $array2) ); +var_dump( array_intersect_key($array2,$array1 ) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** +array(2) { + ["first"]=> + array(2) { + ["blue"]=> + int(1) + ["red"]=> + int(2) + } + ["second"]=> + array(1) { + ["yellow"]=> + int(7) + } +} +array(2) { + ["first"]=> + array(2) { + ["blue"]=> + int(1) + ["red"]=> + int(2) + } + ["second"]=> + array(1) { + ["cyan"]=> + int(8) + } +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_basic.phpt b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt new file mode 100644 index 0000000..1a2d57e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_intersect_uassoc(): Basic test +--FILE-- +<?php +/* +* array array_intersect_uassoc ( array $array1, array $array2 [, array $..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$result = array_intersect_uassoc($array1, $array2, "key_compare_func"); +var_dump($result); +?> +--EXPECT-- +array(1) { + ["a"]=> + string(5) "green" +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_uassoc_error.phpt b/ext/standard/tests/array/array_intersect_uassoc_error.phpt new file mode 100644 index 0000000..ae7acb1 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_error.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_intersect_uassoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : error conditions ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); +$extra_arg = 10; + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//Test array_intersect_uassoc with one more than the expected number of arguments +echo "\n-- Testing array_intersect_uassoc() function with more than expected no. of arguments --\n"; +var_dump( array_intersect_uassoc($array1, $array2, 'key_compare_func',$extra_arg) ); + +// Testing array_intersect_uassoc with one less than the expected number of arguments +echo "\n-- Testing array_intersect_uassoc() function with less than expected no. of arguments --\n"; +var_dump( array_intersect_uassoc($array1, $array2) ); +var_dump( array_intersect_uassoc($array1, $array2, $array3) ); + +// Testing array_intersect_uassoc with no arguments +echo "\n-- Testing array_intersect_uassoc() function with no arguments --\n"; +var_dump( array_intersect_uassoc() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : error conditions *** + +-- Testing array_intersect_uassoc() function with more than expected no. of arguments -- + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Testing array_intersect_uassoc() function with less than expected no. of arguments -- + +Warning: array_intersect_uassoc(): at least 3 parameters are required, 2 given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, second array member is not a valid method in %s on line %d +NULL + +-- Testing array_intersect_uassoc() function with no arguments -- + +Warning: array_intersect_uassoc(): at least 3 parameters are required, 0 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation1.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation1.phpt new file mode 100644 index 0000000..86dec03 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation1.phpt @@ -0,0 +1,323 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($value, $array2, 'key_compare_func') ); + var_dump( array_intersect_uassoc($value, $array2, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- + +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation10.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation10.phpt new file mode 100644 index 0000000..aa0c82d --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation10.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing class/object methods to callback +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +// define some class with method +class MyClass +{ + static function static_compare_func($a, $b) { + return strcasecmp($a, $b); + } + + public function class_compare_func($a, $b) { + return strcasecmp($a, $b); + } + +} + +echo "\n-- Testing array_intersect_uassoc() function using class with static method as callback --\n"; +var_dump( array_intersect_uassoc($array1, $array2, array('MyClass','static_compare_func')) ); +var_dump( array_intersect_uassoc($array1, $array2, 'MyClass::static_compare_func')); + +echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n"; +$obj = new MyClass(); +var_dump( array_intersect_uassoc($array1, $array2, array($obj,'class_compare_func')) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Testing array_intersect_uassoc() function using class with static method as callback -- +array(1) { + ["a"]=> + string(5) "green" +} +array(1) { + ["a"]=> + string(5) "green" +} + +-- Testing array_intersect_uassoc() function using class with regular method as callback -- +array(1) { + ["a"]=> + string(5) "green" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation11.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation11.phpt new file mode 100644 index 0000000..cf2611a --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation11.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing class without string to callback (Handling fatal error) +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + +class classWithoutToString +{ +} + +$value = new classWithoutToString(); + +var_dump( array_intersect_uassoc($array1, $array2, $value) ); +var_dump( array_intersect_uassoc($array1, $array2, $array3, $value) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** +Error: 2 - array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given, %s(%d) +NULL +Error: 2 - array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given, %s(%d) +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation2.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation2.phpt new file mode 100644 index 0000000..51341bb --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation2.phpt @@ -0,0 +1,323 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array3 = array("a"=>"green", "brown"); + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($array1, $value, 'key_compare_func') ); + var_dump( array_intersect_uassoc($array1, $value, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- + +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation3.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation3.phpt new file mode 100644 index 0000000..f596e9c --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation3.phpt @@ -0,0 +1,244 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to optional third argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($array1, $array2, $value, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- + +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation4.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation4.phpt new file mode 100644 index 0000000..e5d0f56 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation4.phpt @@ -0,0 +1,257 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to mandatory third argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($array1, $array2, $value) ); + var_dump( array_intersect_uassoc($array1, $array2, $array3, $value) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation5.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation5.phpt new file mode 100644 index 0000000..ec7ee81 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation5.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of integers with floats and strings. +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_default_int = array(1, 2 ); +$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00); +$arr_string = array('1', '2', '3'); +$arr_string_float = array('1.00', '2.00'); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +echo "\n-- Result of integers and floating point intersection --\n"; +var_dump( array_intersect_uassoc($arr_default_int, $arr_float, "key_compare_func") ); + +echo "\n-- Result of integers and strings containing integers intersection --\n"; +var_dump( array_intersect_uassoc($arr_default_int, $arr_string, "key_compare_func") ); + +echo "\n-- Result of integers and strings containing floating points intersection --\n"; +var_dump( array_intersect_uassoc($arr_default_int, $arr_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of integers and floating point intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing integers intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing floating points intersection -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation6.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation6.phpt new file mode 100644 index 0000000..55dd46d --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation6.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of floating points with strings. +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_float = array(0 => 1.00, 1.00 => 2.00); +$arr_string = array('1', '2', '3'); +$arr_string_float = array('1.00', '2.00'); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +echo "\n-- Result of floating points and strings containing integers intersection --\n"; +var_dump( array_intersect_uassoc($arr_float, $arr_string, "key_compare_func") ); + +echo "\n-- Result of floating points and strings containing floating point intersection --\n"; +var_dump( array_intersect_uassoc($arr_float, $arr_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of floating points and strings containing integers intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} + +-- Result of floating points and strings containing floating point intersection -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation7.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation7.phpt new file mode 100644 index 0000000..7fa053a --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation7.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of strings containing integers, float +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr1_string_int = array('1', '2'); +$arr2_string_int = array('1', '3'); +$arr1_string_float = array('1.00', '2.00'); +$arr2_string_float = array('1.00', '3.00'); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +echo "\n-- Result of strings containing integers intersection --\n"; +var_dump( array_intersect_uassoc($arr1_string_int, $arr2_string_int, "key_compare_func") ); + +echo "\n-- Result of strings containing floating points intersection --\n"; +var_dump( array_intersect_uassoc($arr1_string_float, $arr2_string_float, "key_compare_func") ); + +echo "\n-- Result of strings containing integers and strings containing floating points intersection --\n"; +var_dump( array_intersect_uassoc($arr1_string_int, $arr2_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of strings containing integers intersection -- +array(1) { + [0]=> + string(1) "1" +} + +-- Result of strings containing floating points intersection -- +array(1) { + [0]=> + string(4) "1.00" +} + +-- Result of strings containing integers and strings containing floating points intersection -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation8.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation8.phpt new file mode 100644 index 0000000..7b218f7 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation8.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - arrays containing referenced variables +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$ref_var = 'a'; +$array1 = array('a', $ref_var); +$array2 = array('a' => 1, &$ref_var); + +echo "\n-- Testing array_intersect_uassoc() function with referenced variable \$ref_var has value '$ref_var' --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); + +// re-assign reference variable to different value +$ref_var = 10; +echo "\n-- Testing array_intersect_uassoc() function with referenced variable \$ref_var value changed to $ref_var --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); + +//When array are referenced +$array2 = &$array1; +echo "\n-- Testing array_intersect_uassoc() function when \$array2 is referencd to \$array1 --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Testing array_intersect_uassoc() function with referenced variable $ref_var has value 'a' -- +array(1) { + [0]=> + string(1) "a" +} + +-- Testing array_intersect_uassoc() function with referenced variable $ref_var value changed to 10 -- +array(0) { +} + +-- Testing array_intersect_uassoc() function when $array2 is referencd to $array1 -- +array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "a" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation9.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation9.phpt new file mode 100644 index 0000000..64f58a6 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation9.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing non-existing function name to callback +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//function name within double quotes +var_dump( array_intersect_uassoc($array1, $array2, "unknown_function") ); + +//function name within single quotes +var_dump( array_intersect_uassoc($array1, $array2, 'unknown_function') ); + +//function name without quotes +var_dump( array_intersect_uassoc($array1, $array2, unknown_function) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Notice: Use of undefined constant unknown_function - assumed 'unknown_function' in %s on line %d + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_ukey_basic.phpt b/ext/standard/tests/array/array_intersect_ukey_basic.phpt new file mode 100644 index 0000000..db21b9b --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +array_intersect_ukey(): Basic test. +--FILE-- +<?php +/* +* proto array array_intersect_ukey ( array $array1, array $array2 [, array $ ..., callback $key_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +function key_compare_func($key1, $key2) { + if ($key1 == $key2) return 0; + else if ($key1 > $key2) return 1; + else return -1; +} +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +var_dump(array_intersect_ukey($array1, $array2, 'key_compare_func')); +?> +--EXPECT-- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} diff --git a/ext/standard/tests/array/array_intersect_ukey_error.phpt b/ext/standard/tests/array/array_intersect_ukey_error.phpt new file mode 100644 index 0000000..bb052fb --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_error.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_intersect_ukey() function : error conditions +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : error conditions ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +//Test array_intersect_ukey with one more than the expected number of arguments +echo "\n-- Testing array_intersect_ukey() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( array_intersect_ukey($array1, $array2, 'key_compare_func',$extra_arg) ); + +// Testing array_intersect_ukey with one less than the expected number of arguments +echo "\n-- Testing array_intersect_ukey() function with less than expected no. of arguments --\n"; +var_dump( array_intersect_ukey($array1, $array2) ); + +// Testing array_intersect_ukey with no arguments +echo "\n-- Testing array_intersect_ukey() function with no arguments --\n"; +var_dump( array_intersect_ukey() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : error conditions *** + +-- Testing array_intersect_ukey() function with more than expected no. of arguments -- + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Testing array_intersect_ukey() function with less than expected no. of arguments -- + +Warning: array_intersect_ukey(): at least 3 parameters are required, 2 given in %s on line %d +NULL + +-- Testing array_intersect_ukey() function with no arguments -- + +Warning: array_intersect_ukey(): at least 3 parameters are required, 0 given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation1.phpt b/ext/standard/tests/array/array_intersect_ukey_variation1.phpt new file mode 100644 index 0000000..7012057 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation1.phpt @@ -0,0 +1,320 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialise arguments +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array('green' => 5, 'cyan' => 8); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_ukey($value, $array2, 'key_compare_func') ); + var_dump( array_intersect_ukey($value, $array2, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +--int 0-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #1 is not an array in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation10.phpt b/ext/standard/tests/array/array_intersect_ukey_variation10.phpt new file mode 100644 index 0000000..69a6500 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation10.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing class without string to callback (Handling fatal error) +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array("a"=>"green", "cyan"); + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + + +class classWithoutToString +{ +} + +$value = new classWithoutToString(); + +var_dump( array_intersect_ukey($array1, $array2, $value) ); +var_dump( array_intersect_ukey($array1, $array2, $array3, $value) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** +Error: 2 - array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given, %s(%d) +NULL +Error: 2 - array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given, %s(%d) +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation2.phpt b/ext/standard/tests/array/array_intersect_ukey_variation2.phpt new file mode 100644 index 0000000..b7a1b07 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation2.phpt @@ -0,0 +1,320 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array('green' => 5, 'cyan' => 8); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_ukey($array1, $value, 'key_compare_func') ); + var_dump( array_intersect_ukey($array1, $value, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +--int 0-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #2 is not an array in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation3.phpt b/ext/standard/tests/array/array_intersect_ukey_variation3.phpt new file mode 100644 index 0000000..1236bcd --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation3.phpt @@ -0,0 +1,290 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing unexpected values to callback argument +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array('green' => 5, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for key_compare_func +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_ukey($array1, $array2, $value) ); + var_dump( array_intersect_ukey($array1, $array2, $array3, $value) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +--int 0-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--empty array-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +--int indexed array-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +--associative array-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +--nested arrays-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation4.phpt b/ext/standard/tests/array/array_intersect_ukey_variation4.phpt new file mode 100644 index 0000000..88eff1e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation4.phpt @@ -0,0 +1,321 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing unexpected values to optional third argument +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array4 = array('green' => 5, 'cyan' => 8); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_ukey($array1, $array2, $value, 'key_compare_func') ); + var_dump( array_intersect_ukey($array1, $array2, $value, $array4, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +--int 0-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL + +Warning: array_intersect_ukey(): Argument #3 is not an array in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation5.phpt b/ext/standard/tests/array/array_intersect_ukey_variation5.phpt new file mode 100644 index 0000000..c1520fb --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation5.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Intersection of integers with floats and strings. +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialize variables +$arr_default_int = array(1, 2 ); +$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00); +$arr_string = array('0' => '1', '1' => '2', '2' => '3'); +$arr_string_float = array('0.00' => '1.00', '1.00' => '2.00'); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of integers and floating point intersection --\n"; +var_dump( array_intersect_ukey($arr_default_int, $arr_float, "key_compare_func") ); + +echo "\n-- Result of integers and strings containing integers intersection --\n"; +var_dump( array_intersect_ukey($arr_default_int, $arr_string, "key_compare_func") ); + +echo "\n-- Result of integers and strings containing floating points intersection --\n"; +var_dump( array_intersect_ukey($arr_default_int, $arr_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Result of integers and floating point intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing integers intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing floating points intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation6.phpt b/ext/standard/tests/array/array_intersect_ukey_variation6.phpt new file mode 100644 index 0000000..a918660 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation6.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Intersection of floating points with strings. +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialize variables +$arr_float = array(0.00 => 1.00, 1.00 => 2.00); +$arr_string = array('0' => '1', '1' => '2', '2' => '3'); +$arr_string_float = array('0.00' => '1.00', '1.00' => '2.00'); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of floating points and strings containing integers intersection --\n"; +var_dump( array_intersect_ukey($arr_float, $arr_string, 'key_compare_func') ); + +echo "\n-- Result of floating points and strings containing floating point intersection --\n"; +var_dump( array_intersect_ukey($arr_float, $arr_string_float, 'key_compare_func') ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Result of floating points and strings containing integers intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} + +-- Result of floating points and strings containing floating point intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation7.phpt b/ext/standard/tests/array/array_intersect_ukey_variation7.phpt new file mode 100644 index 0000000..75b601c --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation7.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Intersection of strings containing integer and float +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialize variables +$arr1_string_int = array('0' => '1', '1' => '2'); +$arr2_string_int = array('0' => '1', '1' => '3'); +$arr1_string_float = array('0.00' => '1.00', '1.00' => '2.00'); +$arr2_string_float = array('0.00' => '1.00', '1.00' => '3.00'); + +//Call back function +function key_compare_func($key1, $key2) +{ + if ($key1 == $key2) + return 0; + else + return ($key1 > $key2)? 1:-1; +} + +echo "\n-- Result of strings containing integers intersection --\n"; +var_dump( array_intersect_ukey($arr1_string_int, $arr2_string_int, 'key_compare_func') ); + +echo "\n-- Result of strings containing floating points intersection --\n"; +var_dump( array_intersect_ukey($arr1_string_float, $arr2_string_float, 'key_compare_func') ); + +echo "\n-- Result of strings containing integers and strings containing floating points intersection --\n"; +var_dump( array_intersect_ukey($arr1_string_int, $arr2_string_float, 'key_compare_func') ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Result of strings containing integers intersection -- +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} + +-- Result of strings containing floating points intersection -- +array(2) { + ["0.00"]=> + string(4) "1.00" + ["1.00"]=> + string(4) "2.00" +} + +-- Result of strings containing integers and strings containing floating points intersection -- +array(2) { + [0]=> + string(1) "1" + [1]=> + string(1) "2" +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation8.phpt b/ext/standard/tests/array/array_intersect_ukey_variation8.phpt new file mode 100644 index 0000000..3d580e1 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation8.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing non-existing function name to callback +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//function name within double quotes +var_dump( array_intersect_ukey($array1, $array2, "unknown_function") ); + +//function name within single quotes +var_dump( array_intersect_ukey($array1, $array2, 'unknown_function') ); + +//function name without quotes +var_dump( array_intersect_ukey($array1, $array2, unknown_function) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Notice: Use of undefined constant unknown_function - assumed 'unknown_function' in %s on line %d + +Warning: array_intersect_ukey() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_ukey_variation9.phpt b/ext/standard/tests/array/array_intersect_ukey_variation9.phpt new file mode 100644 index 0000000..fe130a8 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_ukey_variation9.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_intersect_ukey() function : usage variation - Passing class/object methods to callback +--FILE-- +<?php +/* Prototype : array array_intersect_ukey(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays using a callback function on the keys for comparison. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_ukey() : usage variation ***\n"; + +//Initialise arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +class MyClass +{ + static function static_compare_func($key1, $key2) { + return strcasecmp($key1, $key2); + } + + public function class_compare_func($key1, $key2) { + return strcasecmp($key1, $key2); + } + +} + +echo "\n-- Testing array_intersect_ukey() function using class with static method as callback --\n"; +var_dump( array_intersect_ukey($array1, $array2, array('MyClass','static_compare_func')) ); +var_dump( array_intersect_ukey($array1, $array2, 'MyClass::static_compare_func') ); + +echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n"; +$obj = new MyClass(); +var_dump( array_intersect_ukey($array1, $array2, array($obj,'class_compare_func')) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_ukey() : usage variation *** + +-- Testing array_intersect_ukey() function using class with static method as callback -- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} + +-- Testing array_intersect_uassoc() function using class with regular method as callback -- +array(2) { + ["blue"]=> + int(1) + ["green"]=> + int(3) +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_intersect_variation1.phpt b/ext/standard/tests/array/array_intersect_variation1.phpt new file mode 100644 index 0000000..ca203ff --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation1.phpt @@ -0,0 +1,280 @@ +--TEST-- +Test array_intersect() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_intersect() function by passing values to $arr1 argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $arr2 argument is a fixed array. +*/ + +echo "*** Testing array_intersect() : Passing non-array values to \$arr1 argument ***\n"; + +// array to be passsed to $arr2 as default argument +$arr2 = array(1, 2); + +// array to be passed to optional argument +$arr3 = array(1, 2, "one" => 1, "two" => 2); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$arrays = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $unexpected_value) { + echo "\n-- Iterator $iterator --"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($unexpected_value,$arr2) ); + + // Calling array_intersect() with more arguments + var_dump( array_intersect($unexpected_value, $arr2, $arr3) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : Passing non-array values to $arr1 argument *** + +-- Iterator 1 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 2 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 3 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 4 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 5 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 6 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 7 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 8 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 9 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 10 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 11 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 12 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 13 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 14 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 15 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 16 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 17 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 18 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 19 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 20 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 21 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 22 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 23 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +-- Iterator 24 -- +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_intersect_variation10.phpt b/ext/standard/tests/array/array_intersect_variation10.phpt new file mode 100644 index 0000000..e193f97 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation10.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_intersect() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_intersect() by passing array with +* binary values for $arr1 and $arr2 argument. +*/ + +echo "*** Testing array_intersect() : binary safe checking ***\n"; + +// array with binary values +$arr_binary = array(b"hello", b"world"); +// simple array +$arr_normal = array("hello", "world"); + +// array with binary value for $arr1 argument +var_dump( array_intersect($arr_binary, $arr_normal) ); + +// array with binary value for $arr2 argument +var_dump( array_intersect($arr_normal, $arr_binary) ); + +// array with binary value for both $arr1 and $arr2 argument +var_dump( array_intersect($arr_binary, $arr_binary) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : binary safe checking *** +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation2.phpt b/ext/standard/tests/array/array_intersect_variation2.phpt new file mode 100644 index 0000000..b690fc9 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation2.phpt @@ -0,0 +1,281 @@ +--TEST-- +Test array_intersect() function : usage variations - unexpected values for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_intersect() function by passing values to $arr2 argument other than arrays +* and see that function emits proper warning messages wherever expected. +* The $arr1 argument is a fixed array. +*/ + +echo "*** Testing array_intersect() : Passing non-array values to \$arr2 argument ***\n"; + +// array to be passsed to $arr1 as default argument +$arr1 = array(1, 2); + +// arrays to be passed to optional argument +$arr3 = array(1, 2, "one" => 1, "two" => 2); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$arrays = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $unexpected_value) { + echo "\n-- Iterator $iterator --"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1,$unexpected_value) ); + + // Calling array_intersect() with more arguments + var_dump( array_intersect($arr1, $unexpected_value, $arr3) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : Passing non-array values to $arr2 argument *** + +-- Iterator 1 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 2 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 3 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 4 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 5 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 6 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 7 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 8 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 9 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 10 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 11 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 12 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 13 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 14 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 15 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 16 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 17 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 18 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 19 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 20 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 21 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 22 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 23 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +-- Iterator 24 -- +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_intersect_variation3.phpt b/ext/standard/tests/array/array_intersect_variation3.phpt new file mode 100644 index 0000000..b2b7d8a --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation3.phpt @@ -0,0 +1,342 @@ +--TEST-- +Test array_intersect() function : usage variations - different arrays for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of arrays to $arr1 argument and testing whether +* array_intersect() behaves in expected way with the other arguments passed to the function +* The $arr2 argument is a fixed array. +*/ + +echo "*** Testing array_intersect() : Passing different types of arrays to \$arr1 argument ***\n"; + +/* Different heredoc strings passed as argument to $arr1 */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays to be passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array(false,true), // array with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // array with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings + array($blank_line, $multiline_string, $diff_whitespaces, $numeric_string), // array with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + + +// array to be passsed to $arr2 argument +$arr2 = array ( + 1, 1.1, "hello", "one", NULL, 2, + 'world', true, false, false => 5, 'aaaa\r', "aaaa\r", + $numeric_string, $diff_whitespaces, + "one" => "ten", 4 => "four", "two" => 2, 2 => "two", + '', null => "null", '' => 'emptys' +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : Passing different types of arrays to $arr1 argument *** +-- Iterator 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iterator 2 -- +array(1) { + [0]=> + float(1.1) +} +array(1) { + [0]=> + float(1.1) +} +-- Iterator 3 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iterator 4 -- +array(0) { +} +array(0) { +} +-- Iterator 5 -- +array(1) { + [0]=> + NULL +} +array(1) { + [0]=> + NULL +} +-- Iterator 6 -- +array(1) { + [1]=> + string(5) "aaaa
" +} +array(1) { + [1]=> + string(5) "aaaa
" +} +-- Iterator 7 -- +array(1) { + [1]=> + string(6) "aaaa\r" +} +array(1) { + [1]=> + string(6) "aaaa\r" +} +-- Iterator 8 -- +array(2) { + [2]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [3]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +array(2) { + [2]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [3]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iterator 9 -- +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +-- Iterator 10 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iterator 11 -- +array(0) { +} +array(0) { +} +-- Iterator 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iterator 13 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iterator 14 -- +array(2) { + ["NULL"]=> + NULL + ["null"]=> + NULL +} +array(2) { + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iterator 15 -- +array(2) { + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +array(2) { + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iterator 16 -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iterator 17 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iterator 18 -- +array(1) { + [0]=> + int(5) +} +array(1) { + [0]=> + int(5) +} +-- Iterator 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation4.phpt b/ext/standard/tests/array/array_intersect_variation4.phpt new file mode 100644 index 0000000..4f1d6f3 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation4.phpt @@ -0,0 +1,349 @@ +--TEST-- +Test array_intersect() function : usage variations - different arrays for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Passing different types of arrays to $arr2 argument and testing whether +* array_intersect() behaves in expected way with the other arguments passed to the function. +* The $arr1 argument is a fixed array. +*/ + +echo "*** Testing array_intersect() : Passing different types of arrays to \$arr2 argument ***\n"; + +/* Different heredoc strings passed as argument to $arr2 */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// array to be passsed to $arr1 argument +$arr1 = array ( + 1, 1.1, "hello", "one", NULL, 2, + 'world', true, false, false => 5, 'aaaa\r', "aaaa\r", + $numeric_string, $diff_whitespaces, + "one" => "ten", 4 => "four", "two" => 2, 2 => "two", + '', null => "null", '' => 'emptys' +); + +// arrays to be passed to $arr2 argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array(false,true), // array with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // array with NULL + array("a\v\f","aaaa\r","b","b\tbbb","c","\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // array with double quoted strings + array('a\v\f','aaaa\r','b','b\tbbb','c','\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // array with single quoted strings + array($blank_line, $multiline_string, $diff_whitespaces, $numeric_string), // array with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iteration $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : Passing different types of arrays to $arr2 argument *** +-- Iteration 1 -- +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +-- Iteration 2 -- +array(1) { + [1]=> + float(1.1) +} +array(1) { + [1]=> + float(1.1) +} +-- Iteration 3 -- +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 4 -- +array(0) { +} +array(0) { +} +-- Iteration 5 -- +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 6 -- +array(1) { + [10]=> + string(5) "aaaa
" +} +array(1) { + [10]=> + string(5) "aaaa
" +} +-- Iteration 7 -- +array(1) { + [9]=> + string(6) "aaaa\r" +} +array(1) { + [9]=> + string(6) "aaaa\r" +} +-- Iteration 8 -- +array(2) { + [11]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [12]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +array(2) { + [11]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [12]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- Iteration 9 -- +array(2) { + [2]=> + string(3) "two" + [3]=> + string(3) "one" +} +array(2) { + [2]=> + string(3) "two" + [3]=> + string(3) "one" +} +-- Iteration 10 -- +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +array(3) { + [5]=> + int(2) + [7]=> + bool(true) + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(0) { +} +array(0) { +} +-- Iteration 12 -- +array(1) { + ["one"]=> + string(3) "ten" +} +array(1) { + ["one"]=> + string(3) "ten" +} +-- Iteration 13 -- +array(3) { + [2]=> + string(3) "two" + [4]=> + string(4) "four" + [7]=> + bool(true) +} +array(3) { + [2]=> + string(3) "two" + [4]=> + string(4) "four" + [7]=> + bool(true) +} +-- Iteration 14 -- +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(2) { + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 15 -- +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 16 -- +array(3) { + [8]=> + bool(false) + [13]=> + string(0) "" + [""]=> + string(6) "emptys" +} +array(3) { + [8]=> + bool(false) + [13]=> + string(0) "" + [""]=> + string(6) "emptys" +} +-- Iteration 17 -- +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +array(3) { + [7]=> + bool(true) + [8]=> + bool(false) + [13]=> + string(0) "" +} +-- Iteration 18 -- +array(1) { + [0]=> + int(5) +} +array(1) { + [0]=> + int(5) +} +-- Iteration 19 -- +array(0) { +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation5.phpt b/ext/standard/tests/array/array_intersect_variation5.phpt new file mode 100644 index 0000000..9aaedeb --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation5.phpt @@ -0,0 +1,192 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff keys for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect() by passing different + * associative arrays having different possible keys to $arr1 argument. + * The $arr2 argument is a fixed array +*/ + +echo "*** Testing array_intersect() : assoc array with diff keys to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr1 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with unset variable +/*10*/ array( @$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passsed to $arr2 argument +$arr2 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : assoc array with diff keys to $arr1 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [1]=> + string(1) "1" +} +array(1) { + [1]=> + string(1) "1" +} +-- Iterator 4 -- +array(1) { + [1]=> + string(1) "1" +} +array(1) { + [1]=> + string(1) "1" +} +-- Iterator 5 -- +array(1) { + [2]=> + string(5) "float" +} +array(1) { + [2]=> + string(5) "float" +} +-- Iterator 6 -- +array(1) { + [33333333]=> + string(2) "f4" +} +array(1) { + [33333333]=> + string(2) "f4" +} +-- Iterator 7 -- +array(2) { + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +array(2) { + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +-- Iterator 8 -- +array(2) { + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) +} +array(2) { + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) +} +-- Iterator 9 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iterator 10 -- +array(1) { + [""]=> + string(5) "hello" +} +array(1) { + [""]=> + string(5) "hello" +} +-- Iterator 11 -- +array(3) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [444]=> + string(5) "float" +} +array(3) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [444]=> + string(5) "float" +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation6.phpt b/ext/standard/tests/array/array_intersect_variation6.phpt new file mode 100644 index 0000000..48d01f7 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation6.phpt @@ -0,0 +1,192 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff keys for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect() by passing different + * associative arrays having different possible keys to $arr2 argument. + * The $arr1 argument is a fixed array. +*/ + +echo "*** Testing array_intersect() : assoc array with diff keys to \$arr2 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr2 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with unset variable +/*10*/ array( @$unset_var => "hello"), + + // array with mixed keys +/*11*/ array('hello' => 1, "fruit" => 2.2, + 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// array to be passsed to $arr1 argument +$arr1 = array(1, "float", "f4", "hello", 2.2, 'color', "string", "pen\n", 11); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : assoc array with diff keys to $arr2 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iterator 4 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iterator 5 -- +array(1) { + [1]=> + string(5) "float" +} +array(1) { + [1]=> + string(5) "float" +} +-- Iterator 6 -- +array(1) { + [2]=> + string(2) "f4" +} +array(1) { + [2]=> + string(2) "f4" +} +-- Iterator 7 -- +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +-- Iterator 8 -- +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +array(2) { + [4]=> + float(2.2) + [5]=> + string(5) "color" +} +-- Iterator 9 -- +array(2) { + [3]=> + string(5) "hello" + [6]=> + string(6) "string" +} +array(2) { + [3]=> + string(5) "hello" + [6]=> + string(6) "string" +} +-- Iterator 10 -- +array(1) { + [3]=> + string(5) "hello" +} +array(1) { + [3]=> + string(5) "hello" +} +-- Iterator 11 -- +array(3) { + [0]=> + int(1) + [1]=> + string(5) "float" + [4]=> + float(2.2) +} +array(3) { + [0]=> + int(1) + [1]=> + string(5) "float" + [4]=> + float(2.2) +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation7.phpt b/ext/standard/tests/array/array_intersect_variation7.phpt new file mode 100644 index 0000000..da1088c --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation7.phpt @@ -0,0 +1,211 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect() by passing different + * associative arrays having different possible values to $arr1 argument. + * The $arr2 argument is a fixed array +*/ + +echo "*** Testing array_intersect() : assoc array with diff values to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr1 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable +/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// array to be passsed to $arr2 argument +$arr2 = array(1, 2, 1.2, 2.3333, "col\tor", '\v\fworld', $fp, + "Hello world", $heredoc, new classA(), 444.432, "fruit"); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : assoc array with diff values to $arr1 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [1]=> + int(1) +} +array(1) { + [1]=> + int(1) +} +-- Iterator 4 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iterator 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +array(1) { + ["float"]=> + float(2.3333) +} +-- Iterator 6 -- +array(1) { + ["f1"]=> + float(1.2) +} +array(1) { + ["f1"]=> + float(1.2) +} +-- Iterator 7 -- +array(1) { + ["red"]=> + string(6) "col or" +} +array(1) { + ["red"]=> + string(6) "col or" +} +-- Iterator 8 -- +array(1) { + [2]=> + string(9) "\v\fworld" +} +array(1) { + [2]=> + string(9) "\v\fworld" +} +-- Iterator 9 -- +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +array(1) { + ["heredoc"]=> + string(11) "Hello world" +} +-- Iterator 10 -- +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +array(2) { + [11]=> + object(classA)#%d (0) { + } + ["resource"]=> + resource(%d) of type (stream) +} +-- Iterator 11 -- +array(5) { + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["float"]=> + float(444.432) + ["heredoc"]=> + string(11) "Hello world" +} +array(5) { + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["float"]=> + float(444.432) + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation8.phpt b/ext/standard/tests/array/array_intersect_variation8.phpt new file mode 100644 index 0000000..91eae49 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation8.phpt @@ -0,0 +1,219 @@ +--TEST-- +Test array_intersect() function : usage variations - assoc array with diff values for 'arr2' argument +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_intersect() by passing different + * associative arrays having different possible values to $arr2 argument. + * The $arr1 argument is a fixed array. +*/ + +echo "*** Testing array_intersect() : assoc array with diff values to \$arr2 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different variations of associative arrays to be passed to $arr2 argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable +/*10*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// array to be passsed to $arr1 argument +$arr1 = array(1, 2, 1.2, 2.3333, "col\tor", '\v\fworld', $fp, + "Hello world", $heredoc, new classA(), 444.432, "fruit"); + +// loop through each sub-array within $arrrays to check the behavior of array_intersect() +$iterator = 1; +foreach($arrays as $arr2) { + echo "-- Iterator $iterator --\n"; + + // Calling array_intersect() with default arguments + var_dump( array_intersect($arr1, $arr2) ); + + // Calling array_intersect() with more arguments. + // additional argument passed is the same as $arr1 argument + var_dump( array_intersect($arr1, $arr2, $arr1) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : assoc array with diff values to $arr2 argument *** +-- Iterator 1 -- +array(0) { +} +array(0) { +} +-- Iterator 2 -- +array(0) { +} +array(0) { +} +-- Iterator 3 -- +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(1) +} +-- Iterator 4 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iterator 5 -- +array(1) { + [3]=> + float(2.3333) +} +array(1) { + [3]=> + float(2.3333) +} +-- Iterator 6 -- +array(1) { + [2]=> + float(1.2) +} +array(1) { + [2]=> + float(1.2) +} +-- Iterator 7 -- +array(1) { + [4]=> + string(6) "col or" +} +array(1) { + [4]=> + string(6) "col or" +} +-- Iterator 8 -- +array(1) { + [5]=> + string(9) "\v\fworld" +} +array(1) { + [5]=> + string(9) "\v\fworld" +} +-- Iterator 9 -- +array(2) { + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" +} +array(2) { + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" +} +-- Iterator 10 -- +array(2) { + [6]=> + resource(%d) of type (stream) + [9]=> + object(classA)#%d (0) { + } +} +array(2) { + [6]=> + resource(%d) of type (stream) + [9]=> + object(classA)#%d (0) { + } +} +-- Iterator 11 -- +array(6) { + [6]=> + resource(%d) of type (stream) + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" + [9]=> + object(classA)#%d (0) { + } + [10]=> + float(444.432) + [11]=> + string(5) "fruit" +} +array(6) { + [6]=> + resource(%d) of type (stream) + [7]=> + string(11) "Hello world" + [8]=> + string(11) "Hello world" + [9]=> + object(classA)#%d (0) { + } + [10]=> + float(444.432) + [11]=> + string(5) "fruit" +} +Done diff --git a/ext/standard/tests/array/array_intersect_variation9.phpt b/ext/standard/tests/array/array_intersect_variation9.phpt new file mode 100644 index 0000000..fda63dd --- /dev/null +++ b/ext/standard/tests/array/array_intersect_variation9.phpt @@ -0,0 +1,255 @@ +--TEST-- +Test array_intersect() function : usage variations - two dimensional arrays for $arr1 and $arr2 arguments(Bug#43109) +--FILE-- +<?php +/* Prototype : array array_intersect(array $arr1, array $arr2 [, array $...]) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments + * Source code: ext/standard/array.c +*/ + +/* +* Testing the behavior of array_intersect() by passing 2-D arrays +* to both $arr1 and $arr2 argument. +* Optional argument takes the same value as that of $arr1 +*/ + +echo "*** Testing array_intersect() : passing two dimensional array to both \$arr1 and \$arr2 arguments ***\n"; + +// two dimensional arrays for $arr1 and $arr2 argument +$arr1 = array ( + + // arrays with default keys + array(1, 2, "hello", 'world'), + array(1, 2, 3, 4), + + // arrays with explicit keys + array(1 => "one", 2 => "two", 3 => "three"), + array("ten" => 10, "twenty" => 20.00, "thirty" => 30) +); + +$arr2 = array ( + array(1, 2, 3, 4), + array(1 => "one", 2 => "two", 3 => "three") +); + +/* Passing the entire array as argument to $arr1 and $arr2 */ +// Calling array_intersect() with default arguments +echo "-- Passing the entire 2-D array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect($arr1, $arr2) ); + +// Calling array_intersect() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect($arr1, $arr2, $arr1) ); + +/* Passing the sub-array as argument to $arr1 and $arr2 */ +// Calling array_intersect() with default arguments +echo "-- Passing the sub-array to \$arr1 and \$arr2 --\n"; +echo "- With default arguments -\n"; +var_dump( array_intersect($arr1[0], $arr2[0]) ); + +// Calling array_intersect() with more arguments +// additional argument passed is the same as $arr1 +echo "- With more arguments -\n"; +var_dump( array_intersect($arr1[0], $arr2[0], $arr1[0]) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_intersect() : passing two dimensional array to both $arr1 and $arr2 arguments *** +-- Passing the entire 2-D array to $arr1 and $arr2 -- +- With default arguments - + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + } + [3]=> + array(3) { + ["ten"]=> + int(10) + ["twenty"]=> + float(20) + ["thirty"]=> + int(30) + } +} +- With more arguments - + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d + +Notice: Array to string conversion in %sarray_intersect_variation9.php on line %d +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + } + [3]=> + array(3) { + ["ten"]=> + int(10) + ["twenty"]=> + float(20) + ["thirty"]=> + int(30) + } +} +-- Passing the sub-array to $arr1 and $arr2 -- +- With default arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +- With more arguments - +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_key_exists.phpt b/ext/standard/tests/array/array_key_exists.phpt new file mode 100644 index 0000000..f433e12 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists.phpt @@ -0,0 +1,292 @@ +--TEST-- +Test array_key_exists() function +--FILE-- +<?php +/* Prototype: + * bool array_key_exists ( mixed $key, array $search ); + * Description: + * Returns TRUE if the given key is set in the array. + * key can be any value possible for an array index. + * Also also works on objects. + */ + +echo "*** Testing basic functionalities ***\n"; +/* Arrays with regular values */ +$search_arrays = array( + array(1,2,3,4), + array('a','b','c'), + array('abc', 'bcd', 'dcf'), + array("test", "rest", "enjoy"), + array("Name" => "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 ); + +$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 + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d +NULL + +Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d +NULL + +Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d +NULL + +Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d +NULL + +Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d +NULL + +Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d +NULL + +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(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) +Done diff --git a/ext/standard/tests/array/array_key_exists_basic.phpt b/ext/standard/tests/array/array_key_exists_basic.phpt new file mode 100644 index 0000000..6fbd415 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_key_exists() function : basic functionality +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Test basic functionality of array_key_exists() + */ + +echo "*** Testing array_key_exists() : basic functionality ***\n"; + +$key1 = 'key'; +$key2 = 'val'; +$search = array('one', 'key' => 'value', 'val'); +var_dump(array_key_exists($key1, $search)); +var_dump(array_key_exists($key2, $search)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_key_exists() : basic functionality *** +bool(true) +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_error.phpt b/ext/standard/tests/array/array_key_exists_error.phpt new file mode 100644 index 0000000..8b189c8 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_key_exists() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass incorrect number of arguments to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : error conditions ***\n"; + +//Test array_key_exists with one more than the expected number of arguments +echo "\n-- Testing array_key_exists() function with more than expected no. of arguments --\n"; +$key = 1; +$search = array(1, 2); +$extra_arg = 10; +var_dump( array_key_exists($key, $search, $extra_arg) ); + +// Testing array_key_exists with one less than the expected number of arguments +echo "\n-- Testing array_key_exists() function with less than expected no. of arguments --\n"; +$key = 1; +var_dump( array_key_exists($key) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : error conditions *** + +-- Testing array_key_exists() function with more than expected no. of arguments -- + +Warning: array_key_exists() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +-- Testing array_key_exists() function with less than expected no. of arguments -- + +Warning: array_key_exists() expects exactly 2 parameters, 1 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_object1.phpt b/ext/standard/tests/array/array_key_exists_object1.phpt new file mode 100644 index 0000000..4ffafc4 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_object1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_key_exists() function : object functionality +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Test basic functionality of array_key_exists() with objects + */ + +echo "*** Testing array_key_exists() : object functionality ***\n"; + +class myClass { + var $var1; + var $var2; + var $var3; + + function __construct($a, $b, $c = null) { + $this->var1 = $a; + $this->var2 = $b; + if (!is_null($c)) { + $this->var3 = $c; + } + } +} + +echo "\n-- Do not assign a value to \$class1->var3 --\n"; +$class1 = new myClass ('a', 'b'); +echo "\$key = var1:\n"; +var_dump(array_key_exists('var1', $class1)); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class1)); +echo "\$class1:\n"; +var_dump($class1); + +echo "\n-- Assign a value to \$class2->var3 --\n"; +$class2 = new myClass('x', 'y', 'z'); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class2)); +echo "\$class2:\n"; +var_dump($class2); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : object functionality *** + +-- Do not assign a value to $class1->var3 -- +$key = var1: +bool(true) +$key = var3: +bool(true) +$class1: +object(myClass)#1 (3) { + [%b|u%"var1"]=> + %unicode|string%(1) "a" + [%b|u%"var2"]=> + %unicode|string%(1) "b" + [%b|u%"var3"]=> + NULL +} + +-- Assign a value to $class2->var3 -- +$key = var3: +bool(true) +$class2: +object(myClass)#2 (3) { + [%b|u%"var1"]=> + %unicode|string%(1) "x" + [%b|u%"var2"]=> + %unicode|string%(1) "y" + [%b|u%"var3"]=> + %unicode|string%(1) "z" +} +Done diff --git a/ext/standard/tests/array/array_key_exists_object2.phpt b/ext/standard/tests/array/array_key_exists_object2.phpt new file mode 100644 index 0000000..39bb129 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_object2.phpt @@ -0,0 +1,84 @@ +--TEST-- +Test array_key_exists() function : object functionality - different visibilities +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass array_key_exists() an object with private and protected properties + */ + +echo "*** Testing array_key_exists() : object functionality ***\n"; + +class myClass { + public $var1; + protected $var2; + private $var3; + + function __construct($a, $b, $c = null) { + $this->var1 = $a; + $this->var2 = $b; + if (!is_null($c)) { + $this->var3 = $c; + } + } +} + +echo "\n-- Do not assign a value to \$class1->var3 --\n"; +$class1 = new myClass ('a', 'b'); +echo "\$key = var1:\n"; +var_dump(array_key_exists('var1', $class1)); +echo "\$key = var2:\n"; +var_dump(array_key_exists('var2', $class1)); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class1)); +echo "\$class1:\n"; +var_dump($class1); + +echo "\n-- Assign a value to \$class2->var3 --\n"; +$class2 = new myClass('x', 'y', 'z'); +echo "\$key = var3:\n"; +var_dump(array_key_exists('var3', $class2)); +echo "\$class2:\n"; +var_dump($class2); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : object functionality *** + +-- Do not assign a value to $class1->var3 -- +$key = var1: +bool(true) +$key = var2: +bool(false) +$key = var3: +bool(false) +$class1: +object(myClass)#1 (3) { + [%b|u%"var1"]=> + %unicode|string%(1) "a" + [%b|u%"var2":protected]=> + %unicode|string%(1) "b" + [%b|u%"var3":%b|u%"myClass":private]=> + NULL +} + +-- Assign a value to $class2->var3 -- +$key = var3: +bool(false) +$class2: +object(myClass)#2 (3) { + [%b|u%"var1"]=> + %unicode|string%(1) "x" + [%b|u%"var2":protected]=> + %unicode|string%(1) "y" + [%b|u%"var3":%b|u%"myClass":private]=> + %unicode|string%(1) "z" +} +Done diff --git a/ext/standard/tests/array/array_key_exists_variation1.phpt b/ext/standard/tests/array/array_key_exists_variation1.phpt new file mode 100644 index 0000000..2f50d3e --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation1.phpt @@ -0,0 +1,203 @@ +--TEST-- +Test array_key_exists() function : usage variations - Pass different data types as $key arg +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass different data types as $key argument to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$search = array ('zero', 'key' => 'val', 'two'); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "key"; + } +} + +// heredoc string +$heredoc = <<<EOT +key +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $key argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "key", + 'key', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_key_exists($input, $search) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- +bool(true) + +-- Iteration 2 -- +bool(true) + +-- Iteration 3 -- +bool(false) + +-- Iteration 4 -- +bool(false) + +-- Iteration 5 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 10 -- +bool(false) + +-- Iteration 11 -- +bool(false) + +-- Iteration 12 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 16 -- +bool(false) + +-- Iteration 17 -- +bool(false) + +-- Iteration 18 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 19 -- +bool(true) + +-- Iteration 20 -- +bool(true) + +-- Iteration 21 -- +bool(true) + +-- Iteration 22 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) + +-- Iteration 23 -- +bool(false) + +-- Iteration 24 -- +bool(false) + +-- Iteration 25 -- + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation2.phpt b/ext/standard/tests/array/array_key_exists_variation2.phpt new file mode 100644 index 0000000..a6e9cd2 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation2.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test array_key_exists() function : usage variations - Pass differnt data types to $search arg +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass different data types as $search argument to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$key = 'val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $search argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_key_exists($key, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- + +Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_key_exists() expects parameter 2 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_key_exists() expects parameter 2 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_key_exists() expects parameter 2 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_key_exists() expects parameter 2 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_key_exists() expects parameter 2 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_key_exists() expects parameter 2 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_key_exists_variation3.phpt b/ext/standard/tests/array/array_key_exists_variation3.phpt new file mode 100644 index 0000000..e8a52a7 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation3.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_key_exists() function : usage variations - floats and casting to ints +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass floats as $key argument, then cast float values + * to integers and pass as $key argument + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$keys = array(1.2345678900E-10, 1.00000000000001, 1.99999999999999); + +$search = array ('zero', 'one', 'two'); + +$iterator = 1; +foreach($keys as $key) { + echo "\n-- Iteration $iterator --\n"; + echo "Pass float as \$key:\n"; + var_dump(array_key_exists($key, $search)); + echo "Cast float to int:\n"; + var_dump(array_key_exists((int)$key, $search)); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1 -- +Pass float as $key: + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Cast float to int: +bool(true) + +-- Iteration 1 -- +Pass float as $key: + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Cast float to int: +bool(true) + +-- Iteration 1 -- +Pass float as $key: + +Warning: array_key_exists(): The first argument should be either a string or an integer in %s on line %d +bool(false) +Cast float to int: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation4.phpt b/ext/standard/tests/array/array_key_exists_variation4.phpt new file mode 100644 index 0000000..84dfeb9 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation4.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test array_key_exists() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass referenced variables as arguments to array_key_exists() to test behaviour + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$array = array('one' => 1, 'two' => 2, 'three' => 3); + +echo "\n-- \$search is a reference to \$array --\n"; +$search = &$array; +var_dump(array_key_exists('one', $search)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- $search is a reference to $array -- +bool(true) +Done diff --git a/ext/standard/tests/array/array_key_exists_variation5.phpt b/ext/standard/tests/array/array_key_exists_variation5.phpt new file mode 100644 index 0000000..9c15759 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation5.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_key_exists() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Test how array_key_exists() behaves with multi-dimensional arrays + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$multi_array = array ('zero' => 'val1', + 'one' => 'val2', + 'sub1' => array (1, 2, 3)); + +echo "\n-- Attempt to match key in sub-array --\n"; +// this key is in the sub-array +var_dump(array_key_exists(0, $multi_array)); + +echo "\n-- \$search arg points to sub-array --\n"; +var_dump(array_key_exists(0, $multi_array['sub1'])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Attempt to match key in sub-array -- +bool(false) + +-- $search arg points to sub-array -- +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation6.phpt b/ext/standard/tests/array/array_key_exists_variation6.phpt new file mode 100644 index 0000000..d19e58e --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation6.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test array_key_exists() function : usage variations - equality test for certain data types +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass certain data types that can be taken as a key in an array + * and test whether array_key_exists(() thinks they are equal and therefore + * returns true when searching for them + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$unset = 10; +unset($unset); +$array = array ('null' => null, + 'NULL' => NULL, + 'empty single quoted string' => '', + "empty double quoted string" => "", + 'undefined variable' => @$undefined, + 'unset variable' => @$unset); + +//iterate through original array +foreach($array as $name => $input) { + $iterator = 1; + echo "\n-- Key in \$search array is : $name --\n"; + $search[$input] = 'test'; + + //iterate through array again to see which values are considered equal + foreach($array as $key) { + echo "Iteration $iterator: "; + var_dump(array_key_exists($key, $search)); + $iterator++; + } + $search = null; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Key in $search array is : null -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : NULL -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : empty single quoted string -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : empty double quoted string -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : undefined variable -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) + +-- Key in $search array is : unset variable -- +Iteration 1: bool(true) +Iteration 2: bool(true) +Iteration 3: bool(true) +Iteration 4: bool(true) +Iteration 5: bool(true) +Iteration 6: bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation7.phpt b/ext/standard/tests/array/array_key_exists_variation7.phpt new file mode 100644 index 0000000..845c1e5 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation7.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_key_exists() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Check the position of the internal array pointer after calling array_key_exists() + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_key_exists() --\n"; +var_dump($result = array_key_exists('one', $input)); + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Call array_key_exists() -- +bool(true) + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_key_exists_variation8.phpt b/ext/standard/tests/array/array_key_exists_variation8.phpt new file mode 100644 index 0000000..d5bad62 --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation8.phpt @@ -0,0 +1,547 @@ +--TEST-- +Test array_key_exists() function : usage variations - array keys are different data types +--FILE-- +<?php +/* Prototype : bool array_key_exists(mixed $key, array $search) + * Description: Checks if the given key or index exists in the array + * Source code: ext/standard/array.c + * Alias to functions: key_exists + */ + +/* + * Pass an array where the keys are different data types as the $search argument + * then pass many different data types as $key argument to test where array_key_exist() + * returns true. + */ + +echo "*** Testing array_key_exists() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +string +EOT; + +// different data types to be iterated over +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + + 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_key_exists() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator: $type data --\n"; + + //iterate over again to get all different key values + foreach ($inputs as $new_type => $new_input) { + echo "-- \$key arguments are $new_type data:\n"; + foreach ($new_input as $key => $search) { + var_dump(array_key_exists($key, $input)); + } + } + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- Iteration 1: int data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(true) +bool(true) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 2: float data -- +-- $key arguments are int data: +bool(true) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(true) +bool(true) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(true) +-- $key arguments are bool uppercase data: +bool(false) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 3: extreme floats data -- +-- $key arguments are int data: +bool(true) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(true) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(true) +-- $key arguments are bool uppercase data: +bool(false) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 4: null uppercase data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 5: null lowercase data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 6: bool lowercase data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 7: bool uppercase data -- +-- $key arguments are int data: +bool(true) +bool(true) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(true) +-- $key arguments are extreme floats data: +bool(false) +bool(true) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(true) +bool(true) +-- $key arguments are bool uppercase data: +bool(true) +bool(true) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 8: empty double quotes data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 9: empty single quotes data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 10: string data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(false) +-- $key arguments are null lowercase data: +bool(false) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(false) +-- $key arguments are empty single quotes data: +bool(false) +-- $key arguments are string data: +bool(true) +bool(true) +bool(true) +-- $key arguments are undefined data: +bool(false) +-- $key arguments are unset data: +bool(false) + +-- Iteration 11: undefined data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) + +-- Iteration 12: unset data -- +-- $key arguments are int data: +bool(false) +bool(false) +bool(false) +bool(false) +-- $key arguments are float data: +bool(false) +bool(false) +bool(false) +-- $key arguments are extreme floats data: +bool(false) +bool(false) +-- $key arguments are null uppercase data: +bool(true) +-- $key arguments are null lowercase data: +bool(true) +-- $key arguments are bool lowercase data: +bool(false) +bool(false) +-- $key arguments are bool uppercase data: +bool(false) +bool(false) +-- $key arguments are empty double quotes data: +bool(true) +-- $key arguments are empty single quotes data: +bool(true) +-- $key arguments are string data: +bool(false) +bool(false) +bool(false) +-- $key arguments are undefined data: +bool(true) +-- $key arguments are unset data: +bool(true) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_keys_basic.phpt b/ext/standard/tests/array/array_keys_basic.phpt new file mode 100644 index 0000000..80b624b --- /dev/null +++ b/ext/standard/tests/array/array_keys_basic.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test array_keys() function (basic) +--FILE-- +<?php + +echo "*** Testing array_keys() on basic array operation ***\n"; +$basic_arr = array("a" => 1, "b" => 2, 2.0 => 2.0, -23.45 => "asdasd", + array(1,2,3)); +var_dump(array_keys($basic_arr)); + +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) +} +Done diff --git a/ext/standard/tests/array/array_keys_error.phpt b/ext/standard/tests/array/array_keys_error.phpt new file mode 100644 index 0000000..316e91d --- /dev/null +++ b/ext/standard/tests/array/array_keys_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_keys() function (error conditions) +--FILE-- +<?php + +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 + +echo "Done\n"; +?> +--EXPECTF-- +*** 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_keys_variation_001.phpt b/ext/standard/tests/array/array_keys_variation_001.phpt new file mode 100644 index 0000000..1891c13 --- /dev/null +++ b/ext/standard/tests/array/array_keys_variation_001.phpt @@ -0,0 +1,147 @@ +--TEST-- +Test array_keys() function (variation - 1) +--FILE-- +<?php + +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 "Done\n"; +?> +--EXPECTF-- +*** 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) "" +} +Done diff --git a/ext/standard/tests/array/array_keys_variation_002.phpt b/ext/standard/tests/array/array_keys_variation_002.phpt new file mode 100644 index 0000000..d5df95b --- /dev/null +++ b/ext/standard/tests/array/array_keys_variation_002.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_keys() function (variation - 2) +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php + +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 "Done\n"; +?> +--EXPECTF-- +*** 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) { +} +Done diff --git a/ext/standard/tests/array/array_keys_variation_002_64bit.phpt b/ext/standard/tests/array/array_keys_variation_002_64bit.phpt new file mode 100644 index 0000000..c0a034e --- /dev/null +++ b/ext/standard/tests/array/array_keys_variation_002_64bit.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_keys() function (variation - 2) +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php + +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 "Done\n"; +?> +--EXPECTF-- +*** Testing array_keys() on range of values *** +array(6) { + [0]=> + int(2147483647) + [1]=> + int(2147483648) + [2]=> + int(-2147483647) + [3]=> + int(-2147483648) + [4]=> + int(-2147483649) + [5]=> + 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) { +} +Done diff --git a/ext/standard/tests/array/array_keys_variation_003.phpt b/ext/standard/tests/array/array_keys_variation_003.phpt new file mode 100644 index 0000000..5ccf542 --- /dev/null +++ b/ext/standard/tests/array/array_keys_variation_003.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test array_keys() function (variation - 3) +--FILE-- +<?php + +echo "*** Testing array_keys() on all the types other than arrays ***\n"; +$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){ + var_dump($value); + var_dump(array_keys($types_arr, $value)); +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_keys() on all the types other than arrays *** +bool(true) +array(3) { + [0]=> + int(1) + [1]=> + int(-1) + [2]=> + string(3) "php" +} +bool(false) +array(4) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(0) "" +} +int(1) +array(1) { + [0]=> + int(1) +} +int(0) +array(4) { + [0]=> + int(0) + [1]=> + int(2) + [2]=> + string(3) "php" + [3]=> + string(0) "" +} +int(-1) +array(1) { + [0]=> + int(-1) +} +string(1) "1" +array(1) { + [0]=> + int(1) +} +string(1) "0" +array(1) { + [0]=> + int(0) +} +string(2) "-1" +array(1) { + [0]=> + int(-1) +} +NULL +array(3) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + string(0) "" +} +array(0) { +} +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +string(3) "php" +array(1) { + [0]=> + string(3) "php" +} +string(0) "" +array(2) { + [0]=> + int(2) + [1]=> + string(0) "" +} +Done diff --git a/ext/standard/tests/array/array_keys_variation_004.phpt b/ext/standard/tests/array/array_keys_variation_004.phpt new file mode 100644 index 0000000..1a4f0fc --- /dev/null +++ b/ext/standard/tests/array/array_keys_variation_004.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test array_keys() function (variation - 4) +--FILE-- +<?php + +echo "*** Testing array_keys() on all the types other than arrays ***\n"; +$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){ + var_dump(array_keys($types_arr, $value, TRUE)); +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_keys() on all the types other than arrays *** +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(1) { + [0]=> + int(1) +} +array(1) { + [0]=> + int(0) +} +array(1) { + [0]=> + int(-1) +} +array(1) { + [0]=> + int(2) +} +array(1) { + [0]=> + int(3) +} +array(1) { + [0]=> + string(3) "php" +} +array(1) { + [0]=> + string(0) "" +} +Done diff --git a/ext/standard/tests/array/array_keys_variation_005.phpt b/ext/standard/tests/array/array_keys_variation_005.phpt new file mode 100644 index 0000000..9a912d6 --- /dev/null +++ b/ext/standard/tests/array/array_keys_variation_005.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_keys() function (variation - 5) +--FILE-- +<?php + +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 + +/* Closing the resource handles */ +fclose( $resource1 ); +closedir( $resource2 ); + +?> +--EXPECTF-- +*** 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) +} diff --git a/ext/standard/tests/array/array_map_001.phpt b/ext/standard/tests/array/array_map_001.phpt new file mode 100644 index 0000000..646eb76 --- /dev/null +++ b/ext/standard/tests/array/array_map_001.phpt @@ -0,0 +1,23 @@ +--TEST-- +array_map() and exceptions in the callback +--FILE-- +<?php + +$a = array(1,2,3); + +function foo() { + throw new exception(1); +} + +try { + array_map("foo", $a, array(2,3)); +} catch (Exception $e) { + var_dump("exception caught!"); +} + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_map(): An error occurred while invoking the map callback in %s on line %d +string(17) "exception caught!" +Done diff --git a/ext/standard/tests/array/array_map_basic.phpt b/ext/standard/tests/array/array_map_basic.phpt new file mode 100644 index 0000000..53a7bb4 --- /dev/null +++ b/ext/standard/tests/array/array_map_basic.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_map() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_map() : basic functionality ***\n"; + +function multiply($p, $q) { + return ($p * $q); +} + +function square($p) { + return ($p * $p); +} + +function concatenate($a, $b) { + return "$a = $b"; +} + +// integer array +$arr1 = array(1, 2, 3); +$arr2 = array(4, 5, 6); + +echo "-- With two integer array --\n"; +var_dump( array_map('multiply', $arr1, $arr2) ); + +echo "-- With single integer array --\n"; +var_dump( array_map('square', $arr1) ); + +// string array +$arr1 = array("one", "two"); +$arr2 = array("single", "double"); + +echo "-- With string array --\n"; +var_dump( array_map('concatenate', $arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : basic functionality *** +-- With two integer array -- +array(3) { + [0]=> + int(4) + [1]=> + int(10) + [2]=> + int(18) +} +-- With single integer array -- +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} +-- With string array -- +array(2) { + [0]=> + string(12) "one = single" + [1]=> + string(12) "two = double" +} +Done diff --git a/ext/standard/tests/array/array_map_error.phpt b/ext/standard/tests/array/array_map_error.phpt new file mode 100644 index 0000000..7c623ec --- /dev/null +++ b/ext/standard/tests/array/array_map_error.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_map() function : error conditions +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_map() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_map() function with Zero arguments --\n"; +var_dump( array_map() ); + +// Testing array_map with one less than the expected number of arguments +echo "\n-- Testing array_map() function with one less than expected no. of arguments --\n"; +function callback1() { + return 1; +} +var_dump( array_map('callback1') ); + +echo "\n-- Testing array_map() function with less no. of arrays than callback function arguments --\n"; +$arr1 = array(1, 2); +function callback2($p, $q) { + return $p * $q; +} +var_dump( array_map('callback2', $arr1) ); + +echo "\n-- Testing array_map() function with more no. of arrays than callback function arguments --\n"; +$arr2 = array(3, 4); +$arr3 = array(5, 6); +var_dump( array_map('callback2', $arr1, $arr2, $arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : error conditions *** + +-- Testing array_map() function with Zero arguments -- + +Warning: array_map() expects at least 2 parameters, 0 given in %s on line %d%d +NULL + +-- Testing array_map() function with one less than expected no. of arguments -- + +Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d%d +NULL + +-- Testing array_map() function with less no. of arrays than callback function arguments -- + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: q in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: q in %s on line %d%d +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} + +-- Testing array_map() function with more no. of arrays than callback function arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(8) +} +Done diff --git a/ext/standard/tests/array/array_map_object1.phpt b/ext/standard/tests/array/array_map_object1.phpt new file mode 100644 index 0000000..b96338c --- /dev/null +++ b/ext/standard/tests/array/array_map_object1.phpt @@ -0,0 +1,206 @@ +--TEST-- +Test array_map() function : usage variations - object functionality +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Testing array_map() for object functionalities: + * 1) simple class with variable and method + * 2) class without members + * 3) class with only one method and no variable + * 4) abstract and child class + * 5) class with static and final members + * 6) interface and implemented class + */ +echo "*** Testing array_map() : object functionality ***\n"; + +echo "-- simple class with public variable and method --\n"; +class SimpleClass +{ + public $var1 = 1; + public function square($n) { + return $n * $n; + } +} +function test($cb, $args) { + echo join('::', $cb) . "\n"; + var_dump(array_map($cb, $args)); +} +test(array('SimpleClass', 'square'), array(1, 2)); + +echo "\n-- simple class with private variable and method --\n"; +class SimpleClassPri +{ + private $var1 = 10; + private function add($n) { + return $var + $n; + } +} +test(array('SimpleClassPri', 'add'), array(1)); + +echo "\n-- simple class with protected variable and method --\n"; +class SimpleClassPro +{ + protected $var1 = 5; + protected function mul($n) { + return $var1 * $n; + } +} +test(array('SimpleClassPro', 'mul'), array(2)); + +echo "\n-- class without members --\n"; +class EmptyClass +{ +} +test(array('EmptyClass'), array(1, 2)); + +echo "\n-- abstract class --\n"; +abstract class AbstractClass +{ + protected $var2 = 5; + abstract function emptyFunction(); +} + +// class deriving the above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public function emptyFunction() { + echo "defined in child\n"; + } +} +test(array('ChildClass', 'emptyFunction'), array(1, 2)); + +echo "\n-- class with final method --\n"; +class FinalClass +{ + private $var4; + final function finalMethod() { + echo "This function can't be overloaded\n"; + } +} +test(array('FinalClass', 'finalMethod'), array(1, 2)); + +echo "\n-- class with static members --\n"; +class StaticClass +{ + static $var5 = 2; + public static function square($n) { + return ($n * $n); + } + private static function cube($n) { + return ($n * $n * $n); + } + protected static function retVal($n) { + return array($n); + } +} +test(array('StaticClass', 'square'), array(1, 2)); +test(array('StaticClass', 'cube'), array(2)); +test(array('StaticClass', 'retVal'), array(3, 4)); + +echo "-- class implementing an interface --\n"; +interface myInterface +{ + public function toImplement(); +} +class InterClass implements myInterface +{ + public static function square($n) { + return ($n * $n); + } + public function toImplement() { + return 1; + } +} +test(array('InterClass', 'square'), array(1, 2)); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +*** Testing array_map() : object functionality *** +-- simple class with public variable and method -- +SimpleClass::square + +Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method SimpleClass::square() should not be called statically in %sarray_map_object1.php on line %d +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +-- simple class with private variable and method -- +SimpleClassPri::add + +Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method SimpleClassPri::add() in %sarray_map_object1.php on line %d +NULL + +-- simple class with protected variable and method -- +SimpleClassPro::mul + +Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method SimpleClassPro::mul() in %sarray_map_object1.php on line %d +NULL + +-- class without members -- +EmptyClass + +Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %sarray_map_object1.php on line %d +NULL + +-- abstract class -- +ChildClass::emptyFunction + +Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method ChildClass::emptyFunction() should not be called statically in %sarray_map_object1.php on line %d +defined in child +defined in child +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with final method -- +FinalClass::finalMethod + +Strict Standards: array_map() expects parameter 1 to be a valid callback, non-static method FinalClass::finalMethod() should not be called statically in %sarray_map_object1.php on line %d +This function can't be overloaded +This function can't be overloaded +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with static members -- +StaticClass::square +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} +StaticClass::cube + +Warning: array_map() expects parameter 1 to be a valid callback, cannot access private method StaticClass::cube() in %sarray_map_object1.php on line %d +NULL +StaticClass::retVal + +Warning: array_map() expects parameter 1 to be a valid callback, cannot access protected method StaticClass::retVal() in %sarray_map_object1.php on line %d +NULL +-- class implementing an interface -- +InterClass::square +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} +===DONE=== diff --git a/ext/standard/tests/array/array_map_object2.phpt b/ext/standard/tests/array/array_map_object2.phpt new file mode 100644 index 0000000..c98b2cf --- /dev/null +++ b/ext/standard/tests/array/array_map_object2.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_map() function : object functionality - with non-existent class and method +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Testing array_map() for following object functionalities: + * 1) non-existent class + * 2) existent class and non-existent function + */ +echo "*** Testing array_map() : with non-existent class and method ***\n"; + +class SimpleClass +{ + public $var1 = 1; + public function square($n) { + return $n * $n; + } + public static function cube($n) { + return $n * $n * $n; + } +} + +echo "-- with non-existent class --\n"; +var_dump( array_map(array('non-existent', 'square'), array(1, 2)) ); + +echo "-- with existent class and non-existent method --\n"; +var_dump( array_map(array('SimpleClass', 'non-existent'), array(1, 2)) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : with non-existent class and method *** +-- with non-existent class -- + +Warning: array_map() expects parameter 1 to be a valid callback, class 'non-existent' not found in %s on line %d +NULL +-- with existent class and non-existent method -- + +Warning: array_map() expects parameter 1 to be a valid callback, class 'SimpleClass' does not have a method 'non-existent' in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_object3.phpt b/ext/standard/tests/array/array_map_object3.phpt new file mode 100644 index 0000000..9424c44 --- /dev/null +++ b/ext/standard/tests/array/array_map_object3.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test array_map() function : object functionality - class methods as callback function +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Testing array_map() for object functionality with following callback function variations: + * 1) child class method using parent object + * 2) parent class method using child object + * 3) child class method using parent class + * 4) parent class method using child class + */ +echo "*** Testing array_map() : class methods as callback function ***\n"; + +$arr1 = array(1, 5, 7); + +class ParentClass +{ + public $var1 = 10; + public static function staticParent1($n) { + return $n; + } + private static function staticParent2($n) { + return $n; + } +} + +class ChildClass extends ParentClass +{ + var $parent_obj; + public function __construct ( ) { + $this->parent_obj = new ParentClass(); + } + public $var2 = 5; + public static function staticChild($n) { + return $n; + } + public function nonstaticChild($n) { + return $n; + } +} + +$childobj = new ChildClass(); +$parentobj = new ParentClass(); + +echo "-- accessing parent method from child class --\n"; +var_dump( array_map(array('ChildClass', 'staticParent1'), $arr1) ); + +echo "-- accessing child method from parent class --\n"; +var_dump( array_map(array('ParentClass', 'staticChild'), $arr1) ); + +echo "-- accessing parent method using child class object --\n"; +var_dump( array_map(array($childobj, 'staticParent1'), $arr1) ); + +echo "-- accessing child method using parent class object --\n"; +var_dump( array_map(array($parentobj, 'staticChild'), $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : class methods as callback function *** +-- accessing parent method from child class -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method from parent class -- + +Warning: array_map() expects parameter 1 to be a valid callback, class 'ParentClass' does not have a method 'staticChild' in %s on line %d +NULL +-- accessing parent method using child class object -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method using parent class object -- + +Warning: array_map() expects parameter 1 to be a valid callback, class 'ParentClass' does not have a method 'staticChild' in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation1.phpt b/ext/standard/tests/array/array_map_variation1.phpt new file mode 100644 index 0000000..cd09be7 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation1.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_map() function : usage variations - string keys +--FILE-- +<?php + +/* Prototype : array array_map(mixed callback, array input1 [, array input2 ,...]) + * Description: Applies the callback to the elements in given arrays. + * Source code: ext/standard/array.c +*/ + + + +echo "*** Testing array_map() : string keys ***\n"; + +$arr = array("stringkey" => "value"); +function cb1 ($a) {return array ($a);}; +function cb2 ($a,$b) {return array ($a,$b);}; +var_dump( array_map("cb1", $arr)); +var_dump( array_map("cb2", $arr,$arr)); +var_dump( array_map(null, $arr)); +var_dump( array_map(null, $arr, $arr)); +echo "Done"; +?> + +--EXPECT-- +*** Testing array_map() : string keys *** +array(1) { + ["stringkey"]=> + array(1) { + [0]=> + string(5) "value" + } +} +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "value" + [1]=> + string(5) "value" + } +} +array(1) { + ["stringkey"]=> + string(5) "value" +} +array(1) { + [0]=> + array(2) { + [0]=> + string(5) "value" + [1]=> + string(5) "value" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_map_variation10.phpt b/ext/standard/tests/array/array_map_variation10.phpt new file mode 100644 index 0000000..cc75436 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation10.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_map() function : usage variations - anonymous callback function +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing anoymous callback function with following variations + */ + +echo "*** Testing array_map() : anonymous callback function ***\n"; + +$array1 = array(1, 2, 3); +$array2 = array(3, 4, 5); + +echo "-- anonymous function with all parameters and body --\n"; +var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1, $array2)); + +echo "-- anonymous function with two parameters and passing one array --\n"; +var_dump( array_map( create_function('$a, $b', 'return array($a, $b);'), $array1)); + +echo "-- anonymous function with NULL parameter --\n"; +var_dump( array_map( create_function(NULL, 'return NULL;'), $array1)); + +echo "-- anonymous function with NULL body --\n"; +var_dump( array_map( create_function('$a', NULL), $array1)); + +echo "-- passing NULL as 'arr1' --\n"; +var_dump( array_map( create_function('$a', 'return array($a);'), NULL)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : anonymous callback function *** +-- anonymous function with all parameters and body -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(3) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +-- anonymous function with two parameters and passing one array -- + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + NULL + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + NULL + } +} +-- anonymous function with NULL parameter -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- anonymous function with NULL body -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- passing NULL as 'arr1' -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation11.phpt b/ext/standard/tests/array/array_map_variation11.phpt new file mode 100644 index 0000000..9cad366 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation11.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_map() function : usage variations - with recursive callback +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing subarrays and recursive callback function + */ + +echo "*** Testing array_map() : recursive callback function ***\n"; + +// callback function +function square_recur_single_array($var) { + if (is_array($var)) + return array_map('square_recur_single_array', $var); + return $var * $var; +} + +$array1 = array(1, array(2, 3, array(5)), array(4)); + +var_dump( array_map('square_recur_single_array', $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : recursive callback function *** +array(3) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(9) + [2]=> + array(1) { + [0]=> + int(25) + } + } + [2]=> + array(1) { + [0]=> + int(16) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation12.phpt b/ext/standard/tests/array/array_map_variation12.phpt new file mode 100644 index 0000000..5c6d9fb --- /dev/null +++ b/ext/standard/tests/array/array_map_variation12.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_map() function : usage variations - built-in function as callback +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing buit-in function as callback function + */ + +echo "*** Testing array_map() : built-in function ***\n"; + +$array1 = array(1, 2, 3); +$array2 = array(3, 4, 5); + +echo "-- with built-in function 'pow' and two parameters --\n"; +var_dump( array_map('pow', $array1, $array2)); + +echo "-- with built-in function 'pow' and one parameter --\n"; +var_dump( array_map('pow', $array1)); + +echo "-- with language construct --\n"; +var_dump( array_map('echo', $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : built-in function *** +-- with built-in function 'pow' and two parameters -- +array(3) { + [0]=> + int(1) + [1]=> + int(16) + [2]=> + int(243) +} +-- with built-in function 'pow' and one parameter -- + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with language construct -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation13.phpt b/ext/standard/tests/array/array_map_variation13.phpt new file mode 100644 index 0000000..94babdf --- /dev/null +++ b/ext/standard/tests/array/array_map_variation13.phpt @@ -0,0 +1,107 @@ +--TEST-- +Test array_map() function : usage variations - callback function with different return types +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing different callback function returning: + * int, string, bool, null values + */ + +echo "*** Testing array_map() : callback with diff return value ***\n"; + +$array1 = array(1, 2, 3); +$array2 = array(3, 4, 5); + +echo "-- with integer return value --\n"; +function callback_int($a, $b) +{ + return $a + $b; +} +var_dump( array_map('callback_int', $array1, $array2)); + +echo "-- with string return value --\n"; +function callback_string($a, $b) +{ + return "$a"."$b"; +} +var_dump( array_map('callback_string', $array1, $array2)); + +echo "-- with bool return value --\n"; +function callback_bool($a, $b) +{ + return TRUE; +} +var_dump( array_map('callback_bool', $array1, $array2)); + +echo "-- with null return value --\n"; +function callback_null($array1) +{ + return NULL; +} +var_dump( array_map('callback_null', $array1)); + +echo "-- with no return value --\n"; +function callback_without_ret($arr1) +{ + echo "callback_without_ret called\n"; +} +var_dump( array_map('callback_without_ret', $array1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : callback with diff return value *** +-- with integer return value -- +array(3) { + [0]=> + int(4) + [1]=> + int(6) + [2]=> + int(8) +} +-- with string return value -- +array(3) { + [0]=> + string(2) "13" + [1]=> + string(2) "24" + [2]=> + string(2) "35" +} +-- with bool return value -- +array(3) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(true) +} +-- with null return value -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with no return value -- +callback_without_ret called +callback_without_ret called +callback_without_ret called +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +Done diff --git a/ext/standard/tests/array/array_map_variation14.phpt b/ext/standard/tests/array/array_map_variation14.phpt new file mode 100644 index 0000000..771d3f9 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation14.phpt @@ -0,0 +1,125 @@ +--TEST-- +Test array_map() function : usage variations - null value for 'callback' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing null values for $callback argument and testing whether shortest + * array will be extended with empty elements + */ + +echo "*** Testing array_map() : null value for 'callback' argument ***\n"; + +// arrays to be passed as arguments +$arr1 = array(1, 2); +$arr2 = array("one", "two"); +$arr3 = array(1.1, 2.2); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +/* calling array_map() with null callback */ + +echo "-- with null --\n"; +var_dump( array_map(null, $arr1, $arr2, $arr3) ); +var_dump( array_map(NULL, $arr1, $arr2, $arr3) ); + +echo "-- with unset variable --\n"; +var_dump( array_map(@$unset_var, $arr1, $arr2, $arr3) ); + +echo "-- with undefined variable --\n"; +var_dump( array_map(@$undefined_var, $arr1) ); + +echo "-- with empty string --\n"; +var_dump( array_map("", $arr1, $arr2) ); + +echo "-- with empty array --\n"; +var_dump( array_map(array(), $arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : null value for 'callback' argument *** +-- with null -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with unset variable -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with undefined variable -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- with empty string -- + +Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- with empty array -- + +Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation15.phpt b/ext/standard/tests/array/array_map_variation15.phpt new file mode 100644 index 0000000..b29af47 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation15.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_map() function : usage variations - non existent 'callback' function +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing non existent function for $callback argument + */ + +echo "*** Testing array_map() : non existent 'callback' function ***\n"; + +// arrays to be passed as arguments +$arr1 = array(1, 2); +$arr2 = array("one", "two"); +$arr3 = array(1.1, 2.2); + +var_dump( array_map('non_existent', $arr1, $arr2, $arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : non existent 'callback' function *** + +Warning: array_map() expects parameter 1 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation16.phpt b/ext/standard/tests/array/array_map_variation16.phpt new file mode 100644 index 0000000..c4987cb --- /dev/null +++ b/ext/standard/tests/array/array_map_variation16.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_map() function : usage variations - failing built-in functions & language constructs +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing non-permmited built-in functions and language constructs i.e. + * echo(), array(), empty(), eval(), exit(), isset(), list(), print() + */ + +echo "*** Testing array_map() : non-permmited built-in functions ***\n"; + +// array to be passed as arguments +$arr1 = array(1, 2); + +// built-in functions & language constructs +$callback_names = array( +/*1*/ 'echo', + 'array', + 'empty', +/*4*/ 'eval', + 'exit', + 'isset', + 'list', +/*8*/ 'print' +); +for($count = 0; $count < count($callback_names); $count++) +{ + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_map($callback_names[$count], $arr1) ); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : non-permmited built-in functions *** +-- Iteration 1 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'array' not found or invalid function name in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'empty' not found or invalid function name in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'eval' not found or invalid function name in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'isset' not found or invalid function name in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'list' not found or invalid function name in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_map() expects parameter 1 to be a valid callback, function 'print' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation17.phpt b/ext/standard/tests/array/array_map_variation17.phpt new file mode 100644 index 0000000..d9440bb --- /dev/null +++ b/ext/standard/tests/array/array_map_variation17.phpt @@ -0,0 +1,158 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'callback' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing different scalar/nonscalar values in place of $callback + */ + +echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n"; + +$arr1 = array(1, 2, 3); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$unexpected_callbacks = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // boolean data +/*10*/ true, + false, + TRUE, + FALSE, + + // empty data +/*14*/ "", + '', + + // array data +/*16*/ array(), + array(1, 2), + array(1, array(2)), + + // object data +/*19*/ new classA(), + + // resource variable +/*20*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_map +for($count = 0; $count < count($unexpected_callbacks); $count++) { + echo "\n-- Iteration ".($count + 1)." --"; + var_dump( array_map($unexpected_callbacks[$count], $arr1)); +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : unexpected values for 'callback' argument *** + +-- Iteration 1 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation18.phpt b/ext/standard/tests/array/array_map_variation18.phpt new file mode 100644 index 0000000..d0a23d7 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation18.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing non array values in place of $arr1 + */ + +echo "*** Testing array_map() : unexpected values for 'arr1' ***\n"; + +function callback($a) +{ + return $a; +} + +//get an unset array variable +$unset_var1 = array(1, 2); +unset ($unset_var1); + +// get an unset variable +$unset_var2 = 10; +unset ($unset_var2); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// different scalar/non-scalar values for array input +$unexpected_inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var1, + @$unset_var2, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $unexpected_inputs to check the behavior of array_map +for($count = 0; $count < count($unexpected_inputs); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_map('callback', $unexpected_inputs[$count])); +}; + +fclose($fp); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : unexpected values for 'arr1' *** +-- Iteration 1 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 2 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 3 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 4 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 5 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 6 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 7 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 8 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 9 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 10 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 11 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 12 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 13 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 14 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 15 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 16 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 17 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 18 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 19 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 20 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 21 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 22 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 23 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 24 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 25 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation19.phpt b/ext/standard/tests/array/array_map_variation19.phpt new file mode 100644 index 0000000..0e56428 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation19.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_map() function : usage variations - callback pass semantics +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() with a pass-by-value callback forced to behave as a pass-by-reference function. + */ + +$arr1 = array('original.0', 'original.1'); +$arr2 = array('original.0', 'original.1'); + +function callback($a) { + $a = "changed"; +} + +array_map('callback', $arr1); +var_dump($arr1); + +$ref =& $arr2[0]; +array_map("callback", $arr2); +var_dump($arr2); +?> +--EXPECTF-- +array(2) { + [0]=> + string(10) "original.0" + [1]=> + string(10) "original.1" +} +array(2) { + [0]=> + &string(10) "original.0" + [1]=> + string(10) "original.1" +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_map_variation2.phpt b/ext/standard/tests/array/array_map_variation2.phpt new file mode 100644 index 0000000..16561ab --- /dev/null +++ b/ext/standard/tests/array/array_map_variation2.phpt @@ -0,0 +1,213 @@ +--TEST-- +Test array_map() function : usage variations - references +--FILE-- +<?php + +/* Prototype : array array_map(mixed callback, array input1 [, array input2 ,...]) + * Description: Applies the callback to the elements in given arrays. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_map() : references ***\n"; +$arr = array("k1" => "v1","k2"=>"v2"); +$arr[]=&$arr["k1"]; +$arr[]=&$arr; +function cb1 ($a) {var_dump ($a);return array ($a);}; +function cb2 (&$a) {var_dump ($a);return array (&$a);}; +var_dump( array_map("cb1", $arr)); +var_dump( array_map("cb2", $arr,$arr)); +var_dump( array_map(null, $arr)); +var_dump( array_map(null, $arr, $arr)); + +// break cycles +$arr[0] = null; +$arr[1] = null; + +echo "Done"; +?> + +--EXPECT-- +*** Testing array_map() : references *** +string(2) "v1" +string(2) "v2" +string(2) "v1" +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } +} +array(4) { + ["k1"]=> + array(1) { + [0]=> + string(2) "v1" + } + ["k2"]=> + array(1) { + [0]=> + string(2) "v2" + } + [0]=> + array(1) { + [0]=> + string(2) "v1" + } + [1]=> + array(1) { + [0]=> + array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } + } +} +string(2) "v1" +string(2) "v2" +string(2) "v1" +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } +} +array(4) { + [0]=> + array(1) { + [0]=> + &string(2) "v1" + } + [1]=> + array(1) { + [0]=> + string(2) "v2" + } + [2]=> + array(1) { + [0]=> + &string(2) "v1" + } + [3]=> + array(1) { + [0]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } +} +array(4) { + [0]=> + array(2) { + [0]=> + &string(2) "v1" + [1]=> + &string(2) "v1" + } + [1]=> + array(2) { + [0]=> + string(2) "v2" + [1]=> + string(2) "v2" + } + [2]=> + array(2) { + [0]=> + &string(2) "v1" + [1]=> + &string(2) "v1" + } + [3]=> + array(2) { + [0]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + [1]=> + &array(4) { + ["k1"]=> + &string(2) "v1" + ["k2"]=> + string(2) "v2" + [0]=> + &string(2) "v1" + [1]=> + *RECURSION* + } + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation3.phpt b/ext/standard/tests/array/array_map_variation3.phpt new file mode 100644 index 0000000..a071550 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation3.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_map() function : usage variations - different arrays for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing different arrays for $arr1 argument + */ + +echo "*** Testing array_map() : different arrays for 'arr1' argument ***\n"; + +function callback($a) +{ + return ($a); +} + +// different arrays +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array( array(2), array(1)), // sub arrays + array(false,true), // array with default keys and boolean values + array(), // empty array + array(NULL), // array with NULL + array("a","aaaa","b","bbbb","c","ccccc"), + + // associative arrays +/*8*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : different arrays for 'arr1' argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 5 -- +array(0) { +} +-- Iteration 6 -- +array(1) { + [0]=> + NULL +} +-- Iteration 7 -- +array(6) { + [0]=> + string(1) "a" + [1]=> + string(4) "aaaa" + [2]=> + string(1) "b" + [3]=> + string(4) "bbbb" + [4]=> + string(1) "c" + [5]=> + string(5) "ccccc" +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +array(4) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) + [3]=> + int(30) +} +-- Iteration 11 -- +array(3) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 17 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- Iteration 18 -- +array(3) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_map_variation4.phpt b/ext/standard/tests/array/array_map_variation4.phpt new file mode 100644 index 0000000..fcc4090 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation4.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different keys +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing associative array with different keys for $arr1 argument + */ + +echo "*** Testing array_map() : associative array with diff. keys for 'arr1' argument ***\n"; + +function callback($a) +{ + return ($a); +} + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing the array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys +/*2*/ array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"), + + // arrays with string keys + array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33), +/*8*/ array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable + array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed values +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. keys for 'arr1' argument *** + +Warning: Illegal offset type in %s on line %d%d + +Warning: Illegal offset type in %s on line %d%d + +Warning: Illegal offset type in %s on line %d%d + +Warning: Illegal offset type in %s on line %d%d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 6 -- +array(4) { + [1]=> + string(2) "f1" + [3]=> + string(2) "f2" + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +-- Iteration 7 -- +array(4) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 8 -- +array(4) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +array(1) { + [""]=> + string(5) "hello" +} +-- Iteration 11 -- +array(6) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [133]=> + string(3) "int" + [444]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_map_variation5.phpt b/ext/standard/tests/array/array_map_variation5.phpt new file mode 100644 index 0000000..55f1569 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation5.phpt @@ -0,0 +1,181 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different values +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing associative array with different values for $arr1 argument + */ + +echo "*** Testing array_map() : associative array with diff. values for 'arr1' argument ***\n"; + +function callback($a) +{ + return ($a); +} +//get an unset variable +$unset_var = array(1, 2); +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing the array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.3333), + + // arrays with string values + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), +/*8*/ array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. values for 'arr1' argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(33333333.3333) +} +-- Iteration 7 -- +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" + [3]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_map_variation6.phpt b/ext/standard/tests/array/array_map_variation6.phpt new file mode 100644 index 0000000..2409a57 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation6.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_map() function : usage variations - array having subarrays +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having different subarrays + */ + +echo "*** Testing array_map() : array having subarrays ***\n"; + +function callback($a) +{ + return $a; +} + +// different subarrays +$arr1 = array( + array(), + array(1, 2), + array('a', 'b'), + array(1, 2, 'a', 'b'), + array(1 => 'a', 'b' => 2) +); + +var_dump( array_map('callback', $arr1)); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array having subarrays *** +array(5) { + [0]=> + array(0) { + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [3]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(1) "a" + [3]=> + string(1) "b" + } + [4]=> + array(2) { + [1]=> + string(1) "a" + ["b"]=> + int(2) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation7.phpt b/ext/standard/tests/array/array_map_variation7.phpt new file mode 100644 index 0000000..8f88a0f --- /dev/null +++ b/ext/standard/tests/array/array_map_variation7.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test array_map() function : usage variations - arrays of different size +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having different size + * 1) first array as empty array + * 2) second array as empty array + * 3) second array shorter than first array + * 4) first array shorter than second array + * 5) one more array than callback function arguments + */ + +echo "*** Testing array_map() : arrays with diff. size ***\n"; + +function callback($a, $b) +{ + return array($a => $b); +} + +// calling array_map with different arrays +var_dump( array_map('callback', array(1, 2, 3), array()) ); +var_dump( array_map('callback', array(), array('a', 'b', 'c')) ); +var_dump( array_map('callback', array(1, 2, 3), array('a', 'b')) ); +var_dump( array_map('callback', array(012, 0x2F, 0X1A), array(2.3, 12.4e2)) ); +var_dump( array_map('callback', array(), array(1, 2, 3), array('a', 'b')) ); // passing more no. of arrays than callback function argument + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : arrays with diff. size *** +array(3) { + [0]=> + array(1) { + [1]=> + NULL + } + [1]=> + array(1) { + [2]=> + NULL + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [""]=> + string(1) "a" + } + [1]=> + array(1) { + [""]=> + string(1) "b" + } + [2]=> + array(1) { + [""]=> + string(1) "c" + } +} +array(3) { + [0]=> + array(1) { + [1]=> + string(1) "a" + } + [1]=> + array(1) { + [2]=> + string(1) "b" + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [10]=> + float(2.3) + } + [1]=> + array(1) { + [47]=> + float(1240) + } + [2]=> + array(1) { + [26]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [""]=> + int(1) + } + [1]=> + array(1) { + [""]=> + int(2) + } + [2]=> + array(1) { + [""]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation8.phpt b/ext/standard/tests/array/array_map_variation8.phpt new file mode 100644 index 0000000..5672e6c --- /dev/null +++ b/ext/standard/tests/array/array_map_variation8.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test array_map() function : usage variations - array with references +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having reference values for $arr1 argument + */ + +echo "*** Testing array_map() : array with references for 'arr1' argument ***\n"; + +function callback1($a) +{ + return ($a); +} + +function callback_cat($a, $b) +{ + return ($a . $b); +} + +// reference variables +$value1 = 10; +$value2 = "hello"; +$value3 = 0; +$value4 = &$value2; + +// array containing reference variables +$arr1 = array( + 0 => 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + $value4 => &$value2 +); +echo "-- with one array --\n"; +var_dump( array_map('callback1', $arr1) ); + +echo "-- with two arrays --\n"; +var_dump( array_map('callback_cat', $arr1, $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array with references for 'arr1' argument *** +-- with one array -- +array(6) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + int(0) + ["hello"]=> + string(5) "hello" +} +-- with two arrays -- +array(6) { + [0]=> + string(2) "00" + [1]=> + string(10) "hellohello" + [2]=> + string(10) "hellohello" + [3]=> + string(10) "hellohello" + [4]=> + string(2) "00" + [5]=> + string(10) "hellohello" +} +Done diff --git a/ext/standard/tests/array/array_map_variation9.phpt b/ext/standard/tests/array/array_map_variation9.phpt new file mode 100644 index 0000000..f029bec --- /dev/null +++ b/ext/standard/tests/array/array_map_variation9.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test array_map() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) + * Description: Applies the callback to the elements of the given arrays + * Source code: ext/standard/array.c + */ + +/* + * Test array_map() by passing array having binary values for $arr1 argument + */ + +echo "*** Testing array_map() : array with binary data for 'arr1' argument ***\n"; + +function callback1($a) +{ + return ($a); +} +function callback2($a, $b) +{ + return array($a => $b); +} + +// array with binary data +$arr1 = array(b"hello", b"world", "1", b"22.22"); + +echo "-- checking binary safe array with one parameter callback function --\n"; +var_dump( array_map('callback1', $arr1) ); + +echo "-- checking binary safe array with two parameter callback function --\n"; +var_dump( array_map(b"callback2", $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array with binary data for 'arr1' argument *** +-- checking binary safe array with one parameter callback function -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "1" + [3]=> + string(5) "22.22" +} +-- checking binary safe array with two parameter callback function -- + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d +array(4) { + [0]=> + array(1) { + ["hello"]=> + NULL + } + [1]=> + array(1) { + ["world"]=> + NULL + } + [2]=> + array(1) { + [1]=> + NULL + } + [3]=> + array(1) { + ["22.22"]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/array_merge.phpt b/ext/standard/tests/array/array_merge.phpt new file mode 100644 index 0000000..b718386 --- /dev/null +++ b/ext/standard/tests/array/array_merge.phpt @@ -0,0 +1,762 @@ +--TEST-- +Test array_merge() function +--INI-- +precision=14 +--FILE-- +<?php +/* Prototype: array array_merge(array $array1 [, array $array2 [, array $...]]); + Description: Merge one or more arrays +*/ + +echo "\n*** Testing array_merge() basic functionality ***"; +$begin_array = array( + array(), + array( 1 => "string"), + array( "" => "string"), + array( -2.44444 => 12), + array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), + array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL,1 => -2.344), + array( NULL, 1.23 => "Hi", "string" => "hello", + array("" => "World", "-2.34" => "a", "0" => "b")) +); + +$end_array = array( + array(), + array( 1 => "string"), + array( "" => "string"), + array( -2.44444 => 12), + array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), + array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, 1=> -2.344), + array( NULL, 1.23 => "Hi", "string" => "hello", + array("" => "World", "-2.34" => "a", "0" => "b")) +); + +/* loop through to merge two arrays */ +$count_outer = 0; +foreach($begin_array as $first) { + echo "\n\n--- Iteration $count_outer ---"; + $count_inner = 0; + foreach($end_array as $second) { + echo "\n-- Inner iteration $count_inner of Iteration $count_outer --\n"; + $result = array_merge($first, $second); + print_r($result); + $count_inner++; + } + $count_outer++; +} + + +echo "\n*** Testing array_merge() with three or more arrays ***\n"; +var_dump( array_merge( $end_array[0], + $end_array[5], + $end_array[4], + $end_array[6] + ) + ); + +var_dump( array_merge( $end_array[0], + $end_array[5], + array("array on fly"), + array("nullarray" => array()) + ) + ); + + +echo "\n*** Testing single array argument ***\n"; +/* Empty array */ +var_dump(array_merge(array())); + +/* associative array with string keys, which will not be re-indexed */ +var_dump(array_merge($begin_array[4])); + +/* associative array with numeric keys, which will be re-indexed */ +var_dump(array_merge($begin_array[5])); + +/* associative array with mixed keys and sub-array as element */ +var_dump(array_merge($begin_array[6])); + +echo "\n*** Testing array_merge() with typecasting non-array to array ***\n"; +var_dump(array_merge($begin_array[4], (array)"type1", (array)10, (array)12.34)); + +echo "\n*** Testing error conditions ***"; +/* Invalid argumens */ +var_dump(array_merge()); +var_dump(array_merge(100, 200)); +var_dump(array_merge($begin_array[0], $begin_array[1], 100)); +var_dump(array_merge($begin_array[0], $begin_array[1], $arr4)); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_merge() basic functionality *** + +--- Iteration 0 --- +-- Inner iteration 0 of Iteration 0 -- +Array +( +) + +-- Inner iteration 1 of Iteration 0 -- +Array +( + [0] => string +) + +-- Inner iteration 2 of Iteration 0 -- +Array +( + [] => string +) + +-- Inner iteration 3 of Iteration 0 -- +Array +( + [0] => 12 +) + +-- Inner iteration 4 of Iteration 0 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 0 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 +) + +-- Inner iteration 6 of Iteration 0 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + + +--- Iteration 1 --- +-- Inner iteration 0 of Iteration 1 -- +Array +( + [0] => string +) + +-- Inner iteration 1 of Iteration 1 -- +Array +( + [0] => string + [1] => string +) + +-- Inner iteration 2 of Iteration 1 -- +Array +( + [0] => string + [] => string +) + +-- Inner iteration 3 of Iteration 1 -- +Array +( + [0] => string + [1] => 12 +) + +-- Inner iteration 4 of Iteration 1 -- +Array +( + [0] => string + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 1 -- +Array +( + [0] => string + [1] => 1 + [2] => string + [3] => + [4] => -2.344 +) + +-- Inner iteration 6 of Iteration 1 -- +Array +( + [0] => string + [1] => + [2] => Hi + [string] => hello + [3] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + + +--- Iteration 2 --- +-- Inner iteration 0 of Iteration 2 -- +Array +( + [] => string +) + +-- Inner iteration 1 of Iteration 2 -- +Array +( + [] => string + [0] => string +) + +-- Inner iteration 2 of Iteration 2 -- +Array +( + [] => string +) + +-- Inner iteration 3 of Iteration 2 -- +Array +( + [] => string + [0] => 12 +) + +-- Inner iteration 4 of Iteration 2 -- +Array +( + [] => string + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 2 -- +Array +( + [] => string + [0] => 1 + [1] => string + [2] => + [3] => -2.344 +) + +-- Inner iteration 6 of Iteration 2 -- +Array +( + [] => string + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + + +--- Iteration 3 --- +-- Inner iteration 0 of Iteration 3 -- +Array +( + [0] => 12 +) + +-- Inner iteration 1 of Iteration 3 -- +Array +( + [0] => 12 + [1] => string +) + +-- Inner iteration 2 of Iteration 3 -- +Array +( + [0] => 12 + [] => string +) + +-- Inner iteration 3 of Iteration 3 -- +Array +( + [0] => 12 + [1] => 12 +) + +-- Inner iteration 4 of Iteration 3 -- +Array +( + [0] => 12 + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 3 -- +Array +( + [0] => 12 + [1] => 1 + [2] => string + [3] => + [4] => -2.344 +) + +-- Inner iteration 6 of Iteration 3 -- +Array +( + [0] => 12 + [1] => + [2] => Hi + [string] => hello + [3] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + + +--- Iteration 4 --- +-- Inner iteration 0 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 1 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 + [0] => string +) + +-- Inner iteration 2 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 + [] => string +) + +-- Inner iteration 3 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 + [0] => 12 +) + +-- Inner iteration 4 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 + [0] => 1 + [1] => string + [2] => + [3] => -2.344 +) + +-- Inner iteration 6 of Iteration 4 -- +Array +( + [a] => 1 + [b] => string + [c] => + [d] => -2.344 + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + + +--- Iteration 5 --- +-- Inner iteration 0 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 +) + +-- Inner iteration 1 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 + [4] => string +) + +-- Inner iteration 2 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 + [] => string +) + +-- Inner iteration 3 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 + [4] => 12 +) + +-- Inner iteration 4 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 + [4] => 1 + [5] => string + [6] => + [7] => -2.344 +) + +-- Inner iteration 6 of Iteration 5 -- +Array +( + [0] => 1 + [1] => string + [2] => + [3] => -2.344 + [4] => + [5] => Hi + [string] => hello + [6] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + + +--- Iteration 6 --- +-- Inner iteration 0 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + +-- Inner iteration 1 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + + [3] => string +) + +-- Inner iteration 2 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + + [] => string +) + +-- Inner iteration 3 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + + [3] => 12 +) + +-- Inner iteration 4 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + + [a] => 1 + [b] => string + [c] => + [d] => -2.344 +) + +-- Inner iteration 5 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + + [3] => 1 + [4] => string + [5] => + [6] => -2.344 +) + +-- Inner iteration 6 of Iteration 6 -- +Array +( + [0] => + [1] => Hi + [string] => hello + [2] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + + [3] => + [4] => Hi + [5] => Array + ( + [] => World + [-2.34] => a + [0] => b + ) + +) + +*** Testing array_merge() with three or more arrays *** +array(12) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [4]=> + NULL + [5]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [6]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} +array(6) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) + [4]=> + string(12) "array on fly" + ["nullarray"]=> + array(0) { + } +} + +*** Testing single array argument *** +array(0) { +} +array(4) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) +} +array(4) { + [0]=> + int(1) + [1]=> + string(6) "string" + [2]=> + NULL + [3]=> + float(-2.344) +} +array(4) { + [0]=> + NULL + [1]=> + string(2) "Hi" + ["string"]=> + string(5) "hello" + [2]=> + array(3) { + [""]=> + string(5) "World" + ["-2.34"]=> + string(1) "a" + [0]=> + string(1) "b" + } +} + +*** Testing array_merge() with typecasting non-array to array *** +array(7) { + ["a"]=> + int(1) + ["b"]=> + string(6) "string" + ["c"]=> + NULL + ["d"]=> + float(-2.344) + [0]=> + string(5) "type1" + [1]=> + int(10) + [2]=> + float(12.34) +} + +*** Testing error conditions *** +Warning: array_merge() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_merge(): Argument #3 is not an array in %s on line %d +NULL + +Notice: Undefined variable: arr4 in %s on line %d + +Warning: array_merge(): Argument #3 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_basic.phpt b/ext/standard/tests/array/array_merge_basic.phpt new file mode 100644 index 0000000..c4dc696 --- /dev/null +++ b/ext/standard/tests/array/array_merge_basic.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_merge() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_merge() + */ + +echo "*** Testing array_merge() : basic functionality ***\n"; + +//indexed array +$array1 = array ('zero', 'one', 'two'); +//associative array +$array2 = array ('a' => 1, 'b' => 2, 'c' => 3); + +var_dump(array_merge($array1, $array2)); + +var_dump(array_merge($array2, $array1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : basic functionality *** +array(6) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) +} +array(6) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_error.phpt b/ext/standard/tests/array/array_merge_error.phpt new file mode 100644 index 0000000..a017c27 --- /dev/null +++ b/ext/standard/tests/array/array_merge_error.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_merge() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_merge() to test behaviour + */ + +echo "*** Testing array_merge() : error conditions ***\n"; + +// Testing array_merge with zero arguments +echo "\n-- Testing array_merge() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +var_dump( array_merge() ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : error conditions *** + +-- Testing array_merge() function with less than expected no. of arguments -- + +Warning: array_merge() expects at least 1 parameter, 0 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_basic1.phpt b/ext/standard/tests/array/array_merge_recursive_basic1.phpt new file mode 100644 index 0000000..a86a851 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_basic1.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_merge_recursive() function : basic functionality - array with default keys +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_merge_recursive() : array with default keys ***\n"; + +// Initialise the arrays +$arr1 = array(1, array(1, 2)); +$arr2 = array(3, array("hello", 'world')); +$arr3 = array(array(6, 7), array("str1", 'str2')); + +// Calling array_merge_recursive() with default arguments +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +// Calling array_merge_recursive() with more arguments +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1,$arr2) ); +var_dump( array_merge_recursive($arr1,$arr2,$arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with default keys *** +-- With default argument -- +array(2) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(4) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } +} +array(6) { + [0]=> + int(1) + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } + [5]=> + array(2) { + [0]=> + string(4) "str1" + [1]=> + string(4) "str2" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_basic2.phpt b/ext/standard/tests/array/array_merge_recursive_basic2.phpt new file mode 100644 index 0000000..3f8c62e --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_basic2.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test array_merge_recursive() function : basic functionality - associative arrays +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_merge_recursive() : associative arrays ***\n"; + +// Initialise the arrays +$arr1 = array(1 => "one", 2 => array(1, 2)); +$arr2 = array(2 => 'three', "four" => array("hello", 'world')); +$arr3 = array(1 => array(6, 7), 'four' => array("str1", 'str2')); + +// Calling array_merge_recursive() with default arguments +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +// Calling array_merge_recursive() with more arguments +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1,$arr2) ); +var_dump( array_merge_recursive($arr1,$arr2,$arr3) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : associative arrays *** +-- With default argument -- +array(2) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(4) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + ["four"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } +} +array(5) { + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + ["four"]=> + array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(4) "str1" + [3]=> + string(4) "str2" + } + [3]=> + array(2) { + [0]=> + int(6) + [1]=> + int(7) + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_error.phpt b/ext/standard/tests/array/array_merge_recursive_error.phpt new file mode 100644 index 0000000..d7d7172 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +Test array_merge_recursive() function : error conditions +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_merge_recursive() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_merge_recursive() function with Zero arguments --\n"; +var_dump( array_merge_recursive() ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : error conditions *** + +-- Testing array_merge_recursive() function with Zero arguments -- + +Warning: array_merge_recursive() expects at least 1 parameter, 0 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation1.phpt b/ext/standard/tests/array/array_merge_recursive_variation1.phpt new file mode 100644 index 0000000..75e0c20 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation1.phpt @@ -0,0 +1,303 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - unexpected values for $arr1 argument +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Passing non array values to 'arr1' argument of array_merge_recursive() and see + * that the function outputs proper warning messages wherever expected. +*/ + +echo "*** Testing array_merge_recursive() : Passing non array values to \$arr1 argument ***\n"; + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +class A +{ +// public $var = 10; + public function __toString() { + return "object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$arrays = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // undefined data +/*21*/ @$undefined_var, + + // unset data +/*22*/ @$unset_var, + + // resource variable +/*23*/ $fp, + + // object data +/*24*/ new A() +); + +// initialise the second argument +$arr2 = array(1, array("hello", 'world')); + +// loop through each element of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "\n-- Iteration $iterator --"; + + // with default argument + echo "\n-- With default argument --"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : Passing non array values to $arr1 argument *** + +-- Iteration 1 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +-- With default argument -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +-- With more arguments -- +Warning: array_merge_recursive(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation10.phpt b/ext/standard/tests/array/array_merge_recursive_variation10.phpt new file mode 100644 index 0000000..42d315e --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation10.phpt @@ -0,0 +1,174 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - two dimensional arrays +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * two dimensional arrays for $arr1 argument. +*/ + +echo "*** Testing array_merge_recursive() : two dimensional array for \$arr1 argument ***\n"; + +// initialize the 2-d array +$arr1 = array( + array(1, 2, 3, 1), + "array" => array("hello", "world", "str1" => "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +// initialize the second argument +$arr2 = array(1, "hello", "array" => array("hello", 'world')); + +echo "-- Passing the entire 2-d array --\n"; +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "-- Passing the sub-array --\n"; +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1["array"]) ); +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1["array"], $arr2["array"]) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : two dimensional array for $arr1 argument *** +-- Passing the entire 2-d array -- +-- With default argument -- +array(4) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + ["array"]=> + array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + } + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + } + [2]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +-- With more arguments -- +array(6) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + ["array"]=> + array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + [2]=> + string(5) "hello" + [3]=> + string(5) "world" + } + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + } + [2]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } + [3]=> + int(1) + [4]=> + string(5) "hello" +} +-- Passing the sub-array -- +-- With default argument -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" + [2]=> + string(5) "hello" + [3]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation2.phpt b/ext/standard/tests/array/array_merge_recursive_variation2.phpt new file mode 100644 index 0000000..83f2374 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation2.phpt @@ -0,0 +1,199 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - unexpected values for $arr2 argument +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Passing non array values to 'arr2' argument of array_merge_recursive() and see + * that the function outputs proper warning messages wherever expected. +*/ + +echo "*** Testing array_merge_recursive() : Passing non array values to \$arr2 argument ***\n"; + +// initialise the first argument +$arr1 = array(1, array("hello", 'world')); + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +class A +{ +// public $var = 10; + public function __toString() { + return "object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$arrays = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // undefined data +/*21*/ @$undefined_var, + + // unset data +/*22*/ @$unset_var, + + // resource variable +/*23*/ $fp, + + // object data +/*24*/ new A() +); + +// loop through each element of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr2) { + echo "\n-- Iteration $iterator --"; + var_dump( array_merge_recursive($arr1, $arr2) ); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : Passing non array values to $arr2 argument *** + +-- Iteration 1 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_merge_recursive(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation3.phpt b/ext/standard/tests/array/array_merge_recursive_variation3.phpt new file mode 100644 index 0000000..722388a --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation3.phpt @@ -0,0 +1,761 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - different arrays for 'arr1' argument +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $arr1 argument and testing whether +* array_merge_recursive() behaves in an expected way. +*/ + +echo "*** Testing array_merge_recursive() : Passing different arrays to \$arr1 argument ***\n"; + +/* Different heredoc strings */ + +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $arr1 argument +$arrays = array ( +/*1*/ array(1, 2,), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false, true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array containing embedded arrays +/*15*/ array("str1", "array" => array("hello", 'world'), array(1, 2)) +); + +// initialise the second argument +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : Passing different arrays to $arr1 argument *** +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- With more arguments -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- With more arguments -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- With more arguments -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(0) { +} +-- With more arguments -- +array(4) { + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(1) { + [0]=> + NULL +} +-- With more arguments -- +array(5) { + [0]=> + NULL + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(1) "b" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- With more arguments -- +array(8) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(1) "b" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 7 -- +-- With default argument -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- With more arguments -- +array(8) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(3) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- With more arguments -- +array(7) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 9 -- +-- With default argument -- +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +-- With more arguments -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 10 -- +-- With default argument -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + int(1) +} +-- With more arguments -- +array(7) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 11 -- +-- With default argument -- +array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) +} +-- With more arguments -- +array(7) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 12 -- +-- With default argument -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- With more arguments -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 13 -- +-- With default argument -- +array(3) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" +} +-- With more arguments -- +array(7) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 14 -- +-- With default argument -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- With more arguments -- +array(7) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 15 -- +-- With default argument -- +array(4) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- With more arguments -- +array(8) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 16 -- +-- With default argument -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- With more arguments -- +array(7) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 17 -- +-- With default argument -- +array(6) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + NULL + [3]=> + NULL + [4]=> + bool(false) + [5]=> + bool(true) +} +-- With more arguments -- +array(10) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + NULL + [3]=> + NULL + [4]=> + bool(false) + [5]=> + bool(true) + [6]=> + string(3) "one" + [7]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 18 -- +-- With default argument -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- With more arguments -- +array(7) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 19 -- +-- With default argument -- +array(3) { + [0]=> + string(4) "str1" + ["array"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +-- With more arguments -- +array(6) { + [0]=> + string(4) "str1" + ["array"]=> + array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "a" + [3]=> + string(1) "b" + [4]=> + string(1) "c" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation4.phpt b/ext/standard/tests/array/array_merge_recursive_variation4.phpt new file mode 100644 index 0000000..b497ace --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation4.phpt @@ -0,0 +1,424 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - associative array with different keys +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing different + * associative arrays having different keys to $arr1 argument. +*/ + +echo "*** Testing array_merge_recursive() : assoc. array with diff. keys to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different associative arrays to be passed to $arr1 argument +$arrays = array ( +/*1*/ // arrays with integer keys + array(0 => "0", 1 => array(1 => "one")), + array(1 => "1", 2 => array(1 => "one", 2 => "two", 3 => 1, 4 => "4")), + + // arrays with float keys +/*3*/ array(2.3333 => "float", 44.44 => array(1.1 => "float")), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => array(1.1 => "f1"), 3333333.333333 => "f4"), + + // arrays with string keys +/*5*/ array('\tHello' => array("hello", 'world'), '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => array("hello", 'world'), "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => array("heredoc", 'string'), "string"), + + // array with object, unset variable and resource variable +/*8*/ array(new classA() => 11, @$unset_var => array("unset"), $fp => 'resource', 11, "hello") +); + +// initialise the second array +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : assoc. array with diff. keys to $arr1 argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + string(1) "0" + [1]=> + array(1) { + [1]=> + string(3) "one" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(1) "0" + [1]=> + array(1) { + [1]=> + string(3) "one" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(2) { + [0]=> + string(1) "1" + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(1) + [4]=> + string(1) "4" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(1) "1" + [1]=> + array(4) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(1) + [4]=> + string(1) "4" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(2) { + [0]=> + string(5) "float" + [1]=> + array(1) { + [1]=> + string(5) "float" + } +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "float" + [1]=> + array(1) { + [1]=> + string(5) "float" + } + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(4) { + [0]=> + string(2) "f1" + [1]=> + string(2) "f2" + [2]=> + array(1) { + [1]=> + string(2) "f1" + } + [3]=> + string(2) "f4" +} +-- With more arguments -- +array(8) { + [0]=> + string(2) "f1" + [1]=> + string(2) "f2" + [2]=> + array(1) { + [1]=> + string(2) "f1" + } + [3]=> + string(2) "f4" + [4]=> + string(3) "one" + [5]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(3) { + ["\tHello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(111) +} +-- With more arguments -- +array(7) { + ["\tHello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(111) + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 6 -- +-- With default argument -- +array(3) { + [" Hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["world"]=> + float(2.2) + ["pen +"]=> + int(111) +} +-- With more arguments -- +array(7) { + [" Hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + ["world"]=> + float(2.2) + ["pen +"]=> + int(111) + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 7 -- +-- With default argument -- +array(3) { + [0]=> + string(5) "hello" + ["Hello world"]=> + array(2) { + [0]=> + string(7) "heredoc" + [1]=> + string(6) "string" + } + [1]=> + string(6) "string" +} +-- With more arguments -- +array(7) { + [0]=> + string(5) "hello" + ["Hello world"]=> + array(2) { + [0]=> + string(7) "heredoc" + [1]=> + string(6) "string" + } + [1]=> + string(6) "string" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(3) { + [""]=> + array(1) { + [0]=> + string(5) "unset" + } + [0]=> + int(11) + [1]=> + string(5) "hello" +} +-- With more arguments -- +array(7) { + [""]=> + array(1) { + [0]=> + string(5) "unset" + } + [0]=> + int(11) + [1]=> + string(5) "hello" + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation5.phpt b/ext/standard/tests/array/array_merge_recursive_variation5.phpt new file mode 100644 index 0000000..3b25122 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation5.phpt @@ -0,0 +1,404 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - associative array with different values +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing different + * associative arrays having different values to $arr1 argument. +*/ + +echo "*** Testing array_merge_recursive() : assoc. array with diff. values to \$arr1 argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different associative arrays to be passed to $arr1 argument +$arrays = array ( +// arrays with integer values +/*1*/ array('0' => 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("f1" => 2.3333, "f2" => 2.3333, "f3" => array(1.1, 2.22)), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => array(1.2, 'f4' => 1.2)), + + // arrays with string values +/*5*/ array(111 => "\tHello", "array" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', 'array' => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "string" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "string" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// initialise the second array +$arr2 = array( 1 => "one", 2, "string" => "hello", "array" => array("a", "b", "c")); + +// loop through each sub array of $arrays and check the behavior of array_merge_recursive() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + + // with default argument + echo "-- With default argument --\n"; + var_dump( array_merge_recursive($arr1) ); + + // with more arguments + echo "-- With more arguments --\n"; + var_dump( array_merge_recursive($arr1, $arr2) ); + + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : assoc. array with diff. values to $arr1 argument *** +-- Iteration 1 -- +-- With default argument -- +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} +-- With more arguments -- +array(6) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + string(3) "one" + [3]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 2 -- +-- With default argument -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(1) + [0]=> + int(1) +} +-- With more arguments -- +array(8) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(1) + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 3 -- +-- With default argument -- +array(3) { + ["f1"]=> + float(2.3333) + ["f2"]=> + float(2.3333) + ["f3"]=> + array(2) { + [0]=> + float(1.1) + [1]=> + float(2.22) + } +} +-- With more arguments -- +array(7) { + ["f1"]=> + float(2.3333) + ["f2"]=> + float(2.3333) + ["f3"]=> + array(2) { + [0]=> + float(1.1) + [1]=> + float(2.22) + } + [0]=> + string(3) "one" + [1]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 4 -- +-- With default argument -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [0]=> + float(4.8999992284) + ["f4"]=> + array(2) { + [0]=> + float(1.2) + ["f4"]=> + float(1.2) + } +} +-- With more arguments -- +array(8) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [0]=> + float(4.8999992284) + ["f4"]=> + array(2) { + [0]=> + float(1.2) + ["f4"]=> + float(1.2) + } + [1]=> + string(3) "one" + [2]=> + int(2) + ["string"]=> + string(5) "hello" + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 5 -- +-- With default argument -- +array(4) { + [0]=> + string(6) " Hello" + ["array"]=> + string(6) "col or" + [1]=> + string(7) "world" + [2]=> + string(6) " Hello" +} +-- With more arguments -- +array(7) { + [0]=> + string(6) " Hello" + ["array"]=> + array(4) { + [0]=> + string(6) "col or" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(1) "c" + } + [1]=> + string(7) "world" + [2]=> + string(6) " Hello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" +} +-- Iteration 6 -- +-- With default argument -- +array(4) { + [0]=> + string(7) "\tHello" + ["array"]=> + string(7) "col\tor" + [1]=> + string(9) "\v\fworld" + [2]=> + string(7) "\tHello" +} +-- With more arguments -- +array(7) { + [0]=> + string(7) "\tHello" + ["array"]=> + array(4) { + [0]=> + string(7) "col\tor" + [1]=> + string(1) "a" + [2]=> + string(1) "b" + [3]=> + string(1) "c" + } + [1]=> + string(9) "\v\fworld" + [2]=> + string(7) "\tHello" + [3]=> + string(3) "one" + [4]=> + int(2) + ["string"]=> + string(5) "hello" +} +-- Iteration 7 -- +-- With default argument -- +array(3) { + [0]=> + string(5) "hello" + ["string"]=> + string(11) "Hello world" + [1]=> + string(11) "Hello world" +} +-- With more arguments -- +array(6) { + [0]=> + string(5) "hello" + ["string"]=> + array(2) { + [0]=> + string(11) "Hello world" + [1]=> + string(5) "hello" + } + [1]=> + string(11) "Hello world" + [2]=> + string(3) "one" + [3]=> + int(2) + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +-- Iteration 8 -- +-- With default argument -- +array(5) { + [0]=> + object(classA)#%d (0) { + } + ["string"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) + [1]=> + object(classA)#%d (0) { + } + [2]=> + resource(%d) of type (stream) +} +-- With more arguments -- +array(8) { + [0]=> + object(classA)#%d (0) { + } + ["string"]=> + array(2) { + [0]=> + NULL + [1]=> + string(5) "hello" + } + ["resource"]=> + resource(%d) of type (stream) + [1]=> + object(classA)#%d (0) { + } + [2]=> + resource(%d) of type (stream) + [3]=> + string(3) "one" + [4]=> + int(2) + ["array"]=> + array(3) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation6.phpt b/ext/standard/tests/array/array_merge_recursive_variation6.phpt new file mode 100644 index 0000000..8e460ba --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation6.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - array with duplicate keys +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * array having duplicate keys. +*/ + +echo "*** Testing array_merge_recursive() : array with duplicate keys for \$arr1 argument ***\n"; + +/* initialize the array having duplicate keys */ +// array with numeric keys +$arr1_numeric_key = array( 1 => "one", 2 => "two", 2 => array(1, 2), 3 => "three", 1 => array("duplicate", 'strings')); +// array with string keys +$arr1_string_key = array("str1" => "hello", "str2" => 111, "str1" => "world", "str2" => 111.111); + +// initialize the second argument +$arr2 = array("one", "str1" => "two", array("one", "two")); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1_numeric_key) ); +var_dump( array_merge_recursive($arr1_string_key) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1_numeric_key, $arr2) ); +var_dump( array_merge_recursive($arr1_string_key, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with duplicate keys for $arr1 argument *** +-- With default argument -- +array(3) { + [0]=> + array(2) { + [0]=> + string(9) "duplicate" + [1]=> + string(7) "strings" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" +} +array(2) { + ["str1"]=> + string(5) "world" + ["str2"]=> + float(111.111) +} +-- With more arguments -- +array(6) { + [0]=> + array(2) { + [0]=> + string(9) "duplicate" + [1]=> + string(7) "strings" + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + string(5) "three" + [3]=> + string(3) "one" + ["str1"]=> + string(3) "two" + [4]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} +array(4) { + ["str1"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(3) "two" + } + ["str2"]=> + float(111.111) + [0]=> + string(3) "one" + [1]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation7.phpt b/ext/standard/tests/array/array_merge_recursive_variation7.phpt new file mode 100644 index 0000000..b244e7d --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation7.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - array with reference variables +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * array having reference variables. +*/ + +echo "*** Testing array_merge_recursive() : array with reference variables for \$arr1 argument ***\n"; + +$value1 = 10; +$value2 = "hello"; +$value3 = 0; +$value4 = &$value2; + +// input array containing elements as reference variables +$arr1 = array( + 0 => 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + $value4 => &$value2 +); + +// initialize the second argument +$arr2 = array($value4 => "hello", &$value2); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with reference variables for $arr1 argument *** +-- With default argument -- +array(6) { + [0]=> + int(0) + [1]=> + &string(5) "hello" + [2]=> + &string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + &int(0) + ["hello"]=> + &string(5) "hello" +} +-- With more arguments -- +array(7) { + [0]=> + int(0) + [1]=> + &string(5) "hello" + [2]=> + &string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + &int(0) + ["hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + } + [5]=> + &string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation8.phpt b/ext/standard/tests/array/array_merge_recursive_variation8.phpt new file mode 100644 index 0000000..6ad2f69 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation8.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing an array having binary values. +*/ + +echo "*** Testing array_merge_recursive() : array with binary data for \$arr1 argument ***\n"; + +// array with binary values +$arr1 = array(b"1", b"hello" => "hello", b"world", "str1" => b"hello", "str2" => "world"); + +// initialize the second argument +$arr2 = array(b"str1" => b"binary", b"hello" => "binary", b"str2" => b"binary"); + +echo "-- With default argument --\n"; +var_dump( array_merge_recursive($arr1) ); + +echo "-- With more arguments --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : array with binary data for $arr1 argument *** +-- With default argument -- +array(5) { + [0]=> + string(1) "1" + ["hello"]=> + string(5) "hello" + [1]=> + string(5) "world" + ["str1"]=> + string(5) "hello" + ["str2"]=> + string(5) "world" +} +-- With more arguments -- +array(5) { + [0]=> + string(1) "1" + ["hello"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(6) "binary" + } + [1]=> + string(5) "world" + ["str1"]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(6) "binary" + } + ["str2"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(6) "binary" + } +} +Done diff --git a/ext/standard/tests/array/array_merge_recursive_variation9.phpt b/ext/standard/tests/array/array_merge_recursive_variation9.phpt new file mode 100644 index 0000000..d51d2f8 --- /dev/null +++ b/ext/standard/tests/array/array_merge_recursive_variation9.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test array_merge_recursive() function : usage variations - common key and value(Bug#43559) +--FILE-- +<?php +/* Prototype : array array_merge_recursive(array $arr1[, array $...]) + * Description: Recursively merges elements from passed arrays into one array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_merge_recursive() by passing + * arrays having common key and value. +*/ + +echo "*** Testing array_merge_recursive() : arrays with common key and value ***\n"; + +/* initialize the array having duplicate values */ + +// integer values +$arr1 = array("a" => 1, "b" => 2); +$arr2 = array("b" => 2, "c" => 4); +echo "-- Integer values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// float values +$arr1 = array("a" => 1.1, "b" => 2.2); +$arr2 = array("b" => 2.2, "c" => 3.3); +echo "-- Float values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// string values +$arr1 = array("a" => "hello", "b" => "world"); +$arr2 = array("b" => "world", "c" => "string"); +echo "-- String values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// boolean values +$arr1 = array("a" => true, "b" => false); +$arr2 = array("b" => false); +echo "-- Boolean values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +// null values +$arr1 = array( "a" => NULL); +$arr2 = array( "a" => NULL); +echo "-- Null values --\n"; +var_dump( array_merge_recursive($arr1, $arr2) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge_recursive() : arrays with common key and value *** +-- Integer values -- +array(3) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + [0]=> + int(2) + [1]=> + int(2) + } + ["c"]=> + int(4) +} +-- Float values -- +array(3) { + ["a"]=> + float(1.1) + ["b"]=> + array(2) { + [0]=> + float(2.2) + [1]=> + float(2.2) + } + ["c"]=> + float(3.3) +} +-- String values -- +array(3) { + ["a"]=> + string(5) "hello" + ["b"]=> + array(2) { + [0]=> + string(5) "world" + [1]=> + string(5) "world" + } + ["c"]=> + string(6) "string" +} +-- Boolean values -- +array(2) { + ["a"]=> + bool(true) + ["b"]=> + array(2) { + [0]=> + bool(false) + [1]=> + bool(false) + } +} +-- Null values -- +array(1) { + ["a"]=> + array(2) { + [0]=> + NULL + [1]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/array_merge_variation1.phpt b/ext/standard/tests/array/array_merge_variation1.phpt new file mode 100644 index 0000000..1ce71de --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation1.phpt @@ -0,0 +1,231 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types to $arr1 arg +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $arr1 argument to test behaviour + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr2 = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr1 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_merge() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_merge($input, $arr2) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_merge(): Argument #1 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_variation10.phpt b/ext/standard/tests/array/array_merge_variation10.phpt new file mode 100644 index 0000000..7f08a4b --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation10.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_merge() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling array_merge(). + * This test is also passing more than two arguments to array_merge(). + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$arr1 = array ('zero', 'one', 'two'); +$arr2 = array ('zero', 'un', 'deux'); +$arr3 = array ('null', 'eins', 'zwei'); + +echo "\n-- Call array_merge() --\n"; +var_dump($result = array_merge($arr1, $arr2, $arr3)); + +echo "\n-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo "\$arr1: "; +echo key($arr1) . " => " . current ($arr1) . "\n"; +echo "\$arr2: "; +echo key($arr2) . " => " . current ($arr2) . "\n"; +echo "\$arr3: "; +echo key($arr3) . " => " . current ($arr3) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Call array_merge() -- +array(9) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(4) "zero" + [4]=> + string(2) "un" + [5]=> + string(4) "deux" + [6]=> + string(4) "null" + [7]=> + string(4) "eins" + [8]=> + string(4) "zwei" +} + +-- Position of Internal Pointer in Result: -- +0 => zero + +-- Position of Internal Pointer in Original Array: -- +$arr1: 0 => zero +$arr2: 0 => zero +$arr3: 0 => null +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation2.phpt b/ext/standard/tests/array/array_merge_variation2.phpt new file mode 100644 index 0000000..4ebbeb9 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation2.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test array_merge() function : usage variations - Pass different data types as $arr2 arg +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $arr2 argument to array_merge() to test behaviour + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr1 = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr2 argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_merge() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_merge($arr1, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 18 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 19 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_merge(): Argument #2 is not an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_merge_variation3.phpt b/ext/standard/tests/array/array_merge_variation3.phpt new file mode 100644 index 0000000..717968a --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation3.phpt @@ -0,0 +1,379 @@ +--TEST-- +Test array_merge() function : usage variations - arrays of diff. data types +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types to test how array_merge adds them + * onto an existing array + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of array_merge +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_merge($input, $arr) ); + var_dump( array_merge($arr, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1: int data -- +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) + [4]=> + int(1) + [5]=> + int(2) +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(1) + [4]=> + int(12345) + [5]=> + int(-2345) +} + +-- Iteration 2: float data -- +array(7) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) + [5]=> + int(1) + [6]=> + int(2) +} +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(-10.5) + [4]=> + float(123456789000) + [5]=> + float(1.23456789E-9) + [6]=> + float(0.5) +} + +-- Iteration 3: null data -- +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} + +-- Iteration 4: bool data -- +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + int(1) + [5]=> + int(2) +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(false) + [4]=> + bool(true) + [5]=> + bool(false) +} + +-- Iteration 5: empty string data -- +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Iteration 7: string data -- +array(5) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" + [3]=> + int(1) + [4]=> + int(2) +} +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" + [4]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +array(3) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9: undefined data -- +array(3) { + [0]=> + NULL + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL +} + +-- Iteration 10: unset data -- +array(3) { + [0]=> + NULL + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL +} + +-- Iteration 11: resource data -- +array(3) { + [0]=> + resource(%d) of type (stream) + [1]=> + int(1) + [2]=> + int(2) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation4.phpt b/ext/standard/tests/array/array_merge_variation4.phpt new file mode 100644 index 0000000..e4eb257 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation4.phpt @@ -0,0 +1,368 @@ +--TEST-- +Test array_merge() function : usage variations - Diff. data types as array keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass an array with different data types as keys to test how array_merge + * adds it onto an existing array + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$arr = array ('one' => 1, 'two' => 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays with keys as different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_merge +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_merge($input, $arr) ); + var_dump( array_merge($arr, $input) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Iteration 1: int data -- +array(6) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2: float data -- +array(5) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3: extreme floats data -- +array(4) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4: null uppercase data -- +array(3) { + [""]=> + string(6) "null 1" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "null 1" +} + +-- Iteration 5: null lowercase data -- +array(3) { + [""]=> + string(6) "null 2" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "null 2" +} + +-- Iteration 6: bool lowercase data -- +array(4) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7: bool uppercase data -- +array(4) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8: empty double quotes data -- +array(3) { + [""]=> + string(6) "emptyd" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "emptyd" +} + +-- Iteration 9: empty single quotes data -- +array(3) { + [""]=> + string(6) "emptys" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(6) "emptys" +} + +-- Iteration 10: string data -- +array(5) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11: undefined data -- +array(3) { + [""]=> + string(9) "undefined" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(9) "undefined" +} + +-- Iteration 12: unset data -- +array(3) { + [""]=> + string(5) "unset" + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation5.phpt b/ext/standard/tests/array/array_merge_variation5.phpt new file mode 100644 index 0000000..eca6078 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation5.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_merge() function : usage variations - numeric keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge() arrays with only numeric keys to test behaviour. + * $arr2 contains a duplicate element to $arr1. + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//numeric keys +$arr1 = array('zero', 'one', 'two', 'three'); +$arr2 = array(1 => 'one', 20 => 'twenty', 30 => 'thirty'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** +array(7) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(3) "one" + [5]=> + string(6) "twenty" + [6]=> + string(6) "thirty" +} +array(7) { + [0]=> + string(3) "one" + [1]=> + string(6) "twenty" + [2]=> + string(6) "thirty" + [3]=> + string(4) "zero" + [4]=> + string(3) "one" + [5]=> + string(3) "two" + [6]=> + string(5) "three" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation6.phpt b/ext/standard/tests/array/array_merge_variation6.phpt new file mode 100644 index 0000000..13b346e --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_merge() function : usage variations - string keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge arrays with string keys to test behaviour. + * $arr2 has a duplicate key to $arr1 + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//string keys +$arr1 = array('zero' => 'zero', 'one' => 'un', 'two' => 'deux'); +$arr2 = array('zero' => 'zero', 'un' => 'eins', 'deux' => 'zwei'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** +array(5) { + ["zero"]=> + string(4) "zero" + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + ["un"]=> + string(4) "eins" + ["deux"]=> + string(4) "zwei" +} +array(5) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(4) "eins" + ["deux"]=> + string(4) "zwei" + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation7.phpt b/ext/standard/tests/array/array_merge_variation7.phpt new file mode 100644 index 0000000..00943f3 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation7.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_merge() function : usage variations - Mixed keys +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_merge() arrays with mixed keys to test how it attaches them to + * existing arrays + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +//mixed keys +$arr1 = array('zero', 20 => 'twenty', 'thirty' => 30, true => 'bool'); +$arr2 = array(0, 1, 2, null => 'null', 1.234E-10 => 'float'); + +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** +array(8) { + [0]=> + string(4) "zero" + [1]=> + string(6) "twenty" + ["thirty"]=> + int(30) + [2]=> + string(4) "bool" + [3]=> + string(5) "float" + [4]=> + int(1) + [5]=> + int(2) + [""]=> + string(4) "null" +} +array(8) { + [0]=> + string(5) "float" + [1]=> + int(1) + [2]=> + int(2) + [""]=> + string(4) "null" + [3]=> + string(4) "zero" + [4]=> + string(6) "twenty" + ["thirty"]=> + int(30) + [5]=> + string(4) "bool" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation8.phpt b/ext/standard/tests/array/array_merge_variation8.phpt new file mode 100644 index 0000000..a4cdea7 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation8.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_merge() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* + * Test array_merge() with multi-dimensional arrays + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$arr1 = array('zero', 'one', 'two', array(0)); +$arr2 = array(1, 2, 3); + +echo "\n-- Merge a two-dimensional and a one-dimensional array --\n"; +var_dump(array_merge($arr1, $arr2)); + +echo "\n-- Merge an array and a sub-array --\n"; +var_dump(array_merge($arr1[3], $arr2)); +var_dump(array_merge($arr2, $arr1[3])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Merge a two-dimensional and a one-dimensional array -- +array(7) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + array(1) { + [0]=> + int(0) + } + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) +} + +-- Merge an array and a sub-array -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(0) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_merge_variation9.phpt b/ext/standard/tests/array/array_merge_variation9.phpt new file mode 100644 index 0000000..69e0401 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_merge() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : array array_merge(array $arr1, array $arr2 [, array $...]) + * Description: Merges elements from passed arrays into one array + * Source code: ext/standard/array.c + */ + +/* Test array_merge() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array as the first argument and a reference to that array as the second. + */ + +echo "*** Testing array_merge() : usage variations ***\n"; + +$val1 = 'foo'; +$val2 = 'bar'; +$val3 = 'baz'; + +$arr1 = array(&$val1, &$val2, &$val3); +$arr2 = array('key1' => 'val1', 'key2' => 'val2', 'key3' => 'val3'); + +echo "\n-- Merge an array made up of referenced variables to an assoc. array --\n"; +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +$val2 = 'hello world'; + +echo "\n-- Change \$val2 --\n"; +var_dump(array_merge($arr1, $arr2)); +var_dump(array_merge($arr2, $arr1)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_merge() : usage variations *** + +-- Merge an array made up of referenced variables to an assoc. array -- +array(6) { + [0]=> + &string(3) "foo" + [1]=> + &string(3) "bar" + [2]=> + &string(3) "baz" + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +array(6) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" + [0]=> + &string(3) "foo" + [1]=> + &string(3) "bar" + [2]=> + &string(3) "baz" +} + +-- Change $val2 -- +array(6) { + [0]=> + &string(3) "foo" + [1]=> + &string(11) "hello world" + [2]=> + &string(3) "baz" + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +array(6) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" + [0]=> + &string(3) "foo" + [1]=> + &string(11) "hello world" + [2]=> + &string(3) "baz" +} +Done diff --git a/ext/standard/tests/array/array_multisort_basic1.phpt b/ext/standard/tests/array/array_multisort_basic1.phpt new file mode 100644 index 0000000..ab7db94 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_basic1.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_multisort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : basic functionality ***\n"; + +// Initialise all required variables +$ar1 = array("row1" => 2, "row2" => 1, "row3" => 1); +$ar2 = array("row1" => 2, "row2" => "aa", "row3" => "1"); + +echo "\n-- Testing array_multisort() function with all normal arguments --\n"; +var_dump( array_multisort($ar1, SORT_ASC, SORT_REGULAR, $ar2, SORT_DESC, SORT_STRING) ); +var_dump($ar1, $ar2); + +echo "\n-- Testing array_multisort() function with one argument --\n"; +var_dump( array_multisort($ar2) ); +var_dump($ar2); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : basic functionality *** + +-- Testing array_multisort() function with all normal arguments -- +bool(true) +array(3) { + ["row2"]=> + int(1) + ["row3"]=> + int(1) + ["row1"]=> + int(2) +} +array(3) { + ["row2"]=> + string(2) "aa" + ["row3"]=> + string(1) "1" + ["row1"]=> + int(2) +} + +-- Testing array_multisort() function with one argument -- +bool(true) +array(3) { + ["row3"]=> + string(1) "1" + ["row2"]=> + string(2) "aa" + ["row1"]=> + int(2) +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_multisort_basic2.phpt b/ext/standard/tests/array/array_multisort_basic2.phpt new file mode 100644 index 0000000..4a46072 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_basic2.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_multisort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : basic functionality - renumbering of numeric keys ***\n"; + +// Initialise all required variables +$ar1 = array( "strkey" => 2, 1, 9 => 1); +$ar2 = array( 2, "aa" , "1"); + +echo "\n-- Testing array_multisort() function with all normal arguments --\n"; +var_dump( array_multisort($ar1, SORT_ASC, SORT_REGULAR, $ar2, SORT_ASC, SORT_NUMERIC) ); +var_dump($ar1, $ar2); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : basic functionality - renumbering of numeric keys *** + +-- Testing array_multisort() function with all normal arguments -- +bool(true) +array(3) { + [0]=> + int(1) + [1]=> + int(1) + ["strkey"]=> + int(2) +} +array(3) { + [0]=> + string(2) "aa" + [1]=> + string(1) "1" + [2]=> + int(2) +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_multisort_case.phpt b/ext/standard/tests/array/array_multisort_case.phpt new file mode 100644 index 0000000..6be42ed --- /dev/null +++ b/ext/standard/tests/array/array_multisort_case.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_multisort() function : case-sensitive +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : case-sensitive\n"; + +$a = array( + 'Second', + 'First.1', + 'First.2', + 'First.3', + 'Twentieth', + 'Tenth', + 'Third', +); + +$b = array( + '2 a', + '1 bb 1', + '1 bB 2', + '1 BB 3', + '20 c', + '10 d', + '3 e', +); + +array_multisort($b, SORT_STRING, $a); + +var_dump($a, $b); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : case-sensitive +array(7) { + [0]=> + string(7) "First.3" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.1" + [3]=> + string(5) "Tenth" + [4]=> + string(6) "Second" + [5]=> + string(9) "Twentieth" + [6]=> + string(5) "Third" +} +array(7) { + [0]=> + string(6) "1 BB 3" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 bb 1" + [3]=> + string(4) "10 d" + [4]=> + string(3) "2 a" + [5]=> + string(4) "20 c" + [6]=> + string(3) "3 e" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_error.phpt b/ext/standard/tests/array/array_multisort_error.phpt new file mode 100644 index 0000000..5956630 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_multisort() function : error conditions +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_multisort() function with Zero arguments --\n"; +var_dump( array_multisort() ); + +echo "\n-- Testing array_multisort() function with repeated flags --\n"; +$ar1 = array(1); +var_dump( array_multisort($ar1, SORT_ASC, SORT_ASC) ); + +echo "\n-- Testing array_multisort() function with repeated flags --\n"; +$ar1 = array(1); +var_dump( array_multisort($ar1, SORT_STRING, SORT_NUMERIC) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : error conditions *** + +-- Testing array_multisort() function with Zero arguments -- + +Warning: array_multisort() expects at least 1 parameter, 0 given in %sarray_multisort_error.php on line %d +NULL + +-- Testing array_multisort() function with repeated flags -- + +Warning: array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified in %sarray_multisort_error.php on line %d +bool(false) + +-- Testing array_multisort() function with repeated flags -- + +Warning: array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified in %sarray_multisort_error.php on line %d +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_multisort_incase.phpt b/ext/standard/tests/array/array_multisort_incase.phpt new file mode 100644 index 0000000..951cce4 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_incase.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_multisort() function : case-insensitive +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : case-insensitive\n"; + +$a = array( + 'Second', + 'First.1', + 'First.2', + 'First.3', + 'Twentieth', + 'Tenth', + 'Third', +); + +$b = array( + '2 a', + '1 bb 1', + '1 bB 2', + '1 BB 3', + '20 c', + '10 d', + '3 e', +); + +array_multisort($b, SORT_STRING | SORT_FLAG_CASE, $a); + +var_dump($a, $b); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : case-insensitive +array(7) { + [0]=> + string(7) "First.1" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.3" + [3]=> + string(5) "Tenth" + [4]=> + string(6) "Second" + [5]=> + string(9) "Twentieth" + [6]=> + string(5) "Third" +} +array(7) { + [0]=> + string(6) "1 bb 1" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 BB 3" + [3]=> + string(4) "10 d" + [4]=> + string(3) "2 a" + [5]=> + string(4) "20 c" + [6]=> + string(3) "3 e" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_natural.phpt b/ext/standard/tests/array/array_multisort_natural.phpt new file mode 100644 index 0000000..e791088 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_natural.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_multisort() function : natural sorting +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : natural sorting\n"; + +$a = array( + 'Second', + 'First', + 'Twentieth', + 'Tenth', + 'Third', +); + +$b = array( + '2 a', + '1 b', + '20 c', + '10 d', + '3 e', +); + +array_multisort($b, SORT_NATURAL, $a); + +var_dump($a, $b); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : natural sorting +array(5) { + [0]=> + string(5) "First" + [1]=> + string(6) "Second" + [2]=> + string(5) "Third" + [3]=> + string(5) "Tenth" + [4]=> + string(9) "Twentieth" +} +array(5) { + [0]=> + string(3) "1 b" + [1]=> + string(3) "2 a" + [2]=> + string(3) "3 e" + [3]=> + string(4) "10 d" + [4]=> + string(4) "20 c" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_natural_case.phpt b/ext/standard/tests/array/array_multisort_natural_case.phpt new file mode 100644 index 0000000..d59e493 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_natural_case.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_multisort() function : natural sorting case-sensitive +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : natural sorting case-sensitive\n"; + +$a = array( + 'Second', + 'First.1', + 'First.2', + 'First.3', + 'Twentieth', + 'Tenth', + 'Third', +); + +$b = array( + '2 a', + '1 bb 1', + '1 bB 2', + '1 BB 3', + '20 c', + '10 d', + '3 e', +); + +array_multisort($b, SORT_NATURAL, $a); + +var_dump($a, $b); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : natural sorting case-sensitive +array(7) { + [0]=> + string(7) "First.3" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.1" + [3]=> + string(6) "Second" + [4]=> + string(5) "Third" + [5]=> + string(5) "Tenth" + [6]=> + string(9) "Twentieth" +} +array(7) { + [0]=> + string(6) "1 BB 3" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 bb 1" + [3]=> + string(3) "2 a" + [4]=> + string(3) "3 e" + [5]=> + string(4) "10 d" + [6]=> + string(4) "20 c" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_natural_incase.phpt b/ext/standard/tests/array/array_multisort_natural_incase.phpt new file mode 100644 index 0000000..8751405 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_natural_incase.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_multisort() function : natural sorting case-insensitive +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : natural sorting case-insensitive\n"; + +$a = array( + 'Second', + 'First.1', + 'First.2', + 'First.3', + 'Twentieth', + 'Tenth', + 'Third', +); + +$b = array( + '2 a', + '1 bb 1', + '1 bB 2', + '1 BB 3', + '20 c', + '10 d', + '3 e', +); + +array_multisort($b, SORT_NATURAL | SORT_FLAG_CASE, $a); + +var_dump($a, $b); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : natural sorting case-insensitive +array(7) { + [0]=> + string(7) "First.1" + [1]=> + string(7) "First.2" + [2]=> + string(7) "First.3" + [3]=> + string(6) "Second" + [4]=> + string(5) "Third" + [5]=> + string(5) "Tenth" + [6]=> + string(9) "Twentieth" +} +array(7) { + [0]=> + string(6) "1 bb 1" + [1]=> + string(6) "1 bB 2" + [2]=> + string(6) "1 BB 3" + [3]=> + string(3) "2 a" + [4]=> + string(3) "3 e" + [5]=> + string(4) "10 d" + [6]=> + string(4) "20 c" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation1.phpt b/ext/standard/tests/array/array_multisort_variation1.phpt new file mode 100644 index 0000000..93c2659 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation1.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_multisort() function : usage variation +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +$ar2 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ar1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_multisort($value)); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : usage variation *** + +--int 0-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation1.php(%d) +bool(false) + +--int 1-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation1.php(%d) +bool(false) + +--int 12345-- +Error: 2 - array_multisort(): Argument #1 is an unknown sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--int -12345-- +Error: 2 - array_multisort(): Argument #1 is an unknown sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--float 10.5-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--float -10.5-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--float .5-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--lowercase null-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--lowercase true-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--lowercase false-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--empty string DQ-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--empty string SQ-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--string DQ-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--string SQ-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--mixed case string-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--heredoc-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--undefined var-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) + +--unset var-- +Error: 2 - array_multisort(): Argument #1 is expected to be an array or a sort flag, %sarray_multisort_variation1.php(%d) +bool(false) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_multisort_variation10.phpt b/ext/standard/tests/array/array_multisort_variation10.phpt new file mode 100644 index 0000000..71c4494 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation10.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with anonymous arrary arguments +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : Testing with anonymous arguments ***\n"; + +var_dump(array_multisort(array(1,3,2,4))); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : Testing with anonymous arguments *** +bool(true) +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation11.phpt b/ext/standard/tests/array/array_multisort_variation11.phpt new file mode 100644 index 0000000..046b45f --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation11.phpt @@ -0,0 +1,21 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with empty array +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : Testing with empty array ***\n"; + +var_dump(array_multisort(array())); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +*** Testing array_multisort() : Testing with empty array *** +bool(true) +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation2.phpt b/ext/standard/tests/array/array_multisort_variation2.phpt new file mode 100644 index 0000000..86210ee --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation2.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_multisort() function : usage variation +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$ar1 = array(1, 2); +$ar2 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_multisort($ar1, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : usage variation *** + +--int 0-- +bool(true) + +--int 1-- +bool(true) + +--int 12345-- +Error: 2 - array_multisort(): Argument #2 is an unknown sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--int -12345-- +Error: 2 - array_multisort(): Argument #2 is an unknown sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--float 10.5-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--float -10.5-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--float .5-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--empty array-- +Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d) +bool(false) + +--int indexed array-- +Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d) +bool(false) + +--associative array-- +bool(true) + +--nested arrays-- +Error: 2 - array_multisort(): Array sizes are inconsistent, %sarray_multisort_variation2.php(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--lowercase null-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--lowercase true-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--lowercase false-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--empty string DQ-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--empty string SQ-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--string DQ-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--string SQ-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--mixed case string-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--heredoc-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--undefined var-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) + +--unset var-- +Error: 2 - array_multisort(): Argument #2 is expected to be an array or a sort flag, %sarray_multisort_variation2.php(%d) +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation3.phpt b/ext/standard/tests/array/array_multisort_variation3.phpt new file mode 100644 index 0000000..b2cdb05 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation3.phpt @@ -0,0 +1,208 @@ +--TEST-- +Test array_multisort() function : usage variation +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : usage variation ***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + if (error_reporting() != 0) { + // report non-silenced errors + echo "Error: $err_no - $err_msg, $filename($linenum)\n"; + } +} +set_error_handler('test_error_handler'); + +// Initialise function arguments not being substituted (if any) +$ar1 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ar2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_multisort($ar1, SORT_REGULAR, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : usage variation *** + +--int 0-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation3.php(%d) +bool(false) + +--int 1-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or sorting flag that has not already been specified, %sarray_multisort_variation3.php(%d) +bool(false) + +--int 12345-- +Error: 2 - array_multisort(): Argument #3 is an unknown sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--int -12345-- +Error: 2 - array_multisort(): Argument #3 is an unknown sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--float 10.5-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--float -10.5-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--float 12.3456789000e10-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--float -12.3456789000e10-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--float .5-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--uppercase NULL-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--lowercase null-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--lowercase true-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--lowercase false-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--uppercase TRUE-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--uppercase FALSE-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--empty string DQ-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--empty string SQ-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--string DQ-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--string SQ-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--mixed case string-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--heredoc-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--instance of classWithToString-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--instance of classWithoutToString-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--undefined var-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) + +--unset var-- +Error: 2 - array_multisort(): Argument #3 is expected to be an array or a sort flag, %sarray_multisort_variation3.php(%d) +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation4.phpt b/ext/standard/tests/array/array_multisort_variation4.phpt new file mode 100644 index 0000000..5d11fb3 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation4.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with multiple array arguments +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : Testing with multiple array arguments ***\n"; + +$arr1 = array (4,3,3,3); +$arr2 = array (9,3,2,2); +$arr3 = array (9,9,2,1); + +var_dump(array_multisort($arr1, $arr2, $arr3)); + +var_dump($arr1); +var_dump($arr2); +var_dump($arr3); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : Testing with multiple array arguments *** +bool(true) +array(4) { + [0]=> + int(3) + [1]=> + int(3) + [2]=> + int(3) + [3]=> + int(4) +} +array(4) { + [0]=> + int(2) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(9) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(9) + [3]=> + int(9) +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation5.phpt b/ext/standard/tests/array/array_multisort_variation5.phpt new file mode 100644 index 0000000..76d7092 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation5.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with multiple array arguments +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : Testing all array sort specifiers ***\n"; + +$ar = array( 2, "aa" , "1"); + +array_multisort($ar, SORT_REGULAR, SORT_ASC); +var_dump($ar); + +array_multisort($ar, SORT_STRING, SORT_ASC); +var_dump($ar); + +array_multisort($ar, SORT_NUMERIC, SORT_ASC); +var_dump($ar); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : Testing all array sort specifiers *** +array(3) { + [0]=> + string(1) "1" + [1]=> + string(2) "aa" + [2]=> + int(2) +} +array(3) { + [0]=> + string(1) "1" + [1]=> + int(2) + [2]=> + string(2) "aa" +} +array(3) { + [0]=> + string(2) "aa" + [1]=> + string(1) "1" + [2]=> + int(2) +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation6.phpt b/ext/standard/tests/array/array_multisort_variation6.phpt new file mode 100644 index 0000000..4e2a622 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation6.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_multisort() function : usage variation - testing with multiple array arguments +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : Testing all array sort specifiers ***\n"; + +$ar = array( 2, "aa" , "1"); + +array_multisort($ar, SORT_REGULAR, SORT_DESC); +var_dump($ar); + +array_multisort($ar, SORT_STRING, SORT_DESC); +var_dump($ar); + +array_multisort($ar, SORT_NUMERIC, SORT_DESC); +var_dump($ar); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : Testing all array sort specifiers *** +array(3) { + [0]=> + int(2) + [1]=> + string(2) "aa" + [2]=> + string(1) "1" +} +array(3) { + [0]=> + string(2) "aa" + [1]=> + int(2) + [2]=> + string(1) "1" +} +array(3) { + [0]=> + int(2) + [1]=> + string(1) "1" + [2]=> + string(2) "aa" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation7.phpt b/ext/standard/tests/array/array_multisort_variation7.phpt new file mode 100644 index 0000000..4e9feb5 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation7.phpt @@ -0,0 +1,68 @@ +--TEST-- +Test array_multisort() function : usage variation - test sort order of all types +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : usage variation - test sort order of all types***\n"; + +// define some classes +class classWithToString { + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString { } + +$inputs = array( + 'int 0' => 0, + 'float -10.5' => -10.5, + array(), + 'uppercase NULL' => NULL, + 'lowercase true' => true, + 'empty string DQ' => "", + 'string DQ' => "string", + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + 'undefined var' => @$undefined_var, +); + +var_dump(array_multisort($inputs)); +var_dump($inputs); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : usage variation - test sort order of all types*** +bool(true) +array(10) { + ["empty string DQ"]=> + string(0) "" + ["int 0"]=> + int(0) + ["uppercase NULL"]=> + NULL + ["undefined var"]=> + NULL + [0]=> + array(0) { + } + ["instance of classWithToString"]=> + object(classWithToString)#1 (0) { + } + ["instance of classWithoutToString"]=> + object(classWithoutToString)#2 (0) { + } + ["lowercase true"]=> + bool(true) + ["float -10.5"]=> + float(-10.5) + ["string DQ"]=> + string(6) "string" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation8.phpt b/ext/standard/tests/array/array_multisort_variation8.phpt new file mode 100644 index 0000000..1995ee8 --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation8.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_multisort() function : usage variation - test sort order of all types +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : usage variation - test sort order of all types***\n"; + +// Define error handler +function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) { + // We're testing sort order not errors so ignore. +} +set_error_handler('test_error_handler'); + +// define some classes +class classWithToString { + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString { } + +$inputs = array( + 'int 0' => 0, + 'float -10.5' => -10.5, + array(), + 'uppercase NULL' => NULL, + 'lowercase true' => true, + 'empty string DQ' => "", + 'string DQ' => "string", + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + 'undefined var' => @$undefined_var, +); + +var_dump(array_multisort($inputs, SORT_STRING)); +var_dump($inputs); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : usage variation - test sort order of all types*** +bool(true) +array(10) { + ["empty string DQ"]=> + string(0) "" + ["uppercase NULL"]=> + NULL + ["undefined var"]=> + NULL + ["instance of classWithoutToString"]=> + object(classWithoutToString)#2 (0) { + } + ["float -10.5"]=> + float(-10.5) + ["int 0"]=> + int(0) + ["lowercase true"]=> + bool(true) + [0]=> + array(0) { + } + ["instance of classWithToString"]=> + object(classWithToString)#1 (0) { + } + ["string DQ"]=> + string(6) "string" +} +===DONE=== diff --git a/ext/standard/tests/array/array_multisort_variation9.phpt b/ext/standard/tests/array/array_multisort_variation9.phpt new file mode 100644 index 0000000..b56357a --- /dev/null +++ b/ext/standard/tests/array/array_multisort_variation9.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test array_multisort() function : usage variation - test sort order of all types +--FILE-- +<?php +/* Prototype : bool array_multisort(array ar1 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]] [, array ar2 [, SORT_ASC|SORT_DESC [, SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_NATURAL|SORT_FLAG_CASE]], ...]) + * Description: Sort multiple arrays at once similar to how ORDER BY clause works in SQL + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_multisort() : usage variation - test sort order of all types***\n"; + +// define some classes +class classWithToString { + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString { } + +$inputs = array( + 'int 0' => 0, + 'float -10.5' => -10.5, + array(), + 'uppercase NULL' => NULL, + 'lowercase true' => true, + 'empty string DQ' => "", + 'string DQ' => "string", + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + 'undefined var' => @$undefined_var, +); + +var_dump(array_multisort($inputs, SORT_NUMERIC)); +var_dump($inputs); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_multisort() : usage variation - test sort order of all types*** + +Notice: Object of class classWithToString could not be converted to double in %sarray_multisort_variation9.php on line %d + +Notice: Object of class classWithoutToString could not be converted to double in %sarray_multisort_variation9.php on line %d + +Notice: Object of class classWithoutToString could not be converted to double in %sarray_multisort_variation9.php on line %d + +Notice: Object of class classWithoutToString could not be converted to double in %sarray_multisort_variation9.php on line %d + +Notice: Object of class classWithoutToString could not be converted to double in %sarray_multisort_variation9.php on line %d +bool(true) +array(10) { + ["float -10.5"]=> + float(-10.5) + ["string DQ"]=> + string(6) "string" + ["undefined var"]=> + NULL + ["empty string DQ"]=> + string(0) "" + ["uppercase NULL"]=> + NULL + ["int 0"]=> + int(0) + [0]=> + array(0) { + } + ["instance of classWithoutToString"]=> + object(classWithoutToString)#2 (0) { + } + ["lowercase true"]=> + bool(true) + ["instance of classWithToString"]=> + object(classWithToString)#1 (0) { + } +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_next_error1.phpt b/ext/standard/tests/array/array_next_error1.phpt new file mode 100644 index 0000000..72f2cb9 --- /dev/null +++ b/ext/standard/tests/array/array_next_error1.phpt @@ -0,0 +1,13 @@ +--TEST-- +next - ensure warning is received when passing an indirect temporary. +--FILE-- +<?php +function f() { + return array(1, 2); +} +var_dump(next(f())); +?> +--EXPECTF-- + +Strict Standards: Only variables should be passed by reference in %s on line %d +int(2)
\ No newline at end of file diff --git a/ext/standard/tests/array/array_next_error2.phpt b/ext/standard/tests/array/array_next_error2.phpt new file mode 100644 index 0000000..d4f1666 --- /dev/null +++ b/ext/standard/tests/array/array_next_error2.phpt @@ -0,0 +1,12 @@ +--TEST-- +next - ensure we cannot pass a temporary +--FILE-- +<?php +function f() { + return array(1, 2); +} +var_dump(next(array(1, 2))); +?> +--EXPECTF-- + +Fatal error: Only variables can be passed by reference in %s on line %d
\ No newline at end of file diff --git a/ext/standard/tests/array/array_pad.phpt b/ext/standard/tests/array/array_pad.phpt new file mode 100644 index 0000000..add9b3c --- /dev/null +++ b/ext/standard/tests/array/array_pad.phpt @@ -0,0 +1,101 @@ +--TEST-- +array_pad() tests +--FILE-- +<?php + +var_dump(array_pad()); +var_dump(array_pad(array())); +var_dump(array_pad(array(), 1)); +var_dump(array_pad(array(), 1, 0)); + +var_dump(array_pad(array(), 0, 0)); +var_dump(array_pad(array(), -1, 0)); +var_dump(array_pad(array("", -1, 2.0), 5, 0)); +var_dump(array_pad(array("", -1, 2.0), 5, array())); +var_dump(array_pad(array("", -1, 2.0), 2, array())); +var_dump(array_pad(array("", -1, 2.0), -3, array())); +var_dump(array_pad(array("", -1, 2.0), -4, array())); +var_dump(array_pad(array("", -1, 2.0), 2000000, 0)); +var_dump(array_pad("", 2000000, 0)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_pad() expects exactly 3 parameters, 0 given in %s on line %d +NULL + +Warning: array_pad() expects exactly 3 parameters, 1 given in %s on line %d +NULL + +Warning: array_pad() expects exactly 3 parameters, 2 given in %s on line %d +NULL +array(1) { + [0]=> + int(0) +} +array(0) { +} +array(1) { + [0]=> + int(0) +} +array(5) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) + [3]=> + int(0) + [4]=> + int(0) +} +array(5) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) + [3]=> + array(0) { + } + [4]=> + array(0) { + } +} +array(3) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) +} +array(3) { + [0]=> + string(0) "" + [1]=> + int(-1) + [2]=> + float(2) +} +array(4) { + [0]=> + array(0) { + } + [1]=> + string(0) "" + [2]=> + int(-1) + [3]=> + float(2) +} + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_error.phpt b/ext/standard/tests/array/array_pad_error.phpt new file mode 100644 index 0000000..63b4c83 --- /dev/null +++ b/ext/standard/tests/array/array_pad_error.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_pad() function : error conditions +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_pad() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_pad() function with Zero arguments --\n"; +var_dump( array_pad() ); + +//Test array_pad with one more than the expected number of arguments +echo "\n-- Testing array_pad() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$pad_size = 10; +$pad_value = 1; +$extra_arg = 10; +var_dump( array_pad($input, $pad_size, $pad_value, $extra_arg) ); + +// Testing array_pad with less than the expected number of arguments +echo "\n-- Testing array_pad() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +$pad_size = 10; +var_dump( array_pad($input, $pad_size) ); +var_dump( array_pad($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : error conditions *** + +-- Testing array_pad() function with Zero arguments -- + +Warning: array_pad() expects exactly 3 parameters, 0 given in %s on line %d +NULL + +-- Testing array_pad() function with more than expected no. of arguments -- + +Warning: array_pad() expects exactly 3 parameters, 4 given in %s on line %d +NULL + +-- Testing array_pad() function with less than expected no. of arguments -- + +Warning: array_pad() expects exactly 3 parameters, 2 given in %s on line %d +NULL + +Warning: array_pad() expects exactly 3 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_variation1.phpt b/ext/standard/tests/array/array_pad_variation1.phpt new file mode 100644 index 0000000..18a7044 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation1.phpt @@ -0,0 +1,270 @@ +--TEST-- +Test array_pad() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function by passing values to $input argument other than arrays +* and see that function outputs proper warning messages wherever expected. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : passing non array values to \$input argument ***\n"; + +// Initialise $pad_size and $pad_value +$pad_size = 10; +$pad_value = 1; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : passing non array values to $input argument *** + +-- Iteration 1 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d +NULL + +Warning: array_pad() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_pad_variation2.phpt b/ext/standard/tests/array/array_pad_variation2.phpt new file mode 100644 index 0000000..0267f20 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation2.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test array_pad() function : usage variations - unexpected values for 'pad_size' argument(Bug#43482) +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function by passing values to $pad_size argument other than integers +* and see that function outputs proper warning messages wherever expected. +* The $input and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : passing non integer values to \$pad_size argument ***\n"; + +// Initialise $input and $pad_value arguments +$input = array(1, 2); +$pad_value = 1; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +//array of values to iterate over +$pad_sizes = array( + + // float data +/*1*/ 10.5, + -10.5, + 12.3456789000e10, + -12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*6*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*11*/ NULL, + null, + + // boolean data +/*13*/ true, + false, + TRUE, + FALSE, + + // empty data +/*17*/ "", + '', + + // string data +/*19*/ "string", + 'string', + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $pad_sizes to check the behavior of array_pad() +$iterator = 1; +foreach($pad_sizes as $pad_size) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : passing non integer values to $pad_size argument *** +-- Iteration 1 -- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) + [6]=> + int(1) + [7]=> + int(1) + [8]=> + int(1) + [9]=> + int(1) +} +-- Iteration 2 -- +array(10) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) + [6]=> + int(1) + [7]=> + int(1) + [8]=> + int(1) + [9]=> + int(2) +} +-- Iteration 3 -- + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d +bool(false) +-- Iteration 5 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 6 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 7 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_pad() expects parameter 2 to be long, array given in %s on line %d +NULL +-- Iteration 12 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 13 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 14 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 15 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 16 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 17 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 18 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_pad() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_pad() expects parameter 2 to be long, object given in %s on line %d +NULL +-- Iteration 23 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 24 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation3.phpt b/ext/standard/tests/array/array_pad_variation3.phpt new file mode 100644 index 0000000..75df118 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation3.phpt @@ -0,0 +1,869 @@ +--TEST-- +Test array_pad() function : usage variations - possible values for 'pad_value' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_pad() function for expected behavior by passing +* different possible values for $pad_value argument. +* $input and $pad_size arguments take fixed value. +*/ + +echo "*** Testing array_pad() : possible values for \$pad_value argument ***\n"; + +// Initialise $input and $pad_size argument +$input = array(1, 2); +$pad_size = 4; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a reference variable +$value = "hello"; +$reference = &$value; + +// different values to be passed to $pad_value argument +$pad_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // strings with different white spaces +/*26*/ "\v\fHello\t world!! \rstring\n", + '\v\fHello\t world!! \rstring\n', + + // object data +/*28*/ new classA(), + + // undefined data +/*29*/ @$undefined_var, + + // unset data +/*30*/ @$unset_var, + + // resource variable +/*31*/ $fp, + + // reference variable +/*32*/ $reference +); + +// loop through each element of $pad_values to check the behavior of array_pad() +$iterator = 1; +foreach($pad_values as $pad_value) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : possible values for $pad_value argument *** +-- Iteration 1 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(0) + [3]=> + int(0) +} +array(4) { + [0]=> + int(0) + [1]=> + int(0) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 2 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(1) + [3]=> + int(1) +} +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 3 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(12345) + [3]=> + int(12345) +} +array(4) { + [0]=> + int(12345) + [1]=> + int(12345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 4 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(-2345) + [3]=> + int(-2345) +} +array(4) { + [0]=> + int(-2345) + [1]=> + int(-2345) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 5 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(10.5) + [3]=> + float(10.5) +} +array(4) { + [0]=> + float(10.5) + [1]=> + float(10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 6 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(-10.5) + [3]=> + float(-10.5) +} +array(4) { + [0]=> + float(-10.5) + [1]=> + float(-10.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 7 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(123456789000) + [3]=> + float(123456789000) +} +array(4) { + [0]=> + float(123456789000) + [1]=> + float(123456789000) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 8 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(1.23456789E-9) + [3]=> + float(1.23456789E-9) +} +array(4) { + [0]=> + float(1.23456789E-9) + [1]=> + float(1.23456789E-9) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 9 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + float(0.5) + [3]=> + float(0.5) +} +array(4) { + [0]=> + float(0.5) + [1]=> + float(0.5) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 10 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(0) { + } + [3]=> + array(0) { + } +} +array(4) { + [0]=> + array(0) { + } + [1]=> + array(0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 11 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(0) + } + [3]=> + array(1) { + [0]=> + int(0) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(0) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 12 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(1) { + [0]=> + int(1) + } + [3]=> + array(1) { + [0]=> + int(1) + } +} +array(4) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(1) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 13 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [3]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(4) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 14 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [3]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } +} +array(4) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 15 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 16 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 17 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 18 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 19 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(true) + [3]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 20 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + bool(false) + [3]=> + bool(false) +} +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 21 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 22 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(0) "" + [3]=> + string(0) "" +} +array(4) { + [0]=> + string(0) "" + [1]=> + string(0) "" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 23 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 24 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(6) "string" + [3]=> + string(6) "string" +} +array(4) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 25 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(11) "hello world" + [3]=> + string(11) "hello world" +} +array(4) { + [0]=> + string(11) "hello world" + [1]=> + string(11) "hello world" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 26 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(25) "Hello world!!
string +" + [3]=> + string(25) "Hello world!!
string +" +} +array(4) { + [0]=> + string(25) "Hello world!!
string +" + [1]=> + string(25) "Hello world!!
string +" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 27 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(30) "\v\fHello\t world!! \rstring\n" + [3]=> + string(30) "\v\fHello\t world!! \rstring\n" +} +array(4) { + [0]=> + string(30) "\v\fHello\t world!! \rstring\n" + [1]=> + string(30) "\v\fHello\t world!! \rstring\n" + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 28 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + object(classA)#%d (0) { + } + [3]=> + object(classA)#%d (0) { + } +} +array(4) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + object(classA)#%d (0) { + } + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 29 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 30 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + NULL + [3]=> + NULL +} +array(4) { + [0]=> + NULL + [1]=> + NULL + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 31 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + resource(%d) of type (stream) + [3]=> + resource(%d) of type (stream) +} +array(4) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) + [2]=> + int(1) + [3]=> + int(2) +} +-- Iteration 32 -- +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" +} +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + int(1) + [3]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation4.phpt b/ext/standard/tests/array/array_pad_variation4.phpt new file mode 100644 index 0000000..83c1e83 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation4.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_pad() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing binary values to $pad_value argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $input and $pad_size arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing binary values to \$pad_value argument ***\n"; + +// initialize the $input and $pad_size argument +$input = array(1, 2, 3); +$pad_size = 6; + +// initialize $pad_value with reference variable +$binary = b"hello"; + +var_dump( array_pad($input, $pad_size, $binary) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $binary) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing binary values to $pad_value argument *** +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + string(5) "hello" + [4]=> + string(5) "hello" + [5]=> + string(5) "hello" +} +array(6) { + [0]=> + string(5) "hello" + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + int(1) + [4]=> + int(2) + [5]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation5.phpt b/ext/standard/tests/array/array_pad_variation5.phpt new file mode 100644 index 0000000..4e8e0f1 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation5.phpt @@ -0,0 +1,140 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'pad_value' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing two dimensional array to $pad_value argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $input and $pad_size arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing 2-d array to \$pad_value argument ***\n"; + +// initialize the $input and $pad_size argument +$input = array(1, 2, 3); +$pad_size = 5; + +// initialize $pad_value +$pad_value = array ( + array(1), + array("hello", 'world'), + array("one" => 1, 'two' => 2) +); + +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_value' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_value' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing 2-d array to $pad_value argument *** +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [4]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } +} +array(5) { + [0]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [1]=> + array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + } + [2]=> + int(1) + [3]=> + int(2) + [4]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation6.phpt b/ext/standard/tests/array/array_pad_variation6.phpt new file mode 100644 index 0000000..2f97e3e --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation6.phpt @@ -0,0 +1,668 @@ +--TEST-- +Test array_pad() function : usage variations - different arrays for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $input argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing different arrays to \$input argument ***\n"; + +/* Different heredoc strings */ + +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// different arrays to be passed to $input argument +$inputs = array ( +/*1*/ array(1, 2), // with default keys and numeric values + array(1.1, 2.2), // with default keys & float values + array(false,true), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL), // with NULL + array("a\v\f", "aaaa\r", "b\tbbb", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b\tbbb', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $numeric_string), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*19*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 6; +$pad_value = "HELLO"; + +// loop through each sub-array within $inputs to check the behavior of array_pad() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' + var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + int(1) + [5]=> + int(2) +} +-- Iteration 2 -- +array(6) { + [0]=> + float(1.1) + [1]=> + float(2.2) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + float(1.1) + [5]=> + float(2.2) +} +-- Iteration 3 -- +array(6) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + bool(false) + [5]=> + bool(true) +} +-- Iteration 4 -- +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +-- Iteration 5 -- +array(6) { + [0]=> + NULL + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + NULL +} +-- Iteration 6 -- +array(6) { + [0]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(5) "b bbb" + [3]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(3) "a" + [3]=> + string(5) "aaaa
" + [4]=> + string(5) "b bbb" + [5]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(6) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(6) "b\tbbb" + [3]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "a\v\f" + [3]=> + string(6) "aaaa\r" + [4]=> + string(6) "b\tbbb" + [5]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(6) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [0]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + ["h1"]=> + string(1) " +" + ["h2"]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [2]=> + string(90) "11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111. 0000 = 0000 +" +} +-- Iteration 9 -- +array(6) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 10 -- +array(6) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 11 -- +array(6) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(40) + [3]=> + int(30) + [4]=> + string(5) "HELLO" + [5]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + int(10) + [3]=> + int(20) + [4]=> + int(40) + [5]=> + int(30) +} +-- Iteration 12 -- +array(6) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 13 -- +array(6) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(4) "four" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(6) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 15 -- +array(6) { + [0]=> + string(4) "true" + [1]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(4) "true" + [3]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(6) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 17 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 18 -- +array(6) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 19 -- +array(6) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" +} +array(6) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_pad_variation7.phpt b/ext/standard/tests/array/array_pad_variation7.phpt new file mode 100644 index 0000000..887f351 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation7.phpt @@ -0,0 +1,127 @@ +--TEST-- +Test array_pad() function : usage variations - two dimensional array for 'input' argument +--FILE-- +<?php +/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value) + * Description: Returns a copy of input array padded with pad_value to size pad_size + * Source code: ext/standard/array.c +*/ + +/* +* Passing two dimensional array to $input argument and testing whether +* array_pad() behaves in an expected way with the other arguments passed to the function. +* The $pad_size and $pad_value arguments passed are fixed values. +*/ + +echo "*** Testing array_pad() : Passing 2-D array to \$input argument ***\n"; + +// initialize the 2-d array +$input = array ( + array(1, 2, 3), + array("hello", 'world'), + array("one" => 1, "two" => 2) +); + +// initialize the $pad_size and $pad_value arguments +$pad_size = 5; +$pad_value = "HELLO"; + +// entire 2-d array +echo "-- Entire 2-d array for \$input argument --\n"; +var_dump( array_pad($input, $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input, -$pad_size, $pad_value) ); // negative 'pad_size' + +// sub array +echo "-- Sub array for \$input argument --\n"; +var_dump( array_pad($input[1], $pad_size, $pad_value) ); // positive 'pad_size' +var_dump( array_pad($input[1], -$pad_size, $pad_value) ); // negative 'pad_size' + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : Passing 2-D array to $input argument *** +-- Entire 2-d array for $input argument -- +array(5) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [2]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + } + [4]=> + array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) + } +} +-- Sub array for $input argument -- +array(5) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "HELLO" + [4]=> + string(5) "HELLO" +} +array(5) { + [0]=> + string(5) "HELLO" + [1]=> + string(5) "HELLO" + [2]=> + string(5) "HELLO" + [3]=> + string(5) "hello" + [4]=> + string(5) "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 0000000..34a5c54 --- /dev/null +++ b/ext/standard/tests/array/array_pop.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test array_pop() function +--FILE-- +<?php + +array_pop($GLOBALS); + +$empty_array = array(); +$number = 5; +$str = "abc"; + + +/* 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 ) +); + +/* 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"\nDone"; +?> +--EXPECTF-- +*** 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) + +Done diff --git a/ext/standard/tests/array/array_pop_errors.phpt b/ext/standard/tests/array/array_pop_errors.phpt new file mode 100644 index 0000000..d6c86c3 --- /dev/null +++ b/ext/standard/tests/array/array_pop_errors.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_pop() function (errors) +--FILE-- +<?php + +$empty_array = array(); +$number = 5; +$str = "abc"; + + +/* 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 ) +); + +/* 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) ); + +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 + +Done diff --git a/ext/standard/tests/array/array_pop_variation.phpt b/ext/standard/tests/array/array_pop_variation.phpt new file mode 100644 index 0000000..795a8bc --- /dev/null +++ b/ext/standard/tests/array/array_pop_variation.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_pop() function (variation) +--FILE-- +<?php + +/* 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 ) +); + +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-- +*** 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_product_error.phpt b/ext/standard/tests/array/array_product_error.phpt new file mode 100644 index 0000000..79f7cb4 --- /dev/null +++ b/ext/standard/tests/array/array_product_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_product() function : error conditions +--FILE-- +<?php +/* Prototype : mixed array_product(array input) + * Description: Returns the product of the array entries + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_product() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_product() function with Zero arguments --\n"; +var_dump( array_product() ); + +//Test array_product with one more than the expected number of arguments +echo "\n-- Testing array_product() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$extra_arg = 10; +var_dump( array_product($input, $extra_arg) ); + +echo "\n-- Testing array_product() function incorrect argument type --\n"; +var_dump( array_product("bob") ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : error conditions *** + +-- Testing array_product() function with Zero arguments -- + +Warning: array_product() expects exactly 1 parameter, 0 given in %sarray_product_error.php on line %d +NULL + +-- Testing array_product() function with more than expected no. of arguments -- + +Warning: array_product() expects exactly 1 parameter, 2 given in %sarray_product_error.php on line %d +NULL + +-- Testing array_product() function incorrect argument type -- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_product_variation1.phpt b/ext/standard/tests/array/array_product_variation1.phpt new file mode 100644 index 0000000..cd2ed71 --- /dev/null +++ b/ext/standard/tests/array/array_product_variation1.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_product() function : variation +--FILE-- +<?php +/* Prototype : mixed array_product(array input) + * Description: Returns the product of the array entries + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_product() : variation - using non numeric values ***\n"; + +class A { + static function help() { echo "hello\n"; } +} +$fp = fopen(__FILE__, "r"); + +$types = array("boolean (true)" => true, "boolean (false)" => false, + "string" => "hello", "numeric string" => "12", + "resource" => $fp, "object" => new A(), "null" => null, + "array" => array(3,2)); + +foreach ($types as $desc => $type) { + echo $desc . "\n"; + var_dump(array_product(array($type))); + echo "\n"; +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : variation - using non numeric values *** +boolean (true) +int(1) + +boolean (false) +int(0) + +string +int(0) + +numeric string +int(12) + +resource +int(%d) + +object +int(1) + +null +int(0) + +array +int(1) + +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_product_variation2.phpt b/ext/standard/tests/array/array_product_variation2.phpt new file mode 100644 index 0000000..c4c47d8 --- /dev/null +++ b/ext/standard/tests/array/array_product_variation2.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test array_product() function : variation +--FILE-- +<?php +/* Prototype : mixed array_product(array input) + * Description: Returns the product of the array entries + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_product() : variations ***\n"; + +echo "\n-- Testing array_product() function with a keyed array array --\n"; +var_dump( array_product(array("bob" => 2, "janet" => 5)) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : variations *** + +-- Testing array_product() function with a keyed array array -- +int(10) +===DONE=== diff --git a/ext/standard/tests/array/array_product_variation3.phpt b/ext/standard/tests/array/array_product_variation3.phpt new file mode 100644 index 0000000..dc8609e --- /dev/null +++ b/ext/standard/tests/array/array_product_variation3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_product() function : variation +--FILE-- +<?php +/* Prototype : mixed array_product(array input) + * Description: Returns the product of the array entries + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_product() : variations - negative numbers***\n"; + +echo "\n-- Testing array_product() function with one negative number --\n"; +var_dump( array_product(array(-2)) ); + +echo "\n-- Testing array_product() function with two negative numbers --\n"; +var_dump( array_product(array(-2, -3)) ); + +echo "\n-- Testing array_product() function with three negative numbers --\n"; +var_dump( array_product(array(-2, -3, -4)) ); + +echo "\n-- Testing array_product() function with negative floats --\n"; +var_dump( array_product(array(-1.5))); + +echo "\n-- Testing array_product() function with negative floats --\n"; +var_dump( array_product(array(-99999999.9, 99999999.1))); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : variations - negative numbers*** + +-- Testing array_product() function with one negative number -- +int(-2) + +-- Testing array_product() function with two negative numbers -- +int(6) + +-- Testing array_product() function with three negative numbers -- +int(-24) + +-- Testing array_product() function with negative floats -- +float(-1.5) + +-- Testing array_product() function with negative floats -- +float(-9.9999999E+15) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_product_variation4.phpt b/ext/standard/tests/array/array_product_variation4.phpt new file mode 100644 index 0000000..9f83c56 --- /dev/null +++ b/ext/standard/tests/array/array_product_variation4.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_product() function : variation +--FILE-- +<?php +/* Prototype : mixed array_product(array input) + * Description: Returns the product of the array entries + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_product() : variations ***\n"; + +echo "\n-- Testing array_product() function with a very large array --\n"; + +$array = array(); + +for ($i = 0; $i < 999; $i++) { + $array[] = 999; +} + +var_dump( array_product($array) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : variations *** + +-- Testing array_product() function with a very large array -- +float(INF) +===DONE=== diff --git a/ext/standard/tests/array/array_product_variation5.phpt b/ext/standard/tests/array/array_product_variation5.phpt new file mode 100644 index 0000000..183612e --- /dev/null +++ b/ext/standard/tests/array/array_product_variation5.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test array_product() function : usage variation +--FILE-- +<?php +/* Prototype : mixed array_product(array input) + * Description: Returns the product of the array entries + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_product() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for input + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_product($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : usage variation *** + +--int 0-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--int 1-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--int 12345-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--int -12345-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--float 10.5-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float -10.5-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float .5-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL + +--lowercase null-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL + +--lowercase true-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--lowercase false-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--empty string DQ-- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_variation5.php on line %d +NULL + +--empty string SQ-- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_variation5.php on line %d +NULL + +--string DQ-- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_variation5.php on line %d +NULL + +--string SQ-- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_variation5.php on line %d +NULL + +--mixed case string-- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_variation5.php on line %d +NULL + +--heredoc-- + +Warning: array_product() expects parameter 1 to be array, string given in %sarray_product_variation5.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_product() expects parameter 1 to be array, object given in %sarray_product_variation5.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_product() expects parameter 1 to be array, object given in %sarray_product_variation5.php on line %d +NULL + +--undefined var-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL + +--unset var-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_push.phpt b/ext/standard/tests/array/array_push.phpt new file mode 100644 index 0000000..cea77f4 --- /dev/null +++ b/ext/standard/tests/array/array_push.phpt @@ -0,0 +1,282 @@ +--TEST-- +Test array_push() function +--FILE-- +<?php + +/* Prototype: int array_push( array &array ); + * Description: Push one or more elements onto the end of array + and returns the new number of elements in the array. + */ + +$empty_array = array(); +$number = 5; +$str = "abc"; + + +/* 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 ) +); + +/* Error Conditions */ +echo "\n*** Testing Error Conditions ***\n"; + +/* Zero argument */ +var_dump( array_push() ); + +/* Scalar argument */ +var_dump( array_push($number, 22) ); + +/* String argument */ +var_dump( array_push($str, 22) ); + +/* Invalid Number of arguments */ +var_dump( array_push($mixed_array[1],1,2) ); + +/* Empty Array as argument */ +var_dump( array_push($empty_array, 2) ); + + +/* 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 push is :\n"; + var_dump( array_push($sub_array, 22, "abc") ); + $counter++; +} + +/* Checking for return value and the new array formed from push operation */ +echo "\n*** Checking for return value and the new array formed from push operation ***\n"; +var_dump( array_push($mixed_array[2], 22, 33, "44") ); +var_dump( $mixed_array[2] ); + +echo"\nDone"; +?> +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: array_push() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_push() expects parameter 1 to be array, string given in %s on line %d +NULL +int(11) +int(1) + +*** Testing with various array inputs *** + +-- Input Array for Iteration 1 is -- +Array +( +) + +Output after push is : +int(2) + +-- 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 + [9] => 1 + [10] => 2 +) + +Output after push is : +int(13) + +-- Input Array for Iteration 3 is -- +Array +( + [0] => One + [1] => _Two + [2] => Three + [3] => Four + [4] => Five +) + +Output after push is : +int(7) + +-- 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 push is : +int(10) + +-- Input Array for Iteration 5 is -- +Array +( + [a] => aaa + [A] => AAA + [c] => ccc + [d] => ddd + [e] => eee +) + +Output after push is : +int(7) + +-- Input Array for Iteration 6 is -- +Array +( + [1] => one + [2] => two + [3] => three + [4] => four + [5] => five +) + +Output after push is : +int(7) + +-- Input Array for Iteration 7 is -- +Array +( + [1] => one + [2] => two + [3] => 7 + [4] => four + [5] => five +) + +Output after push is : +int(7) + +-- 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 push is : +int(14) + +-- Input Array for Iteration 9 is -- +Array +( + [0] => 12 + [1] => name + [2] => age + [3] => 45 +) + +Output after push is : +int(6) + +-- 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 push is : +int(5) + +-- 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 push is : +int(12) + +*** Checking for return value and the new array formed from push operation *** +int(8) +array(8) { + [0]=> + string(3) "One" + [1]=> + string(4) "_Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" + [5]=> + int(22) + [6]=> + int(33) + [7]=> + string(2) "44" +} + +Done diff --git a/ext/standard/tests/array/array_push_basic.phpt b/ext/standard/tests/array/array_push_basic.phpt new file mode 100644 index 0000000..5ccf037 --- /dev/null +++ b/ext/standard/tests/array/array_push_basic.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_push() function : basic functionality +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_push with indexed and associative arrays + */ + +echo "*** Testing array_push() : basic functionality ***\n"; + +$array = array ('zero', 'one', 'two'); +$var1 = 'three'; +$var2 = 'four'; + +echo "\n-- Push values onto an indexed array --\n"; +var_dump(array_push($array, $var1, $var2)); +var_dump($array); + +$array_assoc = array ('one' => 'un', 'two' => 'deux'); + +echo "\n-- Push values onto an associative array --\n"; +var_dump(array_push($array_assoc, $var1, $var2)); +var_dump($array_assoc); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : basic functionality *** + +-- Push values onto an indexed array -- +int(5) +array(5) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" +} + +-- Push values onto an associative array -- +int(4) +array(4) { + ["one"]=> + string(2) "un" + ["two"]=> + string(4) "deux" + [0]=> + string(5) "three" + [1]=> + string(4) "four" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_error1.phpt b/ext/standard/tests/array/array_push_error1.phpt new file mode 100644 index 0000000..fe26fb6 --- /dev/null +++ b/ext/standard/tests/array/array_push_error1.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_push() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_push() to test behaviour + */ + +echo "*** Testing array_push() : error conditions ***\n"; + +// Testing array_push with one less than the expected number of arguments +echo "\n-- Testing array_push() function with less than expected no. of arguments --\n"; +$stack = array(1, 2); +var_dump( array_push($stack) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : error conditions *** + +-- Testing array_push() function with less than expected no. of arguments -- + +Warning: array_push() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_push_error2.phpt b/ext/standard/tests/array/array_push_error2.phpt new file mode 100644 index 0000000..5d7b655 --- /dev/null +++ b/ext/standard/tests/array/array_push_error2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_push() function : error conditions - max int value as key +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Use PHP's maximum integer value as array key + * then try and push new elements onto the array + */ + +echo "*** Testing array_push() : error conditions ***\n"; + +$array = array(PHP_INT_MAX => 'max'); + +var_dump(array_push($array, 'new')); +var_dump($array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : error conditions *** + +Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d +bool(false) +array(1) { + [%d]=> + string(3) "max" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_variation1.phpt b/ext/standard/tests/array/array_push_variation1.phpt new file mode 100644 index 0000000..cef48b9 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation1.phpt @@ -0,0 +1,225 @@ +--TEST-- +Test array_push() function : usage variations - Pass different data types as $stack arg +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $stack argument to array_push() to test behaviour + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$var = 'value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_push($input, $var) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 -- + +Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_push() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_push() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_push() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_push() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_push() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_push() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_push() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_push() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_push() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_push() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_push() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +int(1) + +-- Iteration 19 -- + +Warning: array_push() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_push() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_push() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_push() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_push() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_push() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_push() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_push_variation2.phpt b/ext/standard/tests/array/array_push_variation2.phpt new file mode 100644 index 0000000..7fefcfa --- /dev/null +++ b/ext/standard/tests/array/array_push_variation2.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test array_push() function : usage variations - Pass different data types as $var arg +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $var argument to array_push to test behaviour + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$stack = array (1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $var argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + $temp_array = $stack; + var_dump( array_push($temp_array, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 -- +int(3) + +-- Iteration 2 -- +int(3) + +-- Iteration 3 -- +int(3) + +-- Iteration 4 -- +int(3) + +-- Iteration 5 -- +int(3) + +-- Iteration 6 -- +int(3) + +-- Iteration 7 -- +int(3) + +-- Iteration 8 -- +int(3) + +-- Iteration 9 -- +int(3) + +-- Iteration 10 -- +int(3) + +-- Iteration 11 -- +int(3) + +-- Iteration 12 -- +int(3) + +-- Iteration 13 -- +int(3) + +-- Iteration 14 -- +int(3) + +-- Iteration 15 -- +int(3) + +-- Iteration 16 -- +int(3) + +-- Iteration 17 -- +int(3) + +-- Iteration 18 -- +int(3) + +-- Iteration 19 -- +int(3) + +-- Iteration 20 -- +int(3) + +-- Iteration 21 -- +int(3) + +-- Iteration 22 -- +int(3) + +-- Iteration 23 -- +int(3) + +-- Iteration 24 -- +int(3) + +-- Iteration 25 -- +int(3) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_variation3.phpt b/ext/standard/tests/array/array_push_variation3.phpt new file mode 100644 index 0000000..2bc71a7 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation3.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_push() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Test array_push when passed: + * 1. an array as $var arg + * 2. as sub-array as $stack arg + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +echo "\n-- Pass array as \$var argument --\n"; +$array = array(1, 2, 3); +$sub_array = array('one', 'two'); +var_dump(array_push($array, $sub_array)); +var_dump($array); + +echo "\n-- Pass sub-array as \$stack argument --\n"; +var_dump(array_push($array[3], 'a')); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Pass array as $var argument -- +int(4) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } +} + +-- Pass sub-array as $stack argument -- +int(3) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(1) "a" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_push_variation5.phpt b/ext/standard/tests/array/array_push_variation5.phpt new file mode 100644 index 0000000..4b6f399 --- /dev/null +++ b/ext/standard/tests/array/array_push_variation5.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_push() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Check the position of the internal array pointer after calling array_push() + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +$stack = array ('one' => 'un', 'two' => 'deux'); +$var0 = 'zero'; + +echo "\n-- Call array_push() --\n"; +var_dump($result = array_push($stack, $var0)); + +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($stack) . " => " . current ($stack) . "\n"; + +echo "Done"; +?> +--EXPECTF-- + +*** Testing array_push() : usage variations *** + +-- Call array_push() -- +int(3) + +-- Position of Internal Pointer in Original Array: -- +one => un +Done diff --git a/ext/standard/tests/array/array_push_variation6.phpt b/ext/standard/tests/array/array_push_variation6.phpt new file mode 100644 index 0000000..19afebb --- /dev/null +++ b/ext/standard/tests/array/array_push_variation6.phpt @@ -0,0 +1,159 @@ +--TEST-- +Test array_push() function : usage variations - array keys are different data types +--FILE-- +<?php +/* Prototype : int array_push(array $stack, mixed $var [, mixed $...]) + * Description: Pushes elements onto the end of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass array_push arrays where the keys are different data types. + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$var = 'value'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays of different data types as keys to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + + 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*3*/ 'null uppercase' => array( + NULL => 'null 1', + ), + 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*4*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*5*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*6*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*8*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*9*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each sub-array of $inputs to check the behavior of array_push() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + echo "Before : "; + var_dump(count($input)); + echo "After : "; + var_dump( array_push($input, $var) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Iteration 1 : int data -- +Before : int(4) +After : int(5) + +-- Iteration 2 : float data -- +Before : int(3) +After : int(4) + +-- Iteration 3 : extreme floats data -- +Before : int(2) +After : int(3) + +-- Iteration 4 : null uppercase data -- +Before : int(1) +After : int(2) + +-- Iteration 5 : null lowercase data -- +Before : int(1) +After : int(2) + +-- Iteration 6 : bool lowercase data -- +Before : int(2) +After : int(3) + +-- Iteration 7 : bool uppercase data -- +Before : int(2) +After : int(3) + +-- Iteration 8 : empty double quotes data -- +Before : int(1) +After : int(2) + +-- Iteration 9 : empty single quotes data -- +Before : int(1) +After : int(2) + +-- Iteration 10 : string data -- +Before : int(3) +After : int(4) + +-- Iteration 11 : undefined data -- +Before : int(1) +After : int(2) + +-- Iteration 12 : unset data -- +Before : int(1) +After : int(2) +Done diff --git a/ext/standard/tests/array/array_rand.phpt b/ext/standard/tests/array/array_rand.phpt new file mode 100644 index 0000000..1f495f4 --- /dev/null +++ b/ext/standard/tests/array/array_rand.phpt @@ -0,0 +1,51 @@ +--TEST-- +array_rand() tests +--FILE-- +<?php + +var_dump(array_rand()); +var_dump(array_rand(array())); +var_dump(array_rand(array(), 0)); +var_dump(array_rand(0, 0)); +var_dump(array_rand(array(1,2,3), 0)); +var_dump(array_rand(array(1,2,3), -1)); +var_dump(array_rand(array(1,2,3), 10)); +var_dump(array_rand(array(1,2,3), 3)); +var_dump(array_rand(array(1,2,3), 2)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_rand() expects at least 1 parameter, 0 given in %s on line %d +NULL +NULL + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +Warning: array_rand() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} +array(2) { + [0]=> + int(%d) + [1]=> + int(%d) +} +Done diff --git a/ext/standard/tests/array/array_rand_basic1.phpt b/ext/standard/tests/array/array_rand_basic1.phpt new file mode 100644 index 0000000..30b5b5c --- /dev/null +++ b/ext/standard/tests/array/array_rand_basic1.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_rand() function : basic functionality - array with default keys +--FILE-- +<?php +/* Prototype : mixed array_rand(array $input [, int $num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* + * Test array_rand() when array with default keys is passed to 'input' argument +*/ + +echo "*** Testing array_rand() : array with default keys ***\n"; + + +// Initialise the 'input' and 'num_req' variables +$input = array(10, 20, 30, 40, 50, 60, 70); +$num_req = 6; + +// Calling array_rand() with optional argument +echo"\n-- with all default and optional arguments --\n"; +var_dump( array_rand($input,$num_req) ); + +// Calling array_rand() with default arguments +echo"\n-- with default argument --\n"; +var_dump( array_rand($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : array with default keys *** + +-- with all default and optional arguments -- +array(%d) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) +} + +-- with default argument -- +int(%d) +Done + diff --git a/ext/standard/tests/array/array_rand_basic2.phpt b/ext/standard/tests/array/array_rand_basic2.phpt new file mode 100644 index 0000000..e18fede --- /dev/null +++ b/ext/standard/tests/array/array_rand_basic2.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_rand() function : basic functionality - with associative array for 'input' argument +--FILE-- +<?php +/* Prototype : mixed array_rand(array $input [, int $num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* + * Test array_rand() when associative array is passed to 'input' argument +*/ + +echo "*** Testing array_rand() : with associative array ***\n"; + + +// Initialise the 'input' and 'num_req' variables +$input = array( + 'one' => 1, 'two' => 2, 'three' => 3, + 'FoUr' => 'four', '#5' => 5, 'SIX' => 'six', + "seven" => 7, "#8" => "eight", "nine" => "NINE" +); + +$num_req = 6; + +// Calling array_rand() with optional argument +echo"\n-- with all default and optional arguments --\n"; +var_dump( array_rand($input,$num_req) ); + +// Calling array_rand() with default arguments +echo"\n-- with default argument --\n"; +var_dump( array_rand($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : with associative array *** + +-- with all default and optional arguments -- +array(6) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" + [4]=> + string(%d) "%s" + [5]=> + string(%d) "%s" +} + +-- with default argument -- +string(%d) "%s" +Done + diff --git a/ext/standard/tests/array/array_rand_error.phpt b/ext/standard/tests/array/array_rand_error.phpt new file mode 100644 index 0000000..30cc85a --- /dev/null +++ b/ext/standard/tests/array/array_rand_error.phpt @@ -0,0 +1,38 @@ +--TEST-- +Test array_rand() function : error conditions +--FILE-- +<?php +/* Prototype : mixed array_rand(array input [, int num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_rand() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_rand() function with Zero arguments --\n"; +var_dump( array_rand() ); + +//Test array_rand with one more than the expected number of arguments +echo "\n-- Testing array_rand() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$num_req = 10; +$extra_arg = 10; +var_dump( array_rand($input,$num_req, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : error conditions *** + +-- Testing array_rand() function with Zero arguments -- + +Warning: array_rand() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing array_rand() function with more than expected no. of arguments -- + +Warning: array_rand() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/array_rand_variation1.phpt b/ext/standard/tests/array/array_rand_variation1.phpt new file mode 100644 index 0000000..e215829 --- /dev/null +++ b/ext/standard/tests/array/array_rand_variation1.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test array_rand() function : usage variations - unexpected values for 'input' parameter +--FILE-- +<?php +/* Prototype : mixed array_rand(array input [, int num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* +* Test array_rand() with different types of values other than arrays passed to the 'input' parameter +* to see that function works with unexpeced data and generates warning message as required. +*/ + +echo "*** Testing array_rand() : unexpected values for 'input' parameter ***\n"; + +// Initialise function arguments +$num_req = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "object"; + } +} + +//array of different values for 'input' parameter +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new test(), + + // resource data +/*21*/ $fp, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +/* loop through each element of the array to test array_rand() function + * for different values for 'input' argument +*/ +$count = 1; +foreach($values as $value) { + echo "\n-- Iteration $count --\n"; + var_dump( array_rand($value,$num_req) ); + $count++; +}; + +// closing the resource +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : unexpected values for 'input' parameter *** + +-- Iteration 1 -- + +Warning: array_rand() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_rand() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_rand() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_rand() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_rand() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_rand() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_rand() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_rand() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_rand() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_rand() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_rand() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_rand() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_rand() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_rand() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_rand() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_rand() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_rand() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_rand() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_rand() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_rand() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_rand() expects parameter 1 to be array, resource given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_rand() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_rand() expects parameter 1 to be array, null given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/array_rand_variation2.phpt b/ext/standard/tests/array/array_rand_variation2.phpt new file mode 100644 index 0000000..3340a12 --- /dev/null +++ b/ext/standard/tests/array/array_rand_variation2.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test array_rand() function : usage variations - unexpected values for 'num_req' parameter +--FILE-- +<?php +/* Prototype : mixed array_rand(array input [, int num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* +* Test array_rand() with different types of values other than int passed to 'num_req' argument +* to see that function works with unexpeced data and generates warning message as required. +*/ + +echo "*** Testing array_rand() : unexpected values for 'num_req' parameter ***\n"; + +// Initialise function arguments +$input = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "3object"; + } +} + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new test(), + + // undefined data +/*21*/ @$undefined_var, + + // unset data +/*22*/ @$unset_var, +); + + +// loop through each element of the array for different values for 'num_req' argument +$count = 1; +foreach($values as $value) { + echo "\n-- Iteration $count --\n"; + var_dump( array_rand($input,$value) ); + $count++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : unexpected values for 'num_req' parameter *** + +-- Iteration 1 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 2 -- +int(%d) + +-- Iteration 3 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 5 -- +array(10) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) + [9]=> + int(%d) +} + +-- Iteration 6 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 12 -- +int(%d) + +-- Iteration 13 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 14 -- +int(%d) + +-- Iteration 15 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_rand() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_rand() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_rand() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_rand() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_rand() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/array_rand_variation3.phpt b/ext/standard/tests/array/array_rand_variation3.phpt new file mode 100644 index 0000000..81194a1 --- /dev/null +++ b/ext/standard/tests/array/array_rand_variation3.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test array_rand() function : usage variation - with MultiDimensional array +--FILE-- +<?php +/* Prototype : mixed array_rand(array $input [, int $num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of array_rand() function when multi-dimensional array +* is passed to 'input' argument +*/ + +echo "*** Testing array_rand() : with multi-dimensional array ***\n"; + +// initialise the multi-dimensional array +$input = array( + // array with int values +/*1*/ array(1, 2, 0, -0, -1, -2), + + // array with float values + array(1.23, -1.23, 0.34, -0.34, 0e2, 2e-3, -2e2, -40e-2), + + // array with single quoted strings +/*3*/ array('one', '123numbers', 'hello\tworld', 'hello world\0', '12.34floatnum'), + + // array with double quoted strings + array("one","123numbers", "hello\tworld", "hello world\0", "12.34floatnum"), + + // array with bool values +/*5*/ array(true, TRUE, FALSE, false, TrUe, FaLsE), + + // array with hexa values + array(0x123, -0x123, 0xabc, 0xABC, 0xab), + + // array with null values +/*7*/ array(null, NULL, "\0", Null, NuLl) + +); + +// initialise 'num_req' variable +$num_req = 3; + +// calling array_rand() function with multi-dimensional array +var_dump( array_rand($input, $num_req) ); + +// looping to test array_rand() with each sub-array in the multi-dimensional array +echo "\n*** Testing array_rand() with arrays having different types of values ***\n"; +$counter = 1; +foreach($input as $arr) { + echo "\n-- Iteration $counter --\n"; + var_dump( array_rand($arr) ); // with default arguments + var_dump( array_rand($arr, 3) ); // with default as well as optional arguments + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : with multi-dimensional array *** +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +*** Testing array_rand() with arrays having different types of values *** + +-- Iteration 1 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 2 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 3 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 4 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 5 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 6 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 7 -- +int(%d) +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} +Done + diff --git a/ext/standard/tests/array/array_rand_variation4.phpt b/ext/standard/tests/array/array_rand_variation4.phpt new file mode 100644 index 0000000..72b6c55 --- /dev/null +++ b/ext/standard/tests/array/array_rand_variation4.phpt @@ -0,0 +1,168 @@ +--TEST-- +Test array_rand() function : usage variation - with associative arrays for 'input' parameter +--FILE-- +<?php +/* Prototype : mixed array_rand(array $input [, int $num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of array_rand() function when associative array is passed to +* the 'input' parameter in the function call +*/ + +echo "*** Testing array_rand() : with associative arrays ***\n"; + +// initialise associative arrays +$asso_arrays = array( + + // array with numeric keys +/*1*/ array(1 => 'one', 2 => 2, 1234567890 => 'big', -1 => 'negative key', + 2.3 => 'float key', 0 => "zero key", 0.2 => 'decimal key', + 2e2 => 'exp key1', -2e3 => 'negative exp key'), + + // array with string keys + array('one' => 1, "two" => 2.0, "three" => 'three', + '12twelve' => 12.00, "" => 'empty string', " " => "space key"), + + // array with hexa values as keys +/*3*/ array(0xabc => 2748, 0x12f => '303', 0xff => "255", -0xff => "-255"), + + // array with octal values as keys + array(0123 => 83, 0129 => 10, 010 => "8", -0348 => "-28", 0012 => '10'), + + // array with bool values as keys + array(TRUE => '1', true => true, TrUe => "TRUE", + FALSE => '0', false => false, FaLsE => "FALSE"), + + // array with special chars as keys +/*6*/ array('##' => "key1", '&$r' => 'key2', '!' => "key3", '<>' =>'key4', + "NULL" => 'key5', "\n" => 'newline as key', + "\t" => "tab as key", "'" => 'single quote as key', + '"' => 'double quote as key', "\0" => "null char as key") +); + +/* looping to test array_rand() function with different arrays having + * different types of keys +*/ +$counter = 1; +foreach($asso_arrays as $input) { + echo "\n-- Iteration $counter --\n"; + + // with default argument + echo"\nWith default argument\n"; + var_dump( array_rand($input) ); + + // with default and optional arguments + echo"\nWith num_req = 1\n"; + var_dump( array_rand($input, 1) ); // with $num_req=1 + echo"\nWith num_req = 2\n"; + var_dump( array_rand($input, 2) ); // with $num_req=2 + + $counter++; +} // end of for loop + + +echo "Done"; +?> +--EXPECTREGEX-- +\*\*\* Testing array_rand\(\) : with associative arrays \*\*\* + +-- Iteration 1 -- + +With default argument +int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) + +With num_req = 1 +int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) + \[1\]=> + int\([012-][12.e]*[23e]*[34]*[5]*[6]*[7]*[8]*[9]*[0]*\) +} + +-- Iteration 2 -- + +With default argument +string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" + +With num_req = 1 +string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" + +With num_req = 2 +array\(2\) { + \[0\]=> + string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" + \[1\]=> + string\([0-9]*\) "[ot1 ]*[hnw2]*[eort]*[ew]*[e]*[l]*[v]*[e]*" +} + +-- Iteration 3 -- + +With default argument +int\([23-]*[2570]*[345]*[58]*\) + +With num_req = 1 +int\([23-]*[2570]*[345]*[58]*\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([23-]*[2570]*[345]*[58]*\) + \[1\]=> + int\([23-]*[2570]*[345]*[58]*\) +} + +-- Iteration 4 -- + +With default argument +int\([18-]*[023]*[8]*\) + +With num_req = 1 +int\([18-]*[023]*[8]*\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([18-]*[023]*[8]*\) + \[1\]=> + int\([18-]*[023]*[8]*\) +} + +-- Iteration 5 -- + +With default argument +int\([01]\) + +With num_req = 1 +int\([01]\) + +With num_req = 2 +array\(2\) { + \[0\]=> + int\([01]\) + \[1\]=> + int\([01]\) +} + +-- Iteration 6 -- + +With default argument +string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" + +With num_req = 1 +string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" + +With num_req = 2 +array\(2\) { + \[0\]=> + string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" + \[1\]=> + string\([0-9]*\) "[#&!N <\n\t'"\0]*[U#$>]*[rL]*[L]*" +} +Done + diff --git a/ext/standard/tests/array/array_rand_variation5.phpt b/ext/standard/tests/array/array_rand_variation5.phpt new file mode 100644 index 0000000..69dded9 --- /dev/null +++ b/ext/standard/tests/array/array_rand_variation5.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test array_rand() function : usage variation - invalid values for 'req_num' parameter +--FILE-- +<?php +/* Prototype : mixed array_rand(array $input [, int $num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of array_rand() function when associative array and +* various invalid values are passed to the 'input' and 'req_num' +* parameters respectively +*/ + +echo "*** Testing array_rand() : with invalid values for 'req_num' ***\n"; + +// initialise associative arrays +$input = array( + 1 => 'one', 2.2 => 'float key', 0.9 => 'decimal key', + 2e2 => 'exp key1', 2000e-3 => 'negative exp key', + 0xabc => 2748, 0x12f => '303', 0xff => "255", + 0123 => 83, 0129 => 10, 010 => "8" +); + +// Testing array_rand() function with various invalid 'req_num' values +// with valid num_req values +echo"\n-- With default num_req value --\n"; +var_dump( array_rand($input) ); // with default $num_req value +echo"\n-- With num_req = 1 --\n"; +var_dump( array_rand($input, 1) ); // with valid $num_req value + +// with invalid num_req value +echo"\n-- With num_req = 0 --\n"; +var_dump( array_rand($input, 0) ); // with $num_req=0 +echo"\n-- With num_req = -1 --\n"; +var_dump( array_rand($input, -1) ); // with $num_req=-1 +echo"\n-- With num_req = -2 --\n"; +var_dump( array_rand($input, -2) ); // with $num_req=-2 +echo"\n-- With num_req more than number of members in 'input' array --\n"; +var_dump( array_rand($input, 13) ); // with $num_req=13 + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_rand() : with invalid values for 'req_num' *** + +-- With default num_req value -- +int(%d) + +-- With num_req = 1 -- +int(%d) + +-- With num_req = 0 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- With num_req = -1 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- With num_req = -2 -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL + +-- With num_req more than number of members in 'input' array -- + +Warning: array_rand(): Second argument has to be between 1 and the number of elements in the array in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/array_rand_variation6.phpt b/ext/standard/tests/array/array_rand_variation6.phpt new file mode 100644 index 0000000..3f1fea2 --- /dev/null +++ b/ext/standard/tests/array/array_rand_variation6.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test array_rand() function : usage variation - with heredoc string as key in the 'input' array +--FILE-- +<?php +/* Prototype : mixed array_rand(array $input [, int $num_req]) + * Description: Return key/keys for random entry/entries in the array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of array_rand() when keys of the 'input' array is heredoc string +*/ + +echo "*** Testing array_rand() : with keys of input array as heredoc strings ***\n"; + +// defining different heredoc strings +$empty_heredoc = <<<EOT +EOT; + +$heredoc_with_newline = <<<EOT +\n +EOT; + +$heredoc_with_characters = <<<EOT +first line of heredoc string +second line of heredoc string +third line of heredocstring +EOT; + +$heredoc_with_newline_and_tabs = <<<EOT +hello\tworld\nhello\nworld\n +EOT; + +$heredoc_with_alphanumerics = <<<EOT +hello123world456 +1234hello\t1234 +EOT; + +$heredoc_with_embedded_nulls = <<<EOT +hello\0world\0hello +\0hello\0 +EOT; + +$input = array( + $empty_heredoc => "heredoc1", + $heredoc_with_newline => "heredoc2", + $heredoc_with_characters => "heredoc3", + $heredoc_with_newline_and_tabs => "heredoc3", + $heredoc_with_alphanumerics => "heredoc4", + $heredoc_with_embedded_nulls => "heredoc5" +); + +// Test array_rand() function with different valid 'req_num' values +echo "\n-- with default parameters --\n"; +var_dump( array_rand($input) ); + +echo "\n-- with num_req = 1 --\n"; +var_dump( array_rand($input, 1) ); + +echo "\n-- with num_req = 3 --\n"; +var_dump( array_rand($input, 3) ); + +echo "\n-- with num_req = 6 --\n"; +var_dump( array_rand($input, 6) ); + + +echo "Done"; +?> +--EXPECTREGEX-- +\*\*\* Testing array_rand\(\) : with keys of input array as heredoc strings \*\*\* + +-- with default parameters -- +string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + +-- with num_req = 1 -- +string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + +-- with num_req = 3 -- +array\(3\) { + \[0\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[1\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[2\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" +} + +-- with num_req = 6 -- +array\(6\) { + \[0\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[1\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[2\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[3\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[4\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" + \[5\]=> + string\([0-9]*\) "[a-z \n \t \0 0-9 ]*" +} +Done + diff --git a/ext/standard/tests/array/array_reduce.phpt b/ext/standard/tests/array/array_reduce.phpt new file mode 100644 index 0000000..94ecca6 --- /dev/null +++ b/ext/standard/tests/array/array_reduce.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test array_reduce() function +--INI-- +precision=14 +--FILE-- +<?php +/* Prototype: array array_reduce(array $array, mixed $callback, mixed $initial); + Description: Iteratively reduce the array to a single value via the callback +*/ + +$array = array('foo', 'foo', 'bar', 'qux', 'qux', 'quux'); + +echo "\n*** Testing array_reduce() to integer ***\n"; +function reduce_int($w, $v) { return $w + strlen($v); } +$initial = 42; +var_dump(array_reduce($array, 'reduce_int', $initial), $initial); + +echo "\n*** Testing array_reduce() to float ***\n"; +function reduce_float($w, $v) { return $w + strlen($v) / 10; } +$initial = 4.2; +var_dump(array_reduce($array, 'reduce_float', $initial), $initial); + +echo "\n*** Testing array_reduce() to string ***\n"; +function reduce_string($w, $v) { return $w . $v; } +$initial = 'quux'; +var_dump(array_reduce($array, 'reduce_string', $initial), $initial); + +echo "\n*** Testing array_reduce() to array ***\n"; +function reduce_array($w, $v) { $w[$v]++; return $w; } +$initial = array('foo' => 42, 'bar' => 17, 'qux' => -2, 'quux' => 0); +var_dump(array_reduce($array, 'reduce_array', $initial), $initial); + +echo "\n*** Testing array_reduce() to null ***\n"; +function reduce_null($w, $v) { return $w . $v; } +$initial = null; +var_dump(array_reduce($array, 'reduce_null', $initial), $initial); + +echo "\nDone"; +?> +--EXPECTF-- +*** Testing array_reduce() to integer *** +int(61) +int(42) + +*** Testing array_reduce() to float *** +float(6.1) +float(4.2) + +*** Testing array_reduce() to string *** +string(23) "quuxfoofoobarquxquxquux" +string(4) "quux" + +*** Testing array_reduce() to array *** +array(4) { + ["foo"]=> + int(44) + ["bar"]=> + int(18) + ["qux"]=> + int(0) + ["quux"]=> + int(1) +} +array(4) { + ["foo"]=> + int(42) + ["bar"]=> + int(17) + ["qux"]=> + int(-2) + ["quux"]=> + int(0) +} + +*** Testing array_reduce() to null *** +string(19) "foofoobarquxquxquux" +NULL + +Done diff --git a/ext/standard/tests/array/array_reduce_error.phpt b/ext/standard/tests/array/array_reduce_error.phpt new file mode 100644 index 0000000..954aa43 --- /dev/null +++ b/ext/standard/tests/array/array_reduce_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_reduce() function : error conditions +--FILE-- +<?php +/* Prototype : mixed array_reduce(array input, mixed callback [, int initial]) + * Description: Iteratively reduce the array to a single value via the callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_reduce() : error conditions ***\n"; + + +//Test array_reduce with one more than the expected number of arguments +echo "\n-- Testing array_reduce() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$callback = 1; +$initial = 10; +$extra_arg = 10; +var_dump( array_reduce($input, $callback, $initial, $extra_arg) ); + +// Testing array_reduce with one less than the expected number of arguments +echo "\n-- Testing array_reduce() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +var_dump( array_reduce($input) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_reduce() : error conditions *** + +-- Testing array_reduce() function with more than expected no. of arguments -- + +Warning: array_reduce() expects at most 3 parameters, 4 given in %sarray_reduce_error.php on line %d +NULL + +-- Testing array_reduce() function with less than expected no. of arguments -- + +Warning: array_reduce() expects at least 2 parameters, 1 given in %sarray_reduce_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_reduce_variation1.phpt b/ext/standard/tests/array/array_reduce_variation1.phpt new file mode 100644 index 0000000..b02a82a --- /dev/null +++ b/ext/standard/tests/array/array_reduce_variation1.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_reduce() function : variation +--FILE-- +<?php +/* Prototype : mixed array_reduce(array input, mixed callback [, int initial]) + * Description: Iteratively reduce the array to a single value via the callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_reduce() : variation ***\n"; + + +function oneArg($v) { + return $v; +} + +function threeArgs($v, $w, $x) { + return $v + $w + $x; +} + +$array = array(1); + +echo "\n--- Testing with a callback with too few parameters ---\n"; +var_dump(array_reduce($array, "oneArg", 2)); + +echo "\n--- Testing with a callback with too many parameters ---\n"; +var_dump(array_reduce($array, "threeArgs", 2)); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_reduce() : variation *** + +--- Testing with a callback with too few parameters --- +int(2) + +--- Testing with a callback with too many parameters --- + +Warning: Missing argument 3 for threeArgs() in %sarray_reduce_variation1.php on line %d + +Notice: Undefined variable: x in %sarray_reduce_variation1.php on line %d +int(3) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_reduce_variation2.phpt b/ext/standard/tests/array/array_reduce_variation2.phpt new file mode 100644 index 0000000..35b2d38 --- /dev/null +++ b/ext/standard/tests/array/array_reduce_variation2.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test array_reduce() function : variation - invalid parameters +--FILE-- +<?php +/* Prototype : mixed array_reduce(array input, mixed callback [, int initial]) + * Description: Iteratively reduce the array to a single value via the callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_reduce() : variation - invalid parameters ***\n"; + + +$array = array(1); + +var_dump(array_reduce($array, "bogusbogus")); + +var_dump(array_reduce("bogusarray", "max")); + +var_dump(array_reduce(new stdClass(), "max")); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_reduce() : variation - invalid parameters *** + +Warning: array_reduce() expects parameter 2 to be a valid callback, function 'bogusbogus' not found or invalid function name in %sarray_reduce_variation2.php on line %d +NULL + +Warning: array_reduce() expects parameter 1 to be array, string given in %sarray_reduce_variation2.php on line %d +NULL + +Warning: array_reduce() expects parameter 1 to be array, object given in %sarray_reduce_variation2.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_reduce_variation3.phpt b/ext/standard/tests/array/array_reduce_variation3.phpt new file mode 100644 index 0000000..f630102 --- /dev/null +++ b/ext/standard/tests/array/array_reduce_variation3.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_reduce() function : variation - object callbacks +--FILE-- +<?php +/* Prototype : mixed array_reduce(array input, mixed callback [, int initial]) + * Description: Iteratively reduce the array to a single value via the callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_reduce() : variation - object callbacks ***\n"; + +class A { + static function adder($a, $b) {return $a + $b;} + public function adder2($a, $b) {return $a + $b;} +} + +$array = array(1); + +echo "\n--- Static method callback ---\n"; +var_dump(array_reduce($array, array("A", "adder"))); + +echo "\n--- Instance method callback ---\n"; +var_dump(array_reduce($array, array(new A(), "adder2"))); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_reduce() : variation - object callbacks *** + +--- Static method callback --- +int(1) + +--- Instance method callback --- +int(1) +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_replace.phpt b/ext/standard/tests/array/array_replace.phpt new file mode 100644 index 0000000..6ba9e43 --- /dev/null +++ b/ext/standard/tests/array/array_replace.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test array_replace and array_replace_recursive +--FILE-- +<?php + +$array1 = array( + 0 => 'dontclobber', + '1' => 'unclobbered', + 'test2' => 0.0, + 'test3' => array( + 'testarray2' => true, + 1 => array( + 'testsubarray1' => 'dontclobber2', + 'testsubarray2' => 'dontclobber3', + ), + ), +); + +$array2 = array( + 1 => 'clobbered', + 'test3' => array( + 'testarray2' => false, + ), + 'test4' => array( + 'clobbered3' => array(0, 1, 2), + ), +); + +$array3 = array(array(array(array()))); + +$array4 = array(); +$array4[] = &$array4; + +echo " -- Testing array_replace() --\n"; +$data = array_replace($array1, $array2); + +var_dump($data); + +echo " -- Testing array_replace_recursive() --\n"; +$data = array_replace_recursive($array1, $array2); + +var_dump($data); + +echo " -- Testing array_replace_recursive() w/ endless recusrsion --\n"; +$data = array_replace_recursive($array3, $array4); + +var_dump($data); +?> +--EXPECTF-- + -- Testing array_replace() -- +array(5) { + [0]=> + string(11) "dontclobber" + [1]=> + string(9) "clobbered" + ["test2"]=> + float(0) + ["test3"]=> + array(1) { + ["testarray2"]=> + bool(false) + } + ["test4"]=> + array(1) { + ["clobbered3"]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + } +} + -- Testing array_replace_recursive() -- +array(5) { + [0]=> + string(11) "dontclobber" + [1]=> + string(9) "clobbered" + ["test2"]=> + float(0) + ["test3"]=> + array(2) { + ["testarray2"]=> + bool(false) + [1]=> + array(2) { + ["testsubarray1"]=> + string(12) "dontclobber2" + ["testsubarray2"]=> + string(12) "dontclobber3" + } + } + ["test4"]=> + array(1) { + ["clobbered3"]=> + array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + } + } +} + -- Testing array_replace_recursive() w/ endless recusrsion -- + +Warning: array_replace_recursive(): recursion detected in %s on line %d +array(1) { + [0]=> + array(1) { + [0]=> + array(1) { + [0]=> + array(0) { + } + } + } +} diff --git a/ext/standard/tests/array/array_reverse_basic1.phpt b/ext/standard/tests/array/array_reverse_basic1.phpt new file mode 100644 index 0000000..f41e0a3 --- /dev/null +++ b/ext/standard/tests/array/array_reverse_basic1.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_reverse() function : basic functionality - simple array for 'array' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_reverse() by giving a simple array for $array argument +*/ + +echo "*** Testing array_reverse() : basic functionality ***\n"; + +// Initialise the array +$array = array("a", "green", "red", 'blue', 10, 13.33); + +// Calling array_reverse() with default arguments +var_dump( array_reverse($array) ); + +// Calling array_reverse() with all possible arguments +var_dump( array_reverse($array, true) ); // expects the keys to be preserved +var_dump( array_reverse($array, false) ); // expects the keys not to be preserved + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : basic functionality *** +array(6) { + [0]=> + float(13.33) + [1]=> + int(10) + [2]=> + string(4) "blue" + [3]=> + string(3) "red" + [4]=> + string(5) "green" + [5]=> + string(1) "a" +} +array(6) { + [5]=> + float(13.33) + [4]=> + int(10) + [3]=> + string(4) "blue" + [2]=> + string(3) "red" + [1]=> + string(5) "green" + [0]=> + string(1) "a" +} +array(6) { + [0]=> + float(13.33) + [1]=> + int(10) + [2]=> + string(4) "blue" + [3]=> + string(3) "red" + [4]=> + string(5) "green" + [5]=> + string(1) "a" +} +Done diff --git a/ext/standard/tests/array/array_reverse_basic2.phpt b/ext/standard/tests/array/array_reverse_basic2.phpt new file mode 100644 index 0000000..9f41f0b --- /dev/null +++ b/ext/standard/tests/array/array_reverse_basic2.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_reverse() function : basic functionality - associative array for 'array' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_reverse() with associative array for $array argument +*/ + +echo "*** Testing array_reverse() : basic functionality ***\n"; + +// Initialise the array +$array = array("a" => "hello", 123 => "number", 'string' => 'blue', "10" => 13.33); + +// Calling array_reverse() with default arguments +var_dump( array_reverse($array) ); + +// Calling array_reverse() with all possible arguments +var_dump( array_reverse($array, true) ); // expects the keys to be preserved +var_dump( array_reverse($array, false) ); // expects the keys not to be preserved + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : basic functionality *** +array(4) { + [0]=> + float(13.33) + ["string"]=> + string(4) "blue" + [1]=> + string(6) "number" + ["a"]=> + string(5) "hello" +} +array(4) { + [10]=> + float(13.33) + ["string"]=> + string(4) "blue" + [123]=> + string(6) "number" + ["a"]=> + string(5) "hello" +} +array(4) { + [0]=> + float(13.33) + ["string"]=> + string(4) "blue" + [1]=> + string(6) "number" + ["a"]=> + string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_reverse_error.phpt b/ext/standard/tests/array/array_reverse_error.phpt new file mode 100644 index 0000000..faf7e82 --- /dev/null +++ b/ext/standard/tests/array/array_reverse_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_reverse() function : error conditions +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_reverse() : error conditions ***\n"; + +// zero arguments +echo "\n-- Testing array_reverse() function with Zero arguments --\n"; +var_dump( array_reverse() ); + +// more than the expected number of arguments +echo "\n-- Testing array_diff() function with more than expected no. of arguments --\n"; +$array = array(1, 2, 3, 4, 5, 6); +$extra_arg = 10; +var_dump( array_reverse($array, true, $extra_arg) ); +var_dump( array_reverse($array, false, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : error conditions *** + +-- Testing array_reverse() function with Zero arguments -- + +Warning: array_reverse() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing array_diff() function with more than expected no. of arguments -- + +Warning: array_reverse() expects at most 2 parameters, 3 given in %s on line %d +NULL + +Warning: array_reverse() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_reverse_variation1.phpt b/ext/standard/tests/array/array_reverse_variation1.phpt new file mode 100644 index 0000000..35a73bb --- /dev/null +++ b/ext/standard/tests/array/array_reverse_variation1.phpt @@ -0,0 +1,340 @@ +--TEST-- +Test array_reverse() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_reverse() : usage variations - unexpected values for 'array' argument ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +//get a heredoc string +$heredoc_string = <<<EOT +Hello world\t\n +EOT; + +//array of values to iterate over +$arrays = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data + 'Hello world', + "Hello world", + $heredoc_string, + + // object data +/*21*/ new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable +/*24*/ $fp + +); + +// loop through each element of the array $arrays to check the behavior of array_reverse() +$iterator = 1; +foreach($arrays as $array) { + echo "\n-- Iteration $iterator --"; + // with default argument + var_dump( array_reverse($array) ); + // with all possible arguments + var_dump( array_reverse($array, true) ); + var_dump( array_reverse($array, false) ); + $iterator++; +}; + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations - unexpected values for 'array' argument *** + +-- Iteration 1 -- +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_reverse() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_reverse() expects parameter 1 to be array, resource given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, resource given in %s on line %d +NULL + +Warning: array_reverse() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_reverse_variation2.phpt b/ext/standard/tests/array/array_reverse_variation2.phpt new file mode 100644 index 0000000..69e7a9f --- /dev/null +++ b/ext/standard/tests/array/array_reverse_variation2.phpt @@ -0,0 +1,414 @@ +--TEST-- +Test array_reverse() function : usage variations - unexpected values for 'preserve_keys' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * testing the functionality of array_reverse() by giving unexpected values for $preserve_keys argument +*/ + +echo "*** Testing array_reverse() : usage variations ***\n"; + +// Initialise the array +$array = array("a" => "green", "red", "blue", "red", "orange", "pink"); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +//array of values to iterate over +$preserve_keys = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data + true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ + "", + '', + + // object data + new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable +/*26*/ $fp + +); + +// loop through each element of the array $preserve_keys to check the behavior of array_reverse() +$iterator = 1; +foreach($preserve_keys as $preserve_key) { + echo "-- Iteration $iterator --\n"; + var_dump( array_reverse($array, $preserve_key) ); + $iterator++; +}; + +// close the file resouce used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** +-- Iteration 1 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 2 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 3 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 4 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 5 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 6 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 7 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 8 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 9 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 10 -- + +Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_reverse() expects parameter 2 to be boolean, array given in %s on line %d +NULL +-- Iteration 15 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 16 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 17 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 18 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 19 -- +array(6) { + [4]=> + string(4) "pink" + [3]=> + string(6) "orange" + [2]=> + string(3) "red" + [1]=> + string(4) "blue" + [0]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 20 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 21 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 22 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 23 -- + +Warning: array_reverse() expects parameter 2 to be boolean, object given in %s on line %d +NULL +-- Iteration 24 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 25 -- +array(6) { + [0]=> + string(4) "pink" + [1]=> + string(6) "orange" + [2]=> + string(3) "red" + [3]=> + string(4) "blue" + [4]=> + string(3) "red" + ["a"]=> + string(5) "green" +} +-- Iteration 26 -- + +Warning: array_reverse() expects parameter 2 to be boolean, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_reverse_variation3.phpt b/ext/standard/tests/array/array_reverse_variation3.phpt new file mode 100644 index 0000000..1029842 --- /dev/null +++ b/ext/standard/tests/array/array_reverse_variation3.phpt @@ -0,0 +1,602 @@ +--TEST-- +Test array_reverse() function : usage variations - different array values for 'array' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_reverse() by giving + * different array values for $array argument +*/ + +echo "*** Testing array_reverse() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array( array(2), array(1)), // sub arrays + array(false,true), // array with default keys and boolean values + array(), // empty array + array(NULL), // array with NULL + array("a","aaaa","b","bbbb","c","ccccc"), + + // associative arrays +/*8*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_reverse() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + // with default argument + echo "- with default argument -\n"; + var_dump( array_reverse($array) ); + // with all possible arguments + echo "- with \$preserve keys = true -\n"; + var_dump( array_reverse($array, true) ); + echo "- with \$preserve_keys = false -\n"; + var_dump( array_reverse($array, false) ); + $iterator++; +}; + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** +-- Iteration 1 -- +- with default argument - +array(2) { + [0]=> + int(2) + [1]=> + int(1) +} +- with $preserve keys = true - +array(2) { + [1]=> + int(2) + [0]=> + int(1) +} +- with $preserve_keys = false - +array(2) { + [0]=> + int(2) + [1]=> + int(1) +} +-- Iteration 2 -- +- with default argument - +array(2) { + [0]=> + float(2.2) + [1]=> + float(1.1) +} +- with $preserve keys = true - +array(2) { + [1]=> + float(2.2) + [0]=> + float(1.1) +} +- with $preserve_keys = false - +array(2) { + [0]=> + float(2.2) + [1]=> + float(1.1) +} +-- Iteration 3 -- +- with default argument - +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +- with $preserve keys = true - +array(2) { + [1]=> + array(1) { + [0]=> + int(1) + } + [0]=> + array(1) { + [0]=> + int(2) + } +} +- with $preserve_keys = false - +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +-- Iteration 4 -- +- with default argument - +array(2) { + [0]=> + bool(true) + [1]=> + bool(false) +} +- with $preserve keys = true - +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} +- with $preserve_keys = false - +array(2) { + [0]=> + bool(true) + [1]=> + bool(false) +} +-- Iteration 5 -- +- with default argument - +array(0) { +} +- with $preserve keys = true - +array(0) { +} +- with $preserve_keys = false - +array(0) { +} +-- Iteration 6 -- +- with default argument - +array(1) { + [0]=> + NULL +} +- with $preserve keys = true - +array(1) { + [0]=> + NULL +} +- with $preserve_keys = false - +array(1) { + [0]=> + NULL +} +-- Iteration 7 -- +- with default argument - +array(6) { + [0]=> + string(5) "ccccc" + [1]=> + string(1) "c" + [2]=> + string(4) "bbbb" + [3]=> + string(1) "b" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "a" +} +- with $preserve keys = true - +array(6) { + [5]=> + string(5) "ccccc" + [4]=> + string(1) "c" + [3]=> + string(4) "bbbb" + [2]=> + string(1) "b" + [1]=> + string(4) "aaaa" + [0]=> + string(1) "a" +} +- with $preserve_keys = false - +array(6) { + [0]=> + string(5) "ccccc" + [1]=> + string(1) "c" + [2]=> + string(4) "bbbb" + [3]=> + string(1) "b" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "a" +} +-- Iteration 8 -- +- with default argument - +array(3) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" +} +- with $preserve keys = true - +array(3) { + [3]=> + string(5) "three" + [2]=> + string(3) "two" + [1]=> + string(3) "one" +} +- with $preserve_keys = false - +array(3) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" +} +-- Iteration 9 -- +- with default argument - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- with $preserve keys = true - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- with $preserve_keys = false - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +-- Iteration 10 -- +- with default argument - +array(4) { + [0]=> + int(30) + [1]=> + int(40) + [2]=> + int(20) + [3]=> + int(10) +} +- with $preserve keys = true - +array(4) { + [3]=> + int(30) + [4]=> + int(40) + [2]=> + int(20) + [1]=> + int(10) +} +- with $preserve_keys = false - +array(4) { + [0]=> + int(30) + [1]=> + int(40) + [2]=> + int(20) + [3]=> + int(10) +} +-- Iteration 11 -- +- with default argument - +array(3) { + ["three"]=> + string(6) "thirty" + ["two"]=> + string(6) "twenty" + ["one"]=> + string(3) "ten" +} +- with $preserve keys = true - +array(3) { + ["three"]=> + string(6) "thirty" + ["two"]=> + string(6) "twenty" + ["one"]=> + string(3) "ten" +} +- with $preserve_keys = false - +array(3) { + ["three"]=> + string(6) "thirty" + ["two"]=> + string(6) "twenty" + ["one"]=> + string(3) "ten" +} +-- Iteration 12 -- +- with default argument - +array(3) { + [0]=> + string(4) "four" + [1]=> + string(3) "two" + ["one"]=> + int(1) +} +- with $preserve keys = true - +array(3) { + [4]=> + string(4) "four" + [2]=> + string(3) "two" + ["one"]=> + int(1) +} +- with $preserve_keys = false - +array(3) { + [0]=> + string(4) "four" + [1]=> + string(3) "two" + ["one"]=> + int(1) +} +-- Iteration 13 -- +- with default argument - +array(3) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [""]=> + string(4) "null" +} +- with $preserve keys = true - +array(3) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [""]=> + string(4) "null" +} +- with $preserve_keys = false - +array(3) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [""]=> + string(4) "null" +} +-- Iteration 14 -- +- with default argument - +array(4) { + ["true"]=> + bool(true) + ["false"]=> + bool(false) + [0]=> + string(5) "false" + [1]=> + string(4) "true" +} +- with $preserve keys = true - +array(4) { + ["true"]=> + bool(true) + ["false"]=> + bool(false) + [0]=> + string(5) "false" + [1]=> + string(4) "true" +} +- with $preserve_keys = false - +array(4) { + ["true"]=> + bool(true) + ["false"]=> + bool(false) + [0]=> + string(5) "false" + [1]=> + string(4) "true" +} +-- Iteration 15 -- +- with default argument - +array(3) { + ["emptys"]=> + string(0) "" + ["emptyd"]=> + string(0) "" + [""]=> + string(6) "emptys" +} +- with $preserve keys = true - +array(3) { + ["emptys"]=> + string(0) "" + ["emptyd"]=> + string(0) "" + [""]=> + string(6) "emptys" +} +- with $preserve_keys = false - +array(3) { + ["emptys"]=> + string(0) "" + ["emptyd"]=> + string(0) "" + [""]=> + string(6) "emptys" +} +-- Iteration 16 -- +- with default argument - +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + NULL + [3]=> + NULL + [4]=> + string(0) "" + [5]=> + string(0) "" +} +- with $preserve keys = true - +array(6) { + [6]=> + bool(true) + [5]=> + bool(false) + [4]=> + NULL + [3]=> + NULL + [2]=> + string(0) "" + [1]=> + string(0) "" +} +- with $preserve_keys = false - +array(6) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + NULL + [3]=> + NULL + [4]=> + string(0) "" + [5]=> + string(0) "" +} +-- Iteration 17 -- +- with default argument - +array(3) { + [0]=> + int(6) + [1]=> + int(5) + [""]=> + int(4) +} +- with $preserve keys = true - +array(3) { + [1]=> + int(6) + [0]=> + int(5) + [""]=> + int(4) +} +- with $preserve_keys = false - +array(3) { + [0]=> + int(6) + [1]=> + int(5) + [""]=> + int(4) +} +-- Iteration 18 -- +- with default argument - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(20) + ["One"]=> + int(10) +} +- with $preserve keys = true - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(20) + ["One"]=> + int(10) +} +- with $preserve_keys = false - +array(3) { + ["three"]=> + int(3) + ["two"]=> + int(20) + ["One"]=> + int(10) +} +Done diff --git a/ext/standard/tests/array/array_reverse_variation4.phpt b/ext/standard/tests/array/array_reverse_variation4.phpt new file mode 100644 index 0000000..e3f0254 --- /dev/null +++ b/ext/standard/tests/array/array_reverse_variation4.phpt @@ -0,0 +1,377 @@ +--TEST-- +Test array_reverse() function : usage variations - assoc. array with diff. keys for 'array' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_reverse() by giving associative arrays with different + * keys for $array argument +*/ + +echo "*** Testing array_reverse() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing the array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"), + + // arrays with string keys + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), +/*8*/ array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable + array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed values +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, $fp => 'resource', 133 => "int", 444.432 => "float", @$unset_var => "unset", $heredoc => "heredoc") +); + +// loop through the various elements of $arrays to test array_reverse() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + // with default argument + echo "- default argument -\n"; + var_dump( array_reverse($array) ); + // with $preserve_keys argument + echo "- \$preserve keys = true -\n"; + var_dump( array_reverse($array, true) ); + echo "- \$preserve_keys = false -\n"; + var_dump( array_reverse($array, false) ); + $iterator++; +}; + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +- default argument - +array(0) { +} +- $preserve keys = true - +array(0) { +} +- $preserve_keys = false - +array(0) { +} +-- Iteration 2 -- +- default argument - +array(1) { + [0]=> + string(1) "0" +} +- $preserve keys = true - +array(1) { + [0]=> + string(1) "0" +} +- $preserve_keys = false - +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +- default argument - +array(1) { + [0]=> + string(1) "1" +} +- $preserve keys = true - +array(1) { + [1]=> + string(1) "1" +} +- $preserve_keys = false - +array(1) { + [0]=> + string(1) "1" +} +-- Iteration 4 -- +- default argument - +array(4) { + [0]=> + string(1) "4" + [1]=> + string(1) "3" + [2]=> + string(1) "2" + [3]=> + string(1) "1" +} +- $preserve keys = true - +array(4) { + [4]=> + string(1) "4" + [3]=> + string(1) "3" + [2]=> + string(1) "2" + [1]=> + string(1) "1" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(1) "4" + [1]=> + string(1) "3" + [2]=> + string(1) "2" + [3]=> + string(1) "1" +} +-- Iteration 5 -- +- default argument - +array(1) { + [0]=> + string(5) "float" +} +- $preserve keys = true - +array(1) { + [2]=> + string(5) "float" +} +- $preserve_keys = false - +array(1) { + [0]=> + string(5) "float" +} +-- Iteration 6 -- +- default argument - +array(4) { + [0]=> + string(2) "f4" + [1]=> + string(2) "f3" + [2]=> + string(2) "f2" + [3]=> + string(2) "f1" +} +- $preserve keys = true - +array(4) { + [33333333]=> + string(2) "f4" + [4]=> + string(2) "f3" + [3]=> + string(2) "f2" + [1]=> + string(2) "f1" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(2) "f4" + [1]=> + string(2) "f3" + [2]=> + string(2) "f2" + [3]=> + string(2) "f1" +} +-- Iteration 7 -- +- default argument - +array(4) { + ["pen +"]=> + int(33) + ["world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve keys = true - +array(4) { + ["pen +"]=> + int(33) + ["world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve_keys = false - +array(4) { + ["pen +"]=> + int(33) + ["world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +-- Iteration 8 -- +- default argument - +array(4) { + ["pen +"]=> + int(33) + ["world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve keys = true - +array(4) { + ["pen +"]=> + int(33) + ["world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +- $preserve_keys = false - +array(4) { + ["pen +"]=> + int(33) + ["world"]=> + float(2.2) + ["re d"]=> + string(5) "color" + [" Hello"]=> + int(111) +} +-- Iteration 9 -- +- default argument - +array(2) { + ["Hello world"]=> + string(6) "string" + [0]=> + string(5) "hello" +} +- $preserve keys = true - +array(2) { + ["Hello world"]=> + string(6) "string" + [0]=> + string(5) "hello" +} +- $preserve_keys = false - +array(2) { + ["Hello world"]=> + string(6) "string" + [0]=> + string(5) "hello" +} +-- Iteration 10 -- +- default argument - +array(1) { + [""]=> + string(5) "hello" +} +- $preserve keys = true - +array(1) { + [""]=> + string(5) "hello" +} +- $preserve_keys = false - +array(1) { + [""]=> + string(5) "hello" +} +-- Iteration 11 -- +- default argument - +array(6) { + ["Hello world"]=> + string(7) "heredoc" + [""]=> + string(5) "unset" + [0]=> + string(5) "float" + [1]=> + string(3) "int" + ["fruit"]=> + float(2.2) + ["hello"]=> + int(1) +} +- $preserve keys = true - +array(6) { + ["Hello world"]=> + string(7) "heredoc" + [""]=> + string(5) "unset" + [444]=> + string(5) "float" + [133]=> + string(3) "int" + ["fruit"]=> + float(2.2) + ["hello"]=> + int(1) +} +- $preserve_keys = false - +array(6) { + ["Hello world"]=> + string(7) "heredoc" + [""]=> + string(5) "unset" + [0]=> + string(5) "float" + [1]=> + string(3) "int" + ["fruit"]=> + float(2.2) + ["hello"]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/array_reverse_variation5.phpt b/ext/standard/tests/array/array_reverse_variation5.phpt new file mode 100644 index 0000000..6c4c952 --- /dev/null +++ b/ext/standard/tests/array/array_reverse_variation5.phpt @@ -0,0 +1,399 @@ +--TEST-- +Test array_reverse() function : usage variations - assoc. array with diff. value for 'array' argument +--INI-- +precision=12 +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_reverse() by giving associative arrays with different + * values for $array argument +*/ + +echo "*** Testing array_reverse() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing the array +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + + // arrays with string values + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), +/*8*/ array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// loop through the various elements of $arrays to test array_reverse() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + // with default argument + echo "- default argument -\n"; + var_dump( array_reverse($array) ); + // with $preserve_keys argument + echo "- \$preserve keys = true -\n"; + var_dump( array_reverse($array, true) ); + echo "- \$preserve_keys = false -\n"; + var_dump( array_reverse($array, false) ); + $iterator++; +}; + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** +-- Iteration 1 -- +- default argument - +array(0) { +} +- $preserve keys = true - +array(0) { +} +- $preserve_keys = false - +array(0) { +} +-- Iteration 2 -- +- default argument - +array(1) { + [0]=> + int(0) +} +- $preserve keys = true - +array(1) { + [0]=> + int(0) +} +- $preserve_keys = false - +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +- default argument - +array(1) { + [0]=> + int(1) +} +- $preserve keys = true - +array(1) { + [1]=> + int(1) +} +- $preserve_keys = false - +array(1) { + [0]=> + int(1) +} +-- Iteration 4 -- +- default argument - +array(4) { + [0]=> + int(4) + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- $preserve keys = true - +array(4) { + [4]=> + int(4) + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +- $preserve_keys = false - +array(4) { + [0]=> + int(4) + ["three"]=> + int(3) + ["two"]=> + int(2) + ["one"]=> + int(1) +} +-- Iteration 5 -- +- default argument - +array(1) { + ["float"]=> + float(2.3333) +} +- $preserve keys = true - +array(1) { + ["float"]=> + float(2.3333) +} +- $preserve_keys = false - +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +- default argument - +array(4) { + ["f4"]=> + float(33333333.3333) + [0]=> + float(4.8999992284) + ["f2"]=> + float(3.33) + ["f1"]=> + float(1.2) +} +- $preserve keys = true - +array(4) { + ["f4"]=> + float(33333333.3333) + [3]=> + float(4.8999992284) + ["f2"]=> + float(3.33) + ["f1"]=> + float(1.2) +} +- $preserve_keys = false - +array(4) { + ["f4"]=> + float(33333333.3333) + [0]=> + float(4.8999992284) + ["f2"]=> + float(3.33) + ["f1"]=> + float(1.2) +} +-- Iteration 7 -- +- default argument - +array(4) { + [0]=> + string(4) "pen +" + [1]=> + string(7) "world" + ["red"]=> + string(6) "col or" + [2]=> + string(6) " Hello" +} +- $preserve keys = true - +array(4) { + [3]=> + string(4) "pen +" + [2]=> + string(7) "world" + ["red"]=> + string(6) "col or" + [111]=> + string(6) " Hello" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(4) "pen +" + [1]=> + string(7) "world" + ["red"]=> + string(6) "col or" + [2]=> + string(6) " Hello" +} +-- Iteration 8 -- +- default argument - +array(4) { + [0]=> + string(5) "pen\n" + [1]=> + string(9) "\v\fworld" + ["red"]=> + string(7) "col\tor" + [2]=> + string(7) "\tHello" +} +- $preserve keys = true - +array(4) { + [3]=> + string(5) "pen\n" + [2]=> + string(9) "\v\fworld" + ["red"]=> + string(7) "col\tor" + [111]=> + string(7) "\tHello" +} +- $preserve_keys = false - +array(4) { + [0]=> + string(5) "pen\n" + [1]=> + string(9) "\v\fworld" + ["red"]=> + string(7) "col\tor" + [2]=> + string(7) "\tHello" +} +-- Iteration 9 -- +- default argument - +array(2) { + ["heredoc"]=> + string(11) "Hello world" + [0]=> + string(5) "hello" +} +- $preserve keys = true - +array(2) { + ["heredoc"]=> + string(11) "Hello world" + [1]=> + string(5) "hello" +} +- $preserve_keys = false - +array(2) { + ["heredoc"]=> + string(11) "Hello world" + [0]=> + string(5) "hello" +} +-- Iteration 10 -- +- default argument - +array(3) { + ["resource"]=> + resource(%d) of type (stream) + ["unset"]=> + NULL + [0]=> + object(classA)#%d (0) { + } +} +- $preserve keys = true - +array(3) { + ["resource"]=> + resource(%d) of type (stream) + ["unset"]=> + NULL + [11]=> + object(classA)#%d (0) { + } +} +- $preserve_keys = false - +array(3) { + ["resource"]=> + resource(%d) of type (stream) + ["unset"]=> + NULL + [0]=> + object(classA)#%d (0) { + } +} +-- Iteration 11 -- +- default argument - +array(8) { + ["heredoc"]=> + string(11) "Hello world" + ["unset"]=> + NULL + ["float"]=> + float(444.432) + ["int"]=> + int(133) + ["resource"]=> + resource(%d) of type (stream) + [0]=> + string(5) "fruit" + [1]=> + object(classA)#%d (0) { + } + [2]=> + string(5) "hello" +} +- $preserve keys = true - +array(8) { + ["heredoc"]=> + string(11) "Hello world" + ["unset"]=> + NULL + ["float"]=> + float(444.432) + ["int"]=> + int(133) + ["resource"]=> + resource(%d) of type (stream) + [222]=> + string(5) "fruit" + [2]=> + object(classA)#%d (0) { + } + [1]=> + string(5) "hello" +} +- $preserve_keys = false - +array(8) { + ["heredoc"]=> + string(11) "Hello world" + ["unset"]=> + NULL + ["float"]=> + float(444.432) + ["int"]=> + int(133) + ["resource"]=> + resource(%d) of type (stream) + [0]=> + string(5) "fruit" + [1]=> + object(classA)#%d (0) { + } + [2]=> + string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_reverse_variation6.phpt b/ext/standard/tests/array/array_reverse_variation6.phpt new file mode 100644 index 0000000..ae1e195 --- /dev/null +++ b/ext/standard/tests/array/array_reverse_variation6.phpt @@ -0,0 +1,209 @@ +--TEST-- +Test array_reverse() function : usage variations - two dimensional arrays for 'array' argument +--FILE-- +<?php +/* Prototype : array array_reverse(array $array [, bool $preserve_keys]) + * Description: Return input as a new array with the order of the entries reversed + * Source code: ext/standard/array.c +*/ + +/* + * testing the functionality of array_reverse() by giving 2-D arrays for $array argument +*/ + +echo "*** Testing array_reverse() : usage variations ***\n"; + +// Initializing the 2-d arrays +$two_dimensional_array = array( + + // associative array + array('color' => 'red', 'item' => 'pen', 'place' => 'LA'), + + // numeric array + array(1, 2, 3, 4, 5), + + // combination of numeric and associative arrays + array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball') +); + +// calling array_reverse() with various types of 2-d arrays +// with default arguments +echo "-- with default argument --\n"; +var_dump( array_reverse($two_dimensional_array) ); // whole array +var_dump( array_reverse($two_dimensional_array[1]) ); // sub array + +// with $preserve_keys argument +echo "-- with all possible arguments --\n"; +// whole array +var_dump( array_reverse($two_dimensional_array, true) ); +var_dump( array_reverse($two_dimensional_array, false) ); +// sub array +var_dump( array_reverse($two_dimensional_array[1], true) ); +var_dump( array_reverse($two_dimensional_array[1], false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_reverse() : usage variations *** +-- with default argument -- +array(3) { + [0]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } + [1]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [2]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } +} +array(5) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) +} +-- with all possible arguments -- +array(3) { + [2]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } + [1]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [0]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } +} +array(3) { + [0]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } + [1]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [2]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } +} +array(5) { + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +array(5) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/array_search.phpt b/ext/standard/tests/array/array_search.phpt Binary files differnew file mode 100644 index 0000000..1afcb1d --- /dev/null +++ b/ext/standard/tests/array/array_search.phpt diff --git a/ext/standard/tests/array/array_search1.phpt b/ext/standard/tests/array/array_search1.phpt new file mode 100644 index 0000000..26377d2 --- /dev/null +++ b/ext/standard/tests/array/array_search1.phpt @@ -0,0 +1,35 @@ +--TEST-- +array_search() tests +--FILE-- +<?php + +$a = array(1=>0, 2=>1, 4=>3, "a"=>"b", "c"=>"d"); + +var_dump(array_search(1)); +var_dump(array_search(1,1)); +var_dump(array_search("a",$a)); +var_dump(array_search("0",$a, true)); +var_dump(array_search("0",$a)); +var_dump(array_search(0,$a)); +var_dump(array_search(1,$a)); +var_dump(array_search("d",$a, true)); +var_dump(array_search("d",$a)); +var_dump(array_search(-1,$a, true)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_search() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: array_search() expects parameter 2 to be array, integer given in %s on line %d +NULL +int(1) +bool(false) +int(1) +int(1) +int(2) +string(1) "c" +int(1) +bool(false) +Done diff --git a/ext/standard/tests/array/array_search_errors.phpt b/ext/standard/tests/array/array_search_errors.phpt new file mode 100644 index 0000000..0127f62 --- /dev/null +++ b/ext/standard/tests/array/array_search_errors.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_search() function - error conditions +--FILE-- +<?php +/* + * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise + * Source Code: ext/standard/array.c +*/ + +echo "*** Testing error conditions of array_search() ***\n"; +/* zero argument */ +var_dump( array_search() ); + +/* unexpected no.of arguments in array_search() */ +$var = array("mon", "tues", "wed", "thurs"); +var_dump( array_search(1, $var, 0, "test") ); +var_dump( array_search("test") ); + +/* unexpected second argument in array_search() */ +$var="test"; +var_dump( array_search("test", $var) ); +var_dump( array_search(1, 123) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing error conditions of array_search() *** + +Warning: array_search() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: array_search() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: array_search() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: array_search() expects parameter 2 to be array, string given in %s on line %d +NULL + +Warning: array_search() expects parameter 2 to be array, integer given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_search_variation1.phpt b/ext/standard/tests/array/array_search_variation1.phpt new file mode 100644 index 0000000..9639501 --- /dev/null +++ b/ext/standard/tests/array/array_search_variation1.phpt @@ -0,0 +1,641 @@ +--TEST-- +Test array_search() function : usage variations - different needle values +--FILE-- +<?php +/* + * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise + * Source Code: ext/standard/array.c +*/ + +/* Test array_search() with different possible needle values */ + +echo "*** Testing array_search() with different needle values ***\n"; +$arrays = array ( + array(0), + array("a" => "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 array_search() */ +$counter = 1; +foreach($arrays as $array) { + foreach($array_compare as $compare) { + echo "-- Iteration $counter --\n"; + //strict option OFF + var_dump(array_search($compare,$array)); + //strict option ON + var_dump(array_search($compare,$array,TRUE)); + //strict option OFF + var_dump(array_search($compare,$array,FALSE)); + $counter++; + } +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_search() with different needle values *** +-- 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 -- +int(0) +bool(false) +int(0) +-- 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 -- +int(0) +bool(false) +int(0) +-- Iteration 11 -- +int(0) +bool(false) +int(0) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +int(0) +bool(false) +int(0) +-- Iteration 14 -- +int(0) +bool(false) +int(0) +-- Iteration 15 -- +int(0) +bool(false) +int(0) +-- Iteration 16 -- +int(0) +bool(false) +int(0) +-- Iteration 17 -- +int(0) +int(0) +int(0) +-- Iteration 18 -- +int(0) +bool(false) +int(0) +-- Iteration 19 -- +int(4) +int(4) +int(4) +-- Iteration 20 -- +int(4) +bool(false) +int(4) +-- Iteration 21 -- +int(4) +bool(false) +int(4) +-- Iteration 22 -- +int(5) +int(5) +int(5) +-- 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 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 30 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 31 -- +string(0) "" +string(0) "" +string(0) "" +-- Iteration 32 -- +int(6) +int(6) +int(6) +-- Iteration 33 -- +int(7) +int(7) +int(7) +-- Iteration 34 -- +string(1) "a" +bool(false) +string(1) "a" +-- Iteration 35 -- +string(1) "a" +bool(false) +string(1) "a" +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +int(0) +int(0) +int(0) +-- Iteration 38 -- +int(0) +bool(false) +int(0) +-- Iteration 39 -- +int(0) +bool(false) +int(0) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +int(5) +bool(false) +int(5) +-- 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 -- +int(1) +int(1) +int(1) +-- Iteration 61 -- +int(1) +bool(false) +int(1) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +string(3) "-.9" +bool(false) +string(3) "-.9" +-- 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 -- +int(2) +bool(false) +int(2) +-- Iteration 71 -- +int(2) +bool(false) +int(2) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +int(0) +bool(false) +int(0) +-- Iteration 74 -- +int(0) +bool(false) +int(0) +-- Iteration 75 -- +int(0) +bool(false) +int(0) +-- Iteration 76 -- +int(0) +bool(false) +int(0) +-- Iteration 77 -- +int(0) +bool(false) +int(0) +-- Iteration 78 -- +int(0) +bool(false) +int(0) +-- Iteration 79 -- +int(0) +bool(false) +int(0) +-- Iteration 80 -- +int(0) +bool(false) +int(0) +-- Iteration 81 -- +int(0) +bool(false) +int(0) +-- Iteration 82 -- +int(0) +bool(false) +int(0) +-- Iteration 83 -- +int(1) +bool(false) +int(1) +-- Iteration 84 -- +int(1) +bool(false) +int(1) +-- Iteration 85 -- +int(1) +bool(false) +int(1) +-- Iteration 86 -- +int(0) +bool(false) +int(0) +-- Iteration 87 -- +int(0) +bool(false) +int(0) +-- Iteration 88 -- +int(1) +bool(false) +int(1) +-- Iteration 89 -- +int(1) +bool(false) +int(1) +-- Iteration 90 -- +int(0) +bool(false) +int(0) +-- 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 -- +int(0) +int(0) +int(0) +-- Iteration 102 -- +int(1) +int(1) +int(1) +-- Iteration 103 -- +int(0) +bool(false) +int(0) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +int(0) +bool(false) +int(0) +-- Iteration 107 -- +int(0) +bool(false) +int(0) +-- 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 -- +int(0) +bool(false) +int(0) +-- Iteration 125 -- +int(0) +bool(false) +int(0) +-- Iteration 126 -- +int(0) +int(0) +int(0) +-- 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 -- +int(0) +bool(false) +int(0) +-- Iteration 143 -- +int(0) +bool(false) +int(0) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) +Done diff --git a/ext/standard/tests/array/array_search_variation2.phpt b/ext/standard/tests/array/array_search_variation2.phpt new file mode 100644 index 0000000..da90de0 --- /dev/null +++ b/ext/standard/tests/array/array_search_variation2.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test array_search() function : usage variations - different haystack values +--FILE-- +<?php +/* + * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise + * Source Code: ext/standard/array.c +*/ + +/* Test array_search() with different possible haystack values */ + +echo "*** Testing array_search() with different haystack values ***\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 array_search(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( array_search($type,$misc_array ) ); + //strict type checking + var_dump( array_search($type,$misc_array,true) ); + //loose type checking + var_dump( array_search($type,$misc_array,false) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_search() with different haystack values *** +-- Iteration 1 -- +int(0) +int(3) +int(0) +-- Iteration 2 -- +string(1) "y" +int(4) +string(1) "y" +-- Iteration 3 -- +int(3) +bool(false) +int(3) +-- Iteration 4 -- +string(3) "key" +int(2) +string(3) "key" +-- Iteration 5 -- +int(3) +bool(false) +int(3) +-- Iteration 6 -- +int(3) +bool(false) +int(3) +-- Iteration 7 -- +int(2) +bool(false) +int(2) +-- Iteration 8 -- +int(3) +bool(false) +int(3) +-- Iteration 9 -- +string(1) "y" +string(1) "y" +string(1) "y" +-- Iteration 10 -- +string(1) "y" +bool(false) +string(1) "y" +-- Iteration 11 -- +int(2) +bool(false) +int(2) +-- Iteration 12 -- +string(1) "y" +string(0) "" +string(1) "y" +Done diff --git a/ext/standard/tests/array/array_search_variation3.phpt b/ext/standard/tests/array/array_search_variation3.phpt new file mode 100644 index 0000000..8af089a --- /dev/null +++ b/ext/standard/tests/array/array_search_variation3.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_search() function : usage variations - haystack as sub-array/object +--FILE-- +<?php +/* + * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise + * Source Code: ext/standard/array.c +*/ + +/* checking for sub-arrays with array_search() */ +echo "*** Testing sub-arrays with array_search() ***\n"; +$sub_array = array ( + "one", + array(1, 2 => "two", "three" => 3), + 4 => "four", + "five" => 5, + array('', 'i') +); +var_dump( array_search("four", $sub_array) ); +//checking for element in a sub-array +var_dump( array_search(3, $sub_array[1]) ); +var_dump( array_search(array('','i'), $sub_array) ); + +/* checking for objects in array_search() */ +echo "\n*** Testing objects with array_search() ***\n"; +class array_search_check { + public $array_var = array(1=>"one", "two"=>2, 3=>3); + public function foo() { + echo "Public function\n"; + } +} + +$array_search_obj = new array_search_check(); //creating new object +//error: as wrong datatype for second argument +var_dump( array_search("array_var", $array_search_obj) ); +//error: as wrong datatype for second argument +var_dump( array_search("foo", $array_search_obj) ); +//element found as "one" exists in array $array_var +var_dump( array_search("one", $array_search_obj->array_var) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sub-arrays with array_search() *** +int(4) +string(5) "three" +int(5) + +*** Testing objects with array_search() *** + +Warning: array_search() expects parameter 2 to be array, object given in %s on line %d +NULL + +Warning: array_search() expects parameter 2 to be array, object given in %s on line %d +NULL +int(1) +Done diff --git a/ext/standard/tests/array/array_search_variation4.phpt b/ext/standard/tests/array/array_search_variation4.phpt new file mode 100644 index 0000000..04f3b91 --- /dev/null +++ b/ext/standard/tests/array/array_search_variation4.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_search() function : usage variations - haystack as resource/multi dimentional array +--FILE-- +<?php +/* + * Prototype : mixed array_search ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise + * Source Code: ext/standard/array.c +*/ + +/* checking for Resources */ +echo "*** Testing resource type with array_search() ***\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( array_search($file_handle, $resources, true) ); +//checking for (int) type resource +var_dump( array_search((int)$dir_handle, $resources, true) ); + +/* Miscellenous input check */ +echo "\n*** Testing miscelleneos inputs with array_search() ***\n"; +//matching "Good" in array(0,"hello"), result:true in loose type check +var_dump( array_search("Good", array(0,"hello")) ); +//false in strict mode +var_dump( array_search("Good", array(0,"hello"), TRUE) ); + +//matching integer 0 in array("this"), result:true in loose type check +var_dump( array_search(0, array("this")) ); +// false in strict mode +var_dump( array_search(0, array("this")),TRUE ); + +//matching string "this" in array(0), result:true in loose type check +var_dump( array_search("this", array(0)) ); +// false in stric mode +var_dump( array_search("this", array(0), TRUE) ); + +//checking for type FALSE in multidimensional array with loose checking, result:false in loose type check +var_dump( array_search(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( array_search('123abc', array(123)) ); +var_dump( array_search('123abc', array(123), TRUE) ); // false in strict mode + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing resource type with array_search() *** +int(0) +bool(false) + +*** Testing miscelleneos inputs with array_search() *** +int(0) +bool(false) +int(0) +int(0) +bool(true) +int(0) +bool(false) +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/array/array_shift_basic.phpt b/ext/standard/tests/array/array_shift_basic.phpt new file mode 100644 index 0000000..2bb4ae9 --- /dev/null +++ b/ext/standard/tests/array/array_shift_basic.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_shift() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_shift() + */ + +echo "*** Testing array_shift() : basic functionality ***\n"; + +$array = array('zero', 'one', '3' => 'three', 'four' => 4); +echo "\n-- Before shift: --\n"; +var_dump($array); + +echo "\n-- After shift: --\n"; +echo "Returned value:\t"; +var_dump(array_shift($array)); +echo "New array:\n"; +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : basic functionality *** + +-- Before shift: -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [3]=> + string(5) "three" + ["four"]=> + int(4) +} + +-- After shift: -- +Returned value: string(4) "zero" +New array: +array(3) { + [0]=> + string(3) "one" + [1]=> + string(5) "three" + ["four"]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_error.phpt b/ext/standard/tests/array/array_shift_error.phpt new file mode 100644 index 0000000..fcfb931 --- /dev/null +++ b/ext/standard/tests/array/array_shift_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_shift() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_shift() to test behaviour + */ + +echo "*** Testing array_shift() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_shift() function with Zero arguments --\n"; +var_dump( array_shift() ); + +//Test array_shift with one more than the expected number of arguments +echo "\n-- Testing array_shift() function with more than expected no. of arguments --\n"; +$stack = array(1, 2); +$extra_arg = 10; +var_dump( array_shift($stack, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : error conditions *** + +-- Testing array_shift() function with Zero arguments -- + +Warning: array_shift() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing array_shift() function with more than expected no. of arguments -- + +Warning: array_shift() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation1.phpt b/ext/standard/tests/array/array_shift_variation1.phpt new file mode 100644 index 0000000..fea2d59 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation1.phpt @@ -0,0 +1,218 @@ +--TEST-- +Test array_shift() function : usage variations - Pass different data types as $stack arg +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $stack argument to array_shift() to test behaviour + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_shift() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_shift($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1 -- + +Warning: array_shift() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_shift() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_shift() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_shift() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_shift() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_shift() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_shift() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_shift() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_shift() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_shift() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_shift() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_shift() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_shift() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_shift() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_shift() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_shift() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_shift() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_shift() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_shift() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_shift() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_shift() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_shift() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_shift() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_shift() expects parameter 1 to be array, resource given in %s on line 85 +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation2.phpt b/ext/standard/tests/array/array_shift_variation2.phpt new file mode 100644 index 0000000..2b3adc6 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation2.phpt @@ -0,0 +1,208 @@ +--TEST-- +Test array_shift() function : usage variations - Pass arrays of different data types +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where values are of one data type to test behaviour of array_shift() + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of array_shift +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_shift($input) ); + var_dump($input); + $iterator++; +}; + +fclose($fp); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1: int data -- +int(0) +array(3) { + [0]=> + int(1) + [1]=> + int(12345) + [2]=> + int(-2345) +} + +-- Iteration 2: float data -- +float(10.5) +array(4) { + [0]=> + float(-10.5) + [1]=> + float(123456789000) + [2]=> + float(1.23456789E-9) + [3]=> + float(0.5) +} + +-- Iteration 3: null data -- +NULL +array(1) { + [0]=> + NULL +} + +-- Iteration 4: bool data -- +bool(true) +array(3) { + [0]=> + bool(false) + [1]=> + bool(true) + [2]=> + bool(false) +} + +-- Iteration 5: empty string data -- +string(0) "" +array(1) { + [0]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +NULL +array(0) { +} + +-- Iteration 7: string data -- +string(6) "string" +array(2) { + [0]=> + string(6) "string" + [1]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +object(classA)#%d (0) { +} +array(0) { +} + +-- Iteration 9: undefined data -- +NULL +array(0) { +} + +-- Iteration 10: unset data -- +NULL +array(0) { +} + +-- Iteration 11: resource data -- +resource(%d) of type (stream) +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation3.phpt b/ext/standard/tests/array/array_shift_variation3.phpt new file mode 100644 index 0000000..cc260c6 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation3.phpt @@ -0,0 +1,188 @@ +--TEST-- +Test array_shift() function : usage variations - Pass array with different data types as keys +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays with different data types as keys to test how array_shift() re-assigns keys + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $stack argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_shift() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( array_shift($input) ); + var_dump($input); + $iterator++; +}; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Iteration 1 : int data -- +string(4) "zero" +array(3) { + [0]=> + string(3) "one" + [1]=> + string(8) "positive" + [2]=> + string(8) "negative" +} + +-- Iteration 2 : float data -- +string(8) "positive" +array(2) { + [0]=> + string(8) "negative" + [1]=> + string(4) "half" +} + +-- Iteration 3 : extreme floats data -- +string(5) "large" +array(1) { + [0]=> + string(5) "small" +} + +-- Iteration 4 : null uppercase data -- +string(6) "null 1" +array(0) { +} + +-- Iteration 5 : null lowercase data -- +string(6) "null 2" +array(0) { +} + +-- Iteration 6 : bool lowercase data -- +string(6) "lowert" +array(1) { + [0]=> + string(6) "lowerf" +} + +-- Iteration 7 : bool uppercase data -- +string(6) "uppert" +array(1) { + [0]=> + string(6) "upperf" +} + +-- Iteration 8 : empty double quotes data -- +string(6) "emptyd" +array(0) { +} + +-- Iteration 9 : empty single quotes data -- +string(6) "emptys" +array(0) { +} + +-- Iteration 10 : string data -- +string(7) "stringd" +array(2) { + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11 : undefined data -- +string(9) "undefined" +array(0) { +} + +-- Iteration 12 : unset data -- +string(5) "unset" +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation4.phpt b/ext/standard/tests/array/array_shift_variation4.phpt new file mode 100644 index 0000000..f276815 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation4.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_shift() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test popping elements from a sub-array and popping an array from an array + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +$stack_first = array(array(1, 2, 3), 'one', 'two'); +$stack_last = array ('zero', 'one', array (1, 2, 3)); +echo "\n-- Before shift: --\n"; +echo "---- \$stack_first:\n"; +var_dump($stack_first); +echo "---- \$stack_last:\n"; +var_dump($stack_last); + +echo "\n-- After shift: --\n"; +echo "---- Pop array from array:\n"; +echo "Returned value:\t"; +var_dump(array_shift($stack_first)); +echo "New array:\n"; +var_dump($stack_first); + +echo "---- Pop element from array within array:\n"; +echo "Returned value:\t"; +var_dump(array_shift($stack_last[2])); +echo "New array:\n"; +var_dump($stack_last); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Before shift: -- +---- $stack_first: +array(3) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +---- $stack_last: +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- After shift: -- +---- Pop array from array: +Returned value: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +New array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +---- Pop element from array within array: +Returned value: int(1) +New array: +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(2) { + [0]=> + int(2) + [1]=> + int(3) + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation5.phpt b/ext/standard/tests/array/array_shift_variation5.phpt new file mode 100644 index 0000000..578b870 --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation5.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_shift() function : usage variations - call recursively +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Use the result of one call to array_shift + * as the $stack argument of another call to array_shift() + * When done in one statement causes strict error messages. + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +$stack = array ( array ( array ('zero', 'one', 'two'), 'un', 'deux'), 'eins', 'zwei'); + +// not following strict standards +echo "\n-- Incorrect Method: --\n"; +var_dump(array_shift(array_shift(array_shift($stack)))); + +$stack = array (array( array('zero', 'one', 'two'), 'un', 'deux'), 'eins', 'zwei'); +// correct way of doing above: +echo "\n-- Correct Method: --\n"; +$result1 = array_shift($stack); +$result2 = array_shift($result1); +var_dump(array_shift($result2)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Incorrect Method: -- + +Strict Standards: Only variables should be passed by reference in %s on line %d + +Strict Standards: Only variables should be passed by reference in %s on line %d +string(4) "zero" + +-- Correct Method: -- +string(4) "zero" +Done diff --git a/ext/standard/tests/array/array_shift_variation6.phpt b/ext/standard/tests/array/array_shift_variation6.phpt new file mode 100644 index 0000000..9033e7d --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation6.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test array_shift() function : usage variations - Referenced arrays +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test how array_shift when passed: + * 1. a variable that is referenced to an array + * 2. an array that contains a referenced array + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +echo "\n-- Variable is referenced array --\n"; +$original_array = array('zero', 'one', 'two'); +$copied_array = &$original_array; + +echo "Result: "; +var_dump(array_shift($copied_array)); +echo "\n\$original_array:\n"; +var_dump($original_array); +echo "\n\$copied_array:\n"; +var_dump($copied_array); + +echo "\n-- Element is referenced array --\n"; +$new_array = array (&$copied_array, 1, 'two'); +echo "Result: "; +var_dump(array_shift($new_array[0])); +echo "\n\$new_array:\n"; +var_dump($new_array); +echo "\n\$copied_array\n"; +var_dump($copied_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Variable is referenced array -- +Result: string(4) "zero" + +$original_array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} + +$copied_array: +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} + +-- Element is referenced array -- +Result: string(3) "one" + +$new_array: +array(3) { + [0]=> + &array(1) { + [0]=> + string(3) "two" + } + [1]=> + int(1) + [2]=> + string(3) "two" +} + +$copied_array +array(1) { + [0]=> + string(3) "two" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation7.phpt b/ext/standard/tests/array/array_shift_variation7.phpt new file mode 100644 index 0000000..9367cac --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation7.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_shift() function : usage variations - position of internal pointer +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * Test that the internal pointer is reset after calling array_shift() + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +$stack = array ('one' => 'un', 'two' => 'deux'); + +echo "\n-- Call array_shift() --\n"; +var_dump($result = array_shift($stack)); + +echo "\n-- Position of Internal Pointer in Passed Array: --\n"; +echo key($stack) . " => " . current ($stack) . "\n"; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Call array_shift() -- +string(2) "un" + +-- Position of Internal Pointer in Passed Array: -- +two => deux +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shift_variation8.phpt b/ext/standard/tests/array/array_shift_variation8.phpt new file mode 100644 index 0000000..717d98f --- /dev/null +++ b/ext/standard/tests/array/array_shift_variation8.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_shift() function : usage variations - maintaining referenced elements +--FILE-- +<?php +/* Prototype : mixed array_shift(array &$stack) + * Description: Pops an element off the beginning of the array + * Source code: ext/standard/array.c + */ + +/* + * From a comment left by Traps on 09-Jul-2007 on the array_shift documentation page: + * For those that may be trying to use array_shift() with an array containing references + * (e.g. working with linked node trees), beware that array_shift() may not work as you expect: + * it will return a *copy* of the first element of the array, + * and not the element itself, so your reference will be lost. + * The solution is to reference the first element before removing it with array_shift(): + */ + +echo "*** Testing array_shift() : usage variations ***\n"; + +// using only array_shift: +echo "\n-- Reference result of array_shift: --\n"; +$a = 1; +$array = array(&$a); +$b =& array_shift($array); +$b = 2; +echo "a = $a, b = $b\n"; + +// solution: referencing the first element first: +echo "\n-- Reference first element before array_shift: --\n"; +$a = 1; +$array = array(&$a); +$b =& $array[0]; +array_shift($array); +$b = 2; +echo "a = $a, b = $b\n"; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_shift() : usage variations *** + +-- Reference result of array_shift: -- + +Strict Standards: Only variables should be assigned by reference in %s on line %d +a = 1, b = 2 + +-- Reference first element before array_shift: -- +a = 2, b = 2 +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_shuffle_basic.phpt b/ext/standard/tests/array/array_shuffle_basic.phpt new file mode 100644 index 0000000..fdf9326 --- /dev/null +++ b/ext/standard/tests/array/array_shuffle_basic.phpt @@ -0,0 +1,99 @@ +--TEST-- +array_shuffle(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto bool shuffle ( array &$array ) +* Function is implemented in ext/standard/array.c +*/ +$numbers = range(1, 20); +echo "*** testing array_shuffle \n"; +$a = array(); +var_dump(shuffle($a)); +var_dump($a); +$a = array(1); +var_dump(shuffle($a)); +var_dump($a); +$a = array(2 => 1); +var_dump(shuffle($a)); +var_dump($a); +$a = array("a" => 1); +var_dump(shuffle($a)); +var_dump($a); +$a = array(array(1, 2, 3)); +var_dump(shuffle($a)); +var_dump($a); +$a = array(1, 1, 1, 1); +var_dump(shuffle($a)); +var_dump($a); +$arr1 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9); +$arr2 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9); +shuffle($arr1); +echo "this should be 0->...." . count(array_diff($arr1, $arr2)) . "\n"; +echo "this should be 4->...." . count(array_intersect($arr1, $arr2)) . "\n"; +$bigarray = range(1, 400); +shuffle($bigarray); +echo "this should be 400->...." . count($bigarray) . "\n"; +echo "*** testing pass by reference \n"; +$original = $bigarray; +shuffle($bigarray); +$diffarray = array_diff_assoc($original, $bigarray); +if (count($diffarray) < 350) { + // with 400 entries, the probability that 50 entries or more get the same + // key-> value association should be so close to zero it wont happen in the lifetime of the + // universe. + echo "shuffled array seems to be similar to original\n"; + var_dump($original); + var_dump($bigarray); +} else { + echo "test passed \n"; +} +?> +--EXPECT-- +*** testing array_shuffle +bool(true) +array(0) { +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + int(1) +} +bool(true) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) +} +this should be 0->....0 +this should be 4->....4 +this should be 400->....400 +*** testing pass by reference +test passed
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice.phpt b/ext/standard/tests/array/array_slice.phpt new file mode 100644 index 0000000..b17fbce --- /dev/null +++ b/ext/standard/tests/array/array_slice.phpt @@ -0,0 +1,1459 @@ +--TEST-- +Testing array_slice() function +--FILE-- +<?php + +$var_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"), + array(12, "name", 'age', '45'), + array( array("oNe", "tWo", 4), array(10, 20, 30, 40, 50), array()) + ); + +$num = 4; +$str = "john"; + +/* Zero args */ +echo"\n*** Output for Zero Argument ***\n"; +array_slice(); + +/* Single args */ +echo"\n*** Output for Single array Argument ***\n"; +array_slice($var_array); + +/* More than valid no. of args (ie. >4 ) */ +echo"\n*** Output for invalid number of Arguments ***\n"; +array_slice($var_array, 2, 4, true, 3); + +/* Scalar arg */ +echo"\n*** Output for scalar Argument ***\n"; +array_slice($num, 2); + +/* String arg */ +echo"\n*** Output for string Argument ***\n"; +array_slice($str, 2); + +$counter = 1; +foreach ($var_array as $sub_array) +{ + /* variations with two arguments */ + /* offset values >, < and = 0 */ + + echo"\n*** Iteration ".$counter." ***\n"; + echo"\n*** Variation with first two Arguments ***\n"; + var_dump ( array_slice($sub_array, 1) ); + var_dump ( array_slice($sub_array, 0) ); + var_dump ( array_slice($sub_array, -2) ); + + /* variations with three arguments */ + /* offset value variations with length values */ + echo"\n*** Variation with first three Arguments ***\n"; + var_dump ( array_slice($sub_array, 1, 3) ); + var_dump ( array_slice($sub_array, 1, 0) ); + var_dump ( array_slice($sub_array, 1, -3) ); + var_dump ( array_slice($sub_array, 0, 3) ); + var_dump ( array_slice($sub_array, 0, 0) ); + var_dump ( array_slice($sub_array, 0, -3) ); + var_dump ( array_slice($sub_array, -2, 3) ); + var_dump ( array_slice($sub_array, -2, 0 ) ); + var_dump ( array_slice($sub_array, -2, -3) ); + + /* variations with four arguments */ + /* offset value, length value and preserve_key values variation */ + echo"\n*** Variation with first two arguments with preserve_key value TRUE ***\n"; + var_dump ( array_slice($sub_array, 1, 3, true) ); + var_dump ( array_slice($sub_array, 1, 0, true) ); + var_dump ( array_slice($sub_array, 1, -3, true) ); + var_dump ( array_slice($sub_array, 0, 3, true) ); + var_dump ( array_slice($sub_array, 0, 0, true) ); + var_dump ( array_slice($sub_array, 0, -3, true) ); + var_dump ( array_slice($sub_array, -2, 3, true) ); + var_dump ( array_slice($sub_array, -2, 0, true) ); + var_dump ( array_slice($sub_array, -2, -3, true) ); + $counter++; +} + + /* variation of offset and length to point to same element */ + echo"\n*** Typical Variation of offset and length Arguments ***\n"; + var_dump (array_slice($var_array[2], 1, -3, true) ); + var_dump (array_slice($var_array[2], 1, -3, false) ); + var_dump (array_slice($var_array[2], -3, -2, true) ); + var_dump (array_slice($var_array[2], -3, -2, false) ); + +?> +--EXPECTF-- +*** Output for Zero Argument *** + +Warning: array_slice() expects at least 2 parameters, 0 given in %s on line %d + +*** Output for Single array Argument *** + +Warning: array_slice() expects at least 2 parameters, 1 given in %s on line %d + +*** Output for invalid number of Arguments *** + +Warning: array_slice() expects at most 4 parameters, 5 given in %s on line %d + +*** Output for scalar Argument *** + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d + +*** Output for string Argument *** + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d + +*** Iteration 1 *** + +*** Variation with first two Arguments *** +array(0) { +} +array(0) { +} +array(0) { +} + +*** Variation with first three Arguments *** +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} +array(0) { +} + +*** Iteration 2 *** + +*** Variation with first two Arguments *** +array(8) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) + [5]=> + int(7) + [6]=> + int(8) + [7]=> + int(9) +} +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) +} +array(2) { + [0]=> + int(8) + [1]=> + int(9) +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) +} +array(0) { +} +array(5) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +array(2) { + [0]=> + int(8) + [1]=> + int(9) +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) +} +array(0) { +} +array(5) { + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +array(2) { + [7]=> + int(8) + [8]=> + int(9) +} +array(0) { +} +array(0) { +} + +*** Iteration 3 *** + +*** Variation with first two Arguments *** +array(4) { + [0]=> + string(3) "Two" + [1]=> + string(5) "Three" + [2]=> + string(4) "Four" + [3]=> + string(4) "Five" +} +array(5) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} +array(2) { + [0]=> + string(4) "Four" + [1]=> + string(4) "Five" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "Two" + [1]=> + string(5) "Three" + [2]=> + string(4) "Four" +} +array(0) { +} +array(1) { + [0]=> + string(3) "Two" +} +array(3) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" +} +array(0) { +} +array(2) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" +} +array(2) { + [0]=> + string(4) "Four" + [1]=> + string(4) "Five" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" + [3]=> + string(4) "Four" +} +array(0) { +} +array(1) { + [1]=> + string(3) "Two" +} +array(3) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" + [2]=> + string(5) "Three" +} +array(0) { +} +array(2) { + [0]=> + string(3) "One" + [1]=> + string(3) "Two" +} +array(2) { + [3]=> + string(4) "Four" + [4]=> + string(4) "Five" +} +array(0) { +} +array(0) { +} + +*** Iteration 4 *** + +*** Variation with first two Arguments *** +array(7) { + [0]=> + string(3) "six" + [1]=> + int(7) + [2]=> + string(5) "seven" + [3]=> + int(8) + [4]=> + string(5) "eight" + [5]=> + int(9) + [6]=> + string(4) "nine" +} +array(8) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) + [5]=> + string(5) "eight" + [6]=> + int(9) + [7]=> + string(4) "nine" +} +array(2) { + [0]=> + int(9) + [1]=> + string(4) "nine" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "six" + [1]=> + int(7) + [2]=> + string(5) "seven" +} +array(0) { +} +array(4) { + [0]=> + string(3) "six" + [1]=> + int(7) + [2]=> + string(5) "seven" + [3]=> + int(8) +} +array(3) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) +} +array(0) { +} +array(5) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) +} +array(2) { + [0]=> + int(9) + [1]=> + string(4) "nine" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" +} +array(0) { +} +array(4) { + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) +} +array(3) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) +} +array(0) { +} +array(5) { + [0]=> + int(6) + [1]=> + string(3) "six" + [2]=> + int(7) + [3]=> + string(5) "seven" + [4]=> + int(8) +} +array(2) { + [6]=> + int(9) + [7]=> + string(4) "nine" +} +array(0) { +} +array(0) { +} + +*** Iteration 5 *** + +*** Variation with first two Arguments *** +array(4) { + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(5) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(2) { + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} + +*** Variation with first three Arguments *** +array(3) { + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" +} +array(0) { +} +array(1) { + ["A"]=> + string(3) "AAA" +} +array(3) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" +} +array(0) { +} +array(2) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" +} +array(2) { + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" + ["d"]=> + string(3) "ddd" +} +array(0) { +} +array(1) { + ["A"]=> + string(3) "AAA" +} +array(3) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" + ["c"]=> + string(3) "ccc" +} +array(0) { +} +array(2) { + ["a"]=> + string(3) "aaa" + ["A"]=> + string(3) "AAA" +} +array(2) { + ["d"]=> + string(3) "ddd" + ["e"]=> + string(3) "eee" +} +array(0) { +} +array(0) { +} + +*** Iteration 6 *** + +*** Variation with first two Arguments *** +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "four" + [3]=> + string(4) "five" +} +array(5) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(4) "four" + [4]=> + string(4) "five" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "four" +} +array(0) { +} +array(1) { + [0]=> + string(3) "two" +} +array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" +} +array(0) { +} +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [2]=> + string(3) "two" + [3]=> + string(5) "three" + [4]=> + string(4) "four" +} +array(0) { +} +array(1) { + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +array(0) { +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(2) { + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Iteration 7 *** + +*** Variation with first two Arguments *** +array(4) { + [0]=> + string(3) "two" + [1]=> + int(7) + [2]=> + string(4) "four" + [3]=> + string(4) "five" +} +array(5) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + int(7) + [3]=> + string(4) "four" + [4]=> + string(4) "five" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "two" + [1]=> + int(7) + [2]=> + string(4) "four" +} +array(0) { +} +array(1) { + [0]=> + string(3) "two" +} +array(3) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + int(7) +} +array(0) { +} +array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" +} +array(2) { + [0]=> + string(4) "four" + [1]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [2]=> + string(3) "two" + [3]=> + int(7) + [4]=> + string(4) "four" +} +array(0) { +} +array(1) { + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(7) +} +array(0) { +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(2) { + [4]=> + string(4) "four" + [5]=> + string(4) "five" +} +array(0) { +} +array(0) { +} + +*** Iteration 8 *** + +*** Variation with first two Arguments *** +array(9) { + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [4]=> + string(4) "Five" + [5]=> + float(8.6) +} +array(10) { + ["f"]=> + string(3) "fff" + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" + [3]=> + float(3.7) + [4]=> + string(4) "Five" + [5]=> + float(8.6) +} +array(2) { + [0]=> + string(4) "Five" + [1]=> + float(8.6) +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" +} +array(0) { +} +array(6) { + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(3) { + ["f"]=> + string(3) "fff" + [0]=> + string(3) "one" + [1]=> + int(6) +} +array(0) { +} +array(7) { + ["f"]=> + string(3) "fff" + [0]=> + string(3) "one" + [1]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(2) { + [0]=> + string(4) "Five" + [1]=> + float(8.6) +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + string(5) "blank" +} +array(0) { +} +array(6) { + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(3) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) +} +array(0) { +} +array(7) { + ["f"]=> + string(3) "fff" + [1]=> + string(3) "one" + [4]=> + int(6) + [""]=> + string(5) "blank" + [2]=> + string(5) "float" + ["F"]=> + string(3) "FFF" + ["blank"]=> + string(0) "" +} +array(2) { + [5]=> + string(4) "Five" + [6]=> + float(8.6) +} +array(0) { +} +array(0) { +} + +*** Iteration 9 *** + +*** Variation with first two Arguments *** +array(3) { + [0]=> + string(4) "name" + [1]=> + string(3) "age" + [2]=> + string(2) "45" +} +array(4) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} +array(2) { + [0]=> + string(3) "age" + [1]=> + string(2) "45" +} + +*** Variation with first three Arguments *** +array(3) { + [0]=> + string(4) "name" + [1]=> + string(3) "age" + [2]=> + string(2) "45" +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" +} +array(0) { +} +array(1) { + [0]=> + int(12) +} +array(2) { + [0]=> + string(3) "age" + [1]=> + string(2) "45" +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(3) { + [1]=> + string(4) "name" + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + int(12) + [1]=> + string(4) "name" + [2]=> + string(3) "age" +} +array(0) { +} +array(1) { + [0]=> + int(12) +} +array(2) { + [2]=> + string(3) "age" + [3]=> + string(2) "45" +} +array(0) { +} +array(0) { +} + +*** Iteration 10 *** + +*** Variation with first two Arguments *** +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} + +*** Variation with first three Arguments *** +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(2) { + [0]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [1]=> + array(0) { + } +} +array(0) { +} +array(0) { +} + +*** Variation with first two arguments with preserve_key value TRUE *** +array(2) { + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(3) { + [0]=> + array(3) { + [0]=> + string(3) "oNe" + [1]=> + string(3) "tWo" + [2]=> + int(4) + } + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} +array(2) { + [1]=> + array(5) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + [3]=> + int(40) + [4]=> + int(50) + } + [2]=> + array(0) { + } +} +array(0) { +} +array(0) { +} + +*** Typical Variation of offset and length Arguments *** +array(1) { + [1]=> + string(3) "Two" +} +array(1) { + [0]=> + string(3) "Two" +} +array(1) { + [2]=> + string(5) "Three" +} +array(1) { + [0]=> + string(5) "Three" +} diff --git a/ext/standard/tests/array/array_slice_basic.phpt b/ext/standard/tests/array/array_slice_basic.phpt new file mode 100644 index 0000000..a4cbe46 --- /dev/null +++ b/ext/standard/tests/array/array_slice_basic.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_slice() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_slice() + */ + +echo "*** Testing array_slice() : basic functionality ***\n"; + + +$input = array('one' => 1, 'two' => 2, 3, 23 => 4); +$offset = 2; +$length = 2; +$preserve_keys = true; + +// Calling array_slice() with all possible arguments +echo "\n-- All arguments --\n"; +var_dump( array_slice($input, $offset, $length, $preserve_keys) ); + +// Calling array_slice() with mandatory arguments +echo "\n-- Mandatory arguments --\n"; +var_dump( array_slice($input, $offset) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : basic functionality *** + +-- All arguments -- +array(2) { + [0]=> + int(3) + [23]=> + int(4) +} + +-- Mandatory arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_error.phpt b/ext/standard/tests/array/array_slice_error.phpt new file mode 100644 index 0000000..0e8f1c7 --- /dev/null +++ b/ext/standard/tests/array/array_slice_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_slice() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass an incorrect number of arguments to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : error conditions ***\n"; + +//Test array_slice with one more than the expected number of arguments +echo "\n-- Testing array_slice() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$offset = 10; +$length = 10; +$preserve_keys = true; +$extra_arg = 10; +var_dump( array_slice($input, $offset, $length, $preserve_keys, $extra_arg) ); + +// Testing array_slice with one less than the expected number of arguments +echo "\n-- Testing array_slice() function with less than expected no. of arguments --\n"; +var_dump( array_slice($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_slice() : error conditions *** + +-- Testing array_slice() function with more than expected no. of arguments -- + +Warning: array_slice() expects at most 4 parameters, 5 given in %s on line %d +NULL + +-- Testing array_slice() function with less than expected no. of arguments -- + +Warning: array_slice() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation1.phpt b/ext/standard/tests/array/array_slice_variation1.phpt new file mode 100644 index 0000000..daed1d8 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation1.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test array_slice() - Third parameter (NULL vs 0) +--FILE-- +<?php + +var_dump(array_slice(range(1, 3), 0, NULL, 1)); +var_dump(array_slice(range(1, 3), 0, 0, 1)); +var_dump(array_slice(range(1, 3), 0, NULL)); +var_dump(array_slice(range(1, 3), 0, 0)); + +var_dump(array_slice(range(1, 3), -1, 0)); +var_dump(array_slice(range(1, 3), -1, 0, 1)); +var_dump(array_slice(range(1, 3), -1, NULL)); +var_dump(array_slice(range(1, 3), -1, NULL, 1)); + + +$a = 'foo'; +var_dump(array_slice(range(1, 3), 0, $a)); +var_dump(array_slice(range(1, 3), 0, $a)); +var_dump($a); + +?> + +--EXPECTF-- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +array(0) { +} +array(0) { +} +array(1) { + [0]=> + int(3) +} +array(1) { + [2]=> + int(3) +} +array(0) { +} +array(0) { +} +string(3) "foo" diff --git a/ext/standard/tests/array/array_slice_variation10.phpt b/ext/standard/tests/array/array_slice_variation10.phpt new file mode 100644 index 0000000..85c521d --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation10.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_slice() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Check position of internal array pointer after calling array_slice() + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 23 => 'twenty-three', 'zero'); + +echo "\n-- Call array_slice() --\n"; +var_dump($result = array_slice($input, 2)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Call array_slice() -- +array(2) { + [0]=> + string(12) "twenty-three" + [1]=> + string(4) "zero" +} +-- Position of Internal Pointer in Result: -- +0 => twenty-three + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation11.phpt b/ext/standard/tests/array/array_slice_variation11.phpt new file mode 100644 index 0000000..4c7a148 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation11.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $input arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different arguments as $input argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$offset = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input, $offset) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_slice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_slice() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_slice() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_slice() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_slice() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_slice() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_slice() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation2.phpt b/ext/standard/tests/array/array_slice_variation2.phpt new file mode 100644 index 0000000..217788f --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation2.phpt @@ -0,0 +1,311 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $offset arg +--SKIPIF-- +<?php if (PHP_INT_SIZE > 4) die("skip this test is for 32bit platform only"); ?> +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $offset argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$input_array = array('one' => 1, 2, 'three' => 3, 4); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $offset argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input_array, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 2 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 3 -- +array(0) { +} + +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 5 -- +array(0) { +} + +-- Iteration 6 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 7 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 8 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 9 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 10 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 11 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 12 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 13 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 14 -- +array(3) { + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 15 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 16 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_slice() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_slice() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 22 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} + +-- Iteration 23 -- +array(4) { + ["one"]=> + int(1) + [0]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation3.phpt b/ext/standard/tests/array/array_slice_variation3.phpt new file mode 100644 index 0000000..bdcb759 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation3.phpt @@ -0,0 +1,213 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $length arg +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $length argument to array_slice to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$input_array = array('one' => 1, 2, 'three' => 3, 4); +$offset = 2; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $length argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_slice +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input_array, $offset, $input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(0) { +} + +-- Iteration 2 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 3 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 4 -- +array(0) { +} + +-- Iteration 5 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 6 -- +array(0) { +} + +-- Iteration 7 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 8 -- +array(0) { +} + +-- Iteration 9 -- +array(0) { +} + +-- Iteration 10 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 11 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 12 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 13 -- +array(0) { +} + +-- Iteration 14 -- +array(1) { + ["three"]=> + int(3) +} + +-- Iteration 15 -- +array(0) { +} + +-- Iteration 16 -- +array(0) { +} + +-- Iteration 17 -- +array(0) { +} + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- +array(0) { +} + +-- Iteration 20 -- +array(0) { +} + +-- Iteration 21 -- +array(0) { +} + +-- Iteration 22 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} + +-- Iteration 23 -- +array(2) { + ["three"]=> + int(3) + [0]=> + int(4) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation4.phpt b/ext/standard/tests/array/array_slice_variation4.phpt new file mode 100644 index 0000000..f093d2d --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation4.phpt @@ -0,0 +1,327 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $preserve_keys arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $preserve_keys argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$input_array = array('one' => 1, 2, 99 => 3, 4); +$offset = 0; +$length = 3; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed to $preserve_keys argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_slice($input_array, $offset, $length, $input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 2 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 3 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 4 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 5 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 6 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 7 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 8 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 10 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 11 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 14 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 15 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 16 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 17 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 18 -- + +Warning: array_slice() expects parameter 4 to be boolean, array given in %s on line %d +NULL + +-- Iteration 19 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 20 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 21 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [99]=> + int(3) +} + +-- Iteration 22 -- + +Warning: array_slice() expects parameter 4 to be boolean, object given in %s on line %d +NULL + +-- Iteration 23 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} + +-- Iteration 24 -- +array(3) { + ["one"]=> + int(1) + [0]=> + int(2) + [1]=> + int(3) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation5.phpt b/ext/standard/tests/array/array_slice_variation5.phpt new file mode 100644 index 0000000..ed5c82f --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation5.phpt @@ -0,0 +1,191 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different integers as $offset argument +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different integers as $offset argument to test how array_slice() behaves + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); + +for ($i = -7; $i <= 7; $i++) { + echo "\n-- \$offset is $i --\n"; + var_dump(array_slice($input, $i)); +} +echo "\n-- \$offset is maximum integer value --\n"; +var_dump(array_slice($input, PHP_INT_MAX)); + +echo "\n-- \$offset is minimum integer value --\n"; +var_dump(array_slice($input, -PHP_INT_MAX)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- $offset is -7 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -6 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -5 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -3 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -2 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is -1 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 0 -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 1 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 2 -- +array(3) { + [0]=> + string(5) "three" + [1]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 3 -- +array(2) { + [0]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $offset is 4 -- +array(1) { + ["ten"]=> + int(10) +} + +-- $offset is 5 -- +array(0) { +} + +-- $offset is 6 -- +array(0) { +} + +-- $offset is 7 -- +array(0) { +} + +-- $offset is maximum integer value -- +array(0) { +} + +-- $offset is minimum integer value -- +array(5) { + ["one"]=> + int(1) + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation6.phpt b/ext/standard/tests/array/array_slice_variation6.phpt new file mode 100644 index 0000000..e32abfc --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation6.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test array_slice() function : usage variations - pass different int values as $length arg +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different integer values as $length argument to array_slice() to test behaviour + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('one' => 1, 2 => 'two', 'three', 9 => 'nine', 'ten' => 10); +$offset = 1; + +for ($i = -6; $i <= 6; $i++) { + echo "\n-- \$length is $i --\n"; + var_dump(array_slice($input, $offset, $i)); +} +echo "\n-- \$length is maximum integer value --\n"; +var_dump(array_slice($input, $offset, PHP_INT_MAX)); + +echo "\n-- \$length is minimum integer value --\n"; +var_dump(array_slice($input, $offset, -PHP_INT_MAX)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- $length is -6 -- +array(0) { +} + +-- $length is -5 -- +array(0) { +} + +-- $length is -4 -- +array(0) { +} + +-- $length is -3 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is -2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is -1 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 0 -- +array(0) { +} + +-- $length is 1 -- +array(1) { + [0]=> + string(3) "two" +} + +-- $length is 2 -- +array(2) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" +} + +-- $length is 3 -- +array(3) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" +} + +-- $length is 4 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 5 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is 6 -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is maximum integer value -- +array(4) { + [0]=> + string(3) "two" + [1]=> + string(5) "three" + [2]=> + string(4) "nine" + ["ten"]=> + int(10) +} + +-- $length is minimum integer value -- +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_slice_variation7.phpt b/ext/standard/tests/array/array_slice_variation7.phpt new file mode 100644 index 0000000..abf517d --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation7.phpt @@ -0,0 +1,300 @@ +--TEST-- +Test array_slice() function : usage variations - different data types as keys in an array +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as keys in an array to array_slice() + * to test how $preserve_keys treats them + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$offset = 0; +$length = 10; // to ensure all elements are displayed + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_slice() +$iterator = 1; +foreach($inputs as $type => $input) { + echo "\n-- Iteration $iterator : key type is $type --\n"; + echo "\$preserve_keys = TRUE\n"; + var_dump( array_slice($input, $offset, $length, true) ); + echo "\$preserve_keys = FALSE\n"; + var_dump( array_slice($input, $offset, $length, false) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Iteration 1 : key type is int -- +$preserve_keys = TRUE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [-2345]=> + string(8) "negative" +} +$preserve_keys = FALSE +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2 : key type is float -- +$preserve_keys = TRUE +array(3) { + [10]=> + string(8) "positive" + [-10]=> + string(8) "negative" + [0]=> + string(4) "half" +} +$preserve_keys = FALSE +array(3) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3 : key type is extreme floats -- +$preserve_keys = TRUE +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4 : key type is null uppercase -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "null 1" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 : key type is null lowercase -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "null 2" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 : key type is bool lowercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "lowert" + [0]=> + string(6) "lowerf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7 : key type is bool uppercase -- +$preserve_keys = TRUE +array(2) { + [1]=> + string(6) "uppert" + [0]=> + string(6) "upperf" +} +$preserve_keys = FALSE +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8 : key type is empty double quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptyd" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 : key type is empty single quotes -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(6) "emptys" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 : key type is string -- +$preserve_keys = TRUE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} +$preserve_keys = FALSE +array(3) { + ["stringd"]=> + string(7) "stringd" + ["strings"]=> + string(7) "strings" + ["hello world"]=> + string(7) "stringh" +} + +-- Iteration 11 : key type is undefined -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(9) "undefined" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 : key type is unset -- +$preserve_keys = TRUE +array(1) { + [""]=> + string(5) "unset" +} +$preserve_keys = FALSE +array(1) { + [""]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation8.phpt b/ext/standard/tests/array/array_slice_variation8.phpt new file mode 100644 index 0000000..aece410 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation8.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_slice() function : usage variations - multidimensional arrays +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Test array_slice when passed + * 1. a two-dimensional array as $input argument + * 2. a sub-array as $input argument + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$input = array ('zero', 'one', array('zero', 'un', 'deux'), 9 => 'nine'); + +echo "\n-- Slice a two-dimensional array --\n"; +var_dump(array_slice($input, 1, 3)); + +echo "\n-- \$input is a sub-array --\n"; +var_dump(array_slice($input[2], 1, 2)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Slice a two-dimensional array -- +array(3) { + [0]=> + string(3) "one" + [1]=> + array(3) { + [0]=> + string(4) "zero" + [1]=> + string(2) "un" + [2]=> + string(4) "deux" + } + [2]=> + string(4) "nine" +} + +-- $input is a sub-array -- +array(2) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_slice_variation9.phpt b/ext/standard/tests/array/array_slice_variation9.phpt new file mode 100644 index 0000000..7ae9238 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation9.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_slice() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : array array_slice(array $input, int $offset [, int $length [, bool $preserve_keys]]) + * Description: Returns elements specified by offset and length + * Source code: ext/standard/array.c + */ + +/* + * Test array_slice() when: + * 1. Passed an array of referenced variables + * 2. $input argument is passed by reference + */ + +echo "*** Testing array_slice() : usage variations ***\n"; + +$val1 = 'one'; +$val2 = 'two'; +$val3 = 'three'; + +echo "\n-- Array of referenced variables (\$preserve_keys = default) --\n"; +$input = array(3 => &$val1, 2 => &$val2, 1 => &$val3); +var_dump(array_slice($input, 1, 2)); + +echo "-- Change \$val2 (\$preserve_keys = TRUE) --\n"; +$val2 = 'hello, world'; +var_dump(array_slice($input, 1, 2, true)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_slice() : usage variations *** + +-- Array of referenced variables ($preserve_keys = default) -- +array(2) { + [0]=> + &string(3) "two" + [1]=> + &string(5) "three" +} +-- Change $val2 ($preserve_keys = TRUE) -- +array(2) { + [2]=> + &string(12) "hello, world" + [1]=> + &string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_splice_basic.phpt b/ext/standard/tests/array/array_splice_basic.phpt new file mode 100644 index 0000000..e96303d --- /dev/null +++ b/ext/standard/tests/array/array_splice_basic.phpt @@ -0,0 +1,117 @@ +--TEST-- +Test array_splice(): basic functionality +--FILE-- +<?php +/* + * proto array array_splice(array input, int offset [, int length [, array replacement]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "*** Testing array_splice() basic operations ***\n"; +echo "test truncation \n"; +$input = array("red", "green", "blue", "yellow"); +var_dump (array_splice($input, 2)); +var_dump ($input); +// $input is now array("red", "green") + +echo "test removing entries from the middle \n"; +$input = array("red", "green", "blue", "yellow"); +var_dump (array_splice($input, 1, -1)); +var_dump ($input); +// $input is now array("red", "yellow") + +echo "test substitution at end \n"; +$input = array("red", "green", "blue", "yellow"); +var_dump (array_splice($input, 1, count($input), "orange")); +var_dump ($input); +// $input is now array("red", "orange") + +$input = array("red", "green", "blue", "yellow"); +var_dump (array_splice($input, -1, 1, array("black", "maroon"))); +var_dump ($input); +// $input is now array("red", "green", +// "blue", "black", "maroon") + +echo "test insertion \n"; +$input = array("red", "green", "blue", "yellow"); +var_dump (array_splice($input, 3, 0, "purple")); +var_dump ($input); +// $input is now array("red", "green", +// "blue", "purple", "yellow"); + + +?> +--EXPECT-- +*** Testing array_splice() basic operations *** +test truncation +array(2) { + [0]=> + string(4) "blue" + [1]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" +} +test removing entries from the middle +array(2) { + [0]=> + string(5) "green" + [1]=> + string(4) "blue" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(6) "yellow" +} +test substitution at end +array(3) { + [0]=> + string(5) "green" + [1]=> + string(4) "blue" + [2]=> + string(6) "yellow" +} +array(2) { + [0]=> + string(3) "red" + [1]=> + string(6) "orange" +} +array(1) { + [0]=> + string(6) "yellow" +} +array(5) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" + [2]=> + string(4) "blue" + [3]=> + string(5) "black" + [4]=> + string(6) "maroon" +} +test insertion +array(0) { +} +array(5) { + [0]=> + string(3) "red" + [1]=> + string(5) "green" + [2]=> + string(4) "blue" + [3]=> + string(6) "purple" + [4]=> + string(6) "yellow" +} diff --git a/ext/standard/tests/array/array_splice_errors.phpt b/ext/standard/tests/array/array_splice_errors.phpt new file mode 100644 index 0000000..0d4e8da --- /dev/null +++ b/ext/standard/tests/array/array_splice_errors.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_splice() function : error conditions +--FILE-- +<?php +/* + * proto array array_splice(array input, int offset [, int length [, array replacement]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing error conditions of array_splice() ***\n"; + +$int=1; +$array=array(1,2); +var_dump (array_splice()); +var_dump (array_splice($int)); +var_dump (array_splice($array)); +var_dump (array_splice($int,$int)); +$obj= new stdclass; +var_dump (array_splice($obj,0,1)); +echo "Done\n"; + +?> +--EXPECTF-- + +*** Testing error conditions of array_splice() *** + +Warning: array_splice() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: array_splice() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: array_splice() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: array_splice() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_splice() expects parameter 1 to be array, object given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_splice_variation1.phpt b/ext/standard/tests/array/array_splice_variation1.phpt new file mode 100644 index 0000000..9ba94f6 --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation1.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_splice() function : usage variations - references +--FILE-- +<?php +/* + * proto array array_splice(array input, int offset [, int length [, array replacement]]) + * Function is implemented in ext/standard/array.c +*/ + + +echo "test behaviour when input array is in a reference set\n"; + +$input_array=array (array(1,2)); +$input_array[]=&$input_array[0]; +var_dump (array_splice ($input_array[0],1,1)); +var_dump ($input_array); + +echo "Test behaviour of input arrays containing references \n"; +/* + * There are three regions to test:, before cut, the cut and after the cut. + * For reach we check a plain value, a reference value with integer key and a + * reference value with a string key. + */ +$numbers=array(0,1,2,3,4,5,6,7,8,9,10,11,12); +$input_array=array(0,1,&$numbers[2],"three"=>&$numbers[3],4,&$numbers[5],"six"=>&$numbers[6],7,&$numbers[8],"nine"=>&$numbers[9]); +var_dump (array_splice ($input_array,4,3)); +var_dump ($input_array); + +echo "Test behaviour of replacement array containing references \n"; + +$three=3; +$four=4; +$input_array=array (0,1,2); +$b=array(&$three,"fourkey"=>&$four); +array_splice ($input_array,-1,1,$b); +var_dump ($input_array); + +echo "Test behaviour of replacement which is part of reference set \n"; + +$int=3; +$input_array=array (1,2); +$b=&$int; + +array_splice ($input_array,-1,1,$b); +var_dump ($input_array); +echo "Done\n"; +?> +--EXPECT-- +test behaviour when input array is in a reference set +array(1) { + [0]=> + int(2) +} +array(2) { + [0]=> + &array(1) { + [0]=> + int(1) + } + [1]=> + &array(1) { + [0]=> + int(1) + } +} +Test behaviour of input arrays containing references +array(3) { + [0]=> + int(4) + [1]=> + &int(5) + ["six"]=> + &int(6) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + &int(2) + ["three"]=> + &int(3) + [3]=> + int(7) + [4]=> + &int(8) + ["nine"]=> + &int(9) +} +Test behaviour of replacement array containing references +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + &int(3) + [3]=> + &int(4) +} +Test behaviour of replacement which is part of reference set +array(2) { + [0]=> + int(1) + [1]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_splice_variation2.phpt b/ext/standard/tests/array/array_splice_variation2.phpt new file mode 100644 index 0000000..516339c --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation2.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test array_splice() function : usage variations - additional parameters +--FILE-- +<?php +/* + * proto array array_splice(array input, int offset [, int length [, array replacement]]) + * Function is implemented in ext/standard/array.c +*/ + +$array=array(0,1,2); +var_dump (array_splice($array,1,1,3,4,5,6,7,8,9)); +var_dump ($array); +echo "Done\n"; +?> +--EXPECTF-- + +Warning: array_splice() expects at most 4 parameters, 10 given in %s on line %d +NULL +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_splice_variation3.phpt b/ext/standard/tests/array/array_splice_variation3.phpt new file mode 100644 index 0000000..33ec80e --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation3.phpt @@ -0,0 +1,856 @@ +--TEST-- +Test array_splice() function : usage variations - lengths and offsets +--FILE-- +<?php +/* + * proto array array_splice(array input, int offset [, int length [, array replacement]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "*** array_splice() function : usage variations - lengths and offsets\n"; + + +function test_splice ($offset, $length) +{ + echo " - No replacement\n"; + $input_array=array(0,1,2,3,4,5); + var_dump (array_splice ($input_array,$offset,$length)); + var_dump ($input_array); + echo " - With replacement\n"; + $input_array=array(0,1,2,3,4,5); + var_dump (array_splice ($input_array,$offset,$length,array ("A","B","C"))); + var_dump ($input_array); +} + +echo "absolute offset - absolute length - cut from beginning\n"; +test_splice (0,2); +echo "absolute offset - absolute length - cut from middle\n"; +test_splice (2,2); +echo "absolute offset - absolute length - cut from end\n"; +test_splice (4,2); +echo "absolute offset - absolute length - attempt to cut past end\n"; +test_splice (4,4); +echo "absolute offset - absolute length - cut everything\n"; +test_splice (0,7); +echo "absolute offset - absolute length - cut nothing\n"; +test_splice (3,0); + +echo "absolute offset - relative length - cut from beginning\n"; +test_splice (0,-4); + +echo "absolute offset - relative length - cut from middle\n"; +test_splice (2,-2); + +echo "absolute offset - relative length - attempt to cut form before beginning \n"; +test_splice (0,-7); + +echo "absolute offset - relative length - cut nothing\n"; +test_splice (2,-7); + +echo "relative offset - absolute length - cut from beginning\n"; +test_splice (-6,2); + +echo "relative offset - absolute length - cut from middle\n"; +test_splice (-4,2); +echo "relative offset - absolute length - cut from end\n"; +test_splice (-2,2); +echo "relative offset - absolute length - attempt to cut past end\n"; +test_splice (-2,4); +echo "relative offset - absolute length - cut everything\n"; +test_splice (-6,6); +echo "relative offset - absolute length - cut nothing\n"; +test_splice (-6,0); + +echo "relative offset - relative length - cut from beginning\n"; +test_splice (-6,-4); + +echo "relative offset - relative length - cut from middle\n"; +test_splice (-4,-2); + +echo "relative offset - relative length - cut nothing\n"; +test_splice (-4,-7); +echo "Done\n"; +?> + +--EXPECT-- +*** array_splice() function : usage variations - lengths and offsets +absolute offset - absolute length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - absolute length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - absolute length - cut from end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +absolute offset - absolute length - attempt to cut past end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +absolute offset - absolute length - cut everything + - No replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(0) { +} + - With replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" +} +absolute offset - absolute length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + string(1) "A" + [4]=> + string(1) "B" + [5]=> + string(1) "C" + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +absolute offset - relative length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - relative length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +absolute offset - relative length - attempt to cut form before beginning + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(0) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +absolute offset - relative length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +relative offset - absolute length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - absolute length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - absolute length - cut from end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +relative offset - absolute length - attempt to cut past end + - No replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) +} + - With replacement +array(2) { + [0]=> + int(4) + [1]=> + int(5) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + string(1) "A" + [5]=> + string(1) "B" + [6]=> + string(1) "C" +} +relative offset - absolute length - cut everything + - No replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(0) { +} + - With replacement +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} +array(3) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" +} +relative offset - absolute length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(0) + [4]=> + int(1) + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +relative offset - relative length - cut from beginning + - No replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(4) { + [0]=> + int(2) + [1]=> + int(3) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} +array(7) { + [0]=> + string(1) "A" + [1]=> + string(1) "B" + [2]=> + string(1) "C" + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - relative length - cut from middle + - No replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(4) + [3]=> + int(5) +} + - With replacement +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(7) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(4) + [6]=> + int(5) +} +relative offset - relative length - cut nothing + - No replacement +array(0) { +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(4) + [5]=> + int(5) +} + - With replacement +array(0) { +} +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + string(1) "A" + [3]=> + string(1) "B" + [4]=> + string(1) "C" + [5]=> + int(2) + [6]=> + int(3) + [7]=> + int(4) + [8]=> + int(5) +} +Done diff --git a/ext/standard/tests/array/array_splice_variation4.phpt b/ext/standard/tests/array/array_splice_variation4.phpt new file mode 100644 index 0000000..d1cc501 --- /dev/null +++ b/ext/standard/tests/array/array_splice_variation4.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test array_splice() function : usage variations - non array replacement values +--FILE-- +<?php +/* + * proto array array_splice(array input, int offset [, int length [, array replacement]]) + * Function is implemented in ext/standard/array.c +*/ + +function test_splice ($replacement) +{ + $input_array=array(0,1); + var_dump (array_splice ($input_array,2,0,$replacement)); + var_dump ($input_array); +} + +test_splice (2); + +test_splice (2.1); + +test_splice (true); +//file type resource +$file_handle = fopen(__FILE__, "r"); + +test_splice ($file_handle); +echo "Done\n"; +?> +--EXPECTF-- +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + float(2.1) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + bool(true) +} +array(0) { +} +array(3) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + resource(%d) of type (stream) +} +Done diff --git a/ext/standard/tests/array/array_sum.phpt b/ext/standard/tests/array/array_sum.phpt new file mode 100644 index 0000000..08aec21 --- /dev/null +++ b/ext/standard/tests/array/array_sum.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_sum() +--INI-- +precision=14 +memory_limit=128M +--FILE-- +<?php +$i = 0; +while ($i++ < 1000) { + $a[] = $i; + $b[] = (string)$i; +} +$s1 = array_sum($a); +$s2 = array_sum($b); +var_dump($s1, $s2); + +$j = 0; +while ($j++ < 100000) { + $c[] = $j; + $d[] = (string) $j; +} +$s3 = array_sum($c); +$s4 = array_sum($d); +var_dump($s3, $s4); +?> +--EXPECTF-- +int(500500) +int(500500) +%st(5000050000) +%st(5000050000) diff --git a/ext/standard/tests/array/array_sum_basic.phpt b/ext/standard/tests/array/array_sum_basic.phpt new file mode 100644 index 0000000..c178853 --- /dev/null +++ b/ext/standard/tests/array/array_sum_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_sum() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_sum() : basic functionality ***\n"; + +// array with integer values +$input = array(1, 2, 3, 4, 5); +echo "-- array_sum() with integer array entries --\n"; +var_dump( array_sum($input) ); + +// array with float values +$input = array(1.0, 2.2, 3.4, 4.6); +echo "-- array_sum() with float array entries --\n"; +var_dump( array_sum($input) ); + +// array with integer and float values +$input = array(1, 2.3, 4, 0.6, 10); +echo "-- array_sum() with integer/float array entries --\n"; +var_dump( array_sum($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : basic functionality *** +-- array_sum() with integer array entries -- +int(15) +-- array_sum() with float array entries -- +float(11.2) +-- array_sum() with integer/float array entries -- +float(17.9) +Done diff --git a/ext/standard/tests/array/array_sum_error.phpt b/ext/standard/tests/array/array_sum_error.phpt new file mode 100644 index 0000000..209405d --- /dev/null +++ b/ext/standard/tests/array/array_sum_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_sum() function : error conditions +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_sum() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_sum() function with zero arguments --\n"; +var_dump( array_sum() ); + +// One more than the expected number of arguments +echo "-- Testing array_sum() function with more than expected no. of arguments --\n"; +$input = array(1, 2, 3, 4); +$extra_arg = 10; +var_dump( array_sum($input, $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : error conditions *** +-- Testing array_sum() function with zero arguments -- + +Warning: array_sum() expects exactly 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_sum() function with more than expected no. of arguments -- + +Warning: array_sum() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_sum_variation1.phpt b/ext/standard/tests/array/array_sum_variation1.phpt new file mode 100644 index 0000000..f551375 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation1.phpt @@ -0,0 +1,179 @@ +--TEST-- +Test array_sum() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Passing different scalar/nonscalar values as 'input' argument to array_sum() +*/ + +echo "*** Testing array_sum() : unexpected values for 'input' ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Class definition +class MyClass +{ + public function __toString() + { + return "object"; + } +} + +// different scalar/non scalar values for 'input' argument +$input_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new MyClass(), + + // resource data +/*21*/ $fp = fopen(__FILE__,'r'), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, +); + +// loop through each element of the array for input +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_sum($input_values[$count]) ); +}; + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_sum() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_sum() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_sum_variation2.phpt b/ext/standard/tests/array/array_sum_variation2.phpt new file mode 100644 index 0000000..a697a15 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation2.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_sum() function : usage variations - array with different integer value +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with different types of integer arrays containing data of following type: +* integer, octal, hexadecimal, maximum and minimum integer values & mixed of all integers +*/ + +echo "*** Testing array_sum() : different integer array ***\n"; + +// Int array +$int_values = array(3, 2, 100, 150, 25, 350, 0, -3, -1200); +echo "-- Sum of Integer array --\n"; +var_dump( array_sum($int_values) ); + +// Octal array +$octal_values = array(056, 023, 090, 015, -045, 01, -078); +echo "-- Sum of Octal array --\n"; +var_dump( array_sum($octal_values) ); + +// Hexadecimal array +$hex_values = array(0xAE, 0x2B, 0X10, -0xCF, 0X12, -0XF2); +echo "-- Sum of Hex array --\n"; +var_dump( array_sum($hex_values) ); + +// Mixed values int, octal & hex +$mixed_int_value = array(2, 5, -1, 054, 0X3E, 0, -014, -0x2A); +echo "-- Sum of mixed integer values --\n"; +var_dump( array_sum($mixed_int_value) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : different integer array *** +-- Sum of Integer array -- +int(-573) +-- Sum of Octal array -- +int(35) +-- Sum of Hex array -- +int(-198) +-- Sum of mixed integer values -- +int(58) +Done diff --git a/ext/standard/tests/array/array_sum_variation3.phpt b/ext/standard/tests/array/array_sum_variation3.phpt new file mode 100644 index 0000000..9d32c2c --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation3.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_sum() function : usage variations - array with different float values +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* + * sum of array containing different float values +*/ + +echo "*** Testing array_sum() : array with different float values ***\n"; + +// Simple float array +$float_input = array( 1.1, 2.3, 0.0, 0.5, -2.3, -0.8, .5); +echo "-- simple float array --\n"; +var_dump( array_sum($float_input) ); + +// float array with scientific notations +$float_input = array( 1.2e2, 23.4e3, -4.1e2, 0.2e2, 2.1e-2, .5e3); +echo "-- float array with scientific notations e and E --\n"; +var_dump( array_sum($float_input) ); +$float_input = array( 1.2E2, 23.4E3, -4.1E2, 0.2E2, 2.1E-2, .5E3); +var_dump( array_sum($float_input) ); + +// Mixed float array +$float_input = array( + 1.2, + 0.5 + -5.8, + 6.334, + -0.65, + 1.2e3, + -2.3e2, + 5.56E3, + -3.82E-2 +); +echo "-- Mixed float array --\n"; +var_dump( array_sum($float_input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with different float values *** +-- simple float array -- +float(1.3) +-- float array with scientific notations e and E -- +float(23630.021) +float(23630.021) +-- Mixed float array -- +float(6531.5458) +Done diff --git a/ext/standard/tests/array/array_sum_variation4.phpt b/ext/standard/tests/array/array_sum_variation4.phpt new file mode 100644 index 0000000..4959dee --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation4.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_sum() function : usage variations - array with duplicate values +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Checking array_sum() with integer and float array containing duplicate values +*/ + +echo "*** Testing array_sum() : array with duplicate values ***\n"; + +// integer array with duplicate values +$int_input = array( 2, 5, 7, 5, 0, -4, 2, 100); +echo "-- With integer array --\n"; +var_dump( array_sum($int_input) ); + +// float array with duplicate values +$float_input = array( 2.3, 1.9, -4.1, 0.5, 1.9, -4.1, 3.6, 0.5); +echo "-- With float array --\n"; +var_dump( array_sum($float_input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with duplicate values *** +-- With integer array -- +int(117) +-- With float array -- +float(2.5) +Done diff --git a/ext/standard/tests/array/array_sum_variation5.phpt b/ext/standard/tests/array/array_sum_variation5.phpt new file mode 100644 index 0000000..9068c45 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation5.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_sum() function : usage variations - array with reference variables as elements +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with 'input' having reference variables as elements +*/ + +echo "*** Testing array_sum() : array with elements as reference ***\n"; + +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// input array containing elements as reference variables +$input = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +var_dump( array_sum($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with elements as reference *** +int(305) +Done diff --git a/ext/standard/tests/array/array_sum_variation6.phpt b/ext/standard/tests/array/array_sum_variation6.phpt new file mode 100644 index 0000000..ba67cfd --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation6.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_sum() function : usage variations - associative array +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with associative array as 'input' argument +*/ + +echo "*** Testing array_sum() : with associative array ***\n"; + +// array with numeric keys +$input = array(0 => 1, 1 => 10, 2 => 0, 3 => -2, 4 => 23.56); +echo "-- with numeric keys --\n"; +var_dump( array_sum($input) ); + +// array with string keys +$input = array('a' => 20, "b" => 50, 'c' => 0, 'd' => -30, "e" => 100); +echo "-- with string keys --\n"; +var_dump( array_sum($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : with associative array *** +-- with numeric keys -- +float(32.56) +-- with string keys -- +int(140) +Done diff --git a/ext/standard/tests/array/array_sum_variation7.phpt b/ext/standard/tests/array/array_sum_variation7.phpt new file mode 100644 index 0000000..d309875 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation7.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test array_sum() function : usage variations - 'input' array with unexpected values as array element +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with array having other than numeric entries +* strings, bool, null, subarrays & objects +*/ + +echo "*** Testing array_sum() : array with unexpected entries ***\n"; + +// empty array +$input = array(); +echo "-- empty array --\n"; +var_dump( array_sum($input) ); + +// string array +$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange'); +echo "-- array with string values --\n"; +var_dump( array_sum($input) ); + +// bool array +$input = array( true, true, false, true, false); +echo "-- array with bool values --\n"; +var_dump( array_sum($input) ); + +// array with null entry +$input = array(null, NULL); +echo "-- array with null values --\n"; +var_dump( array_sum($input) ); + +// array with subarray +$input = array( + array(1, 2), + array(), + array(0) +); +echo "-- array with subarrays --\n"; +var_dump( array_sum($input) ); + +class MyClass +{ + public $value; + public function __construct($value) + { + $this->value = $value; + } +} +// array of objects +$input = array( + new MyClass(2), + new MyClass(5), + new MyClass(10), + new MyClass(0) +); +echo "-- array with object values --\n"; +var_dump( array_sum($input) ); + +// Mixed values +$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array())); +echo "-- array with mixed values --\n"; +var_dump( array_sum($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with unexpected entries *** +-- empty array -- +int(0) +-- array with string values -- +int(0) +-- array with bool values -- +int(3) +-- array with null values -- +int(0) +-- array with subarrays -- +int(0) +-- array with object values -- +int(0) +-- array with mixed values -- +float(14) +Done diff --git a/ext/standard/tests/array/array_udiff_assoc_basic.phpt b/ext/standard/tests/array/array_udiff_assoc_basic.phpt new file mode 100644 index 0000000..769bafb --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_udiff_assoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_udiff_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_assoc_error.phpt b/ext/standard/tests/array/array_udiff_assoc_error.phpt new file mode 100644 index 0000000..ec1cc06 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_udiff_assoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_assoc() : error conditions ***\n"; + +$arr1 = array(1, 2); +$arr2 = array(1, 2); +$extra_arg = 10; +include('compare_function.inc'); +$key_comp_func = 'compare_function'; + + +//Test array_udiff_assoc with one more than the expected number of arguments +echo "\n-- Testing array_udiff_assoc() function with more than expected no. of arguments --\n"; +var_dump( array_udiff_assoc($arr1, $arr2, $key_comp_func, $extra_arg) ); + +// Testing array_udiff_assoc with one less than the expected number of arguments +echo "\n-- Testing array_udiff_assoc() function with less than expected no. of arguments --\n"; +var_dump( array_udiff_assoc($arr1, $arr2) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : error conditions *** + +-- Testing array_udiff_assoc() function with more than expected no. of arguments -- + +Warning: array_udiff_assoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_assoc_error.php on line %d +NULL + +-- Testing array_udiff_assoc() function with less than expected no. of arguments -- + +Warning: array_udiff_assoc(): at least 3 parameters are required, 2 given in %sarray_udiff_assoc_error.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_assoc_variation.phpt b/ext/standard/tests/array/array_udiff_assoc_variation.phpt new file mode 100644 index 0000000..84e8841 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_variation.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_udiff_assoc() function : variation +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_assoc() : variation - testing with multiple array arguments ***\n"; + +include('compare_function.inc'); +$key_compare_function = 'compare_function'; + +// Initialise all required variables +$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 6.0 => 6, "seven" => "0x7"); +$arr2 = array("one" => "one", "02" => "two", '3' => "three"); +$arr3 = array("four", "0.5" => "five", 6 => 6, "seven" => 7); +$arr4 = array("four", "0.5" => "five", 6 => 6, "seven" => 7); + + +var_dump( array_udiff_assoc($arr1, $arr2, $arr3, $arr4, $key_compare_function) ); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : variation - testing with multiple array arguments *** +array(2) { + [4]=> + string(4) "four" + ["0.5"]=> + int(5) +} +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_assoc_variation1.phpt b/ext/standard/tests/array/array_udiff_assoc_variation1.phpt new file mode 100644 index 0000000..9886d73 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_variation1.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr2 = array(1, 2); + +include('compare_function.inc'); +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_assoc($value, $arr2, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_assoc(): Argument #1 is not an array in %sarray_udiff_assoc_variation1.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_assoc_variation2.phpt b/ext/standard/tests/array/array_udiff_assoc_variation2.phpt new file mode 100644 index 0000000..18484a7 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_variation2.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); + +include('compare_function.inc'); +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_assoc($arr1, $value, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_assoc(): Argument #2 is not an array in %sarray_udiff_assoc_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_assoc_variation3.phpt b/ext/standard/tests/array/array_udiff_assoc_variation3.phpt new file mode 100644 index 0000000..e693aff --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_variation3.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for key_comp_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_assoc($arr1, $arr2, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--empty array-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--int indexed array-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--associative array-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--nested arrays-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_assoc_variation3.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_assoc_variation4.phpt b/ext/standard/tests/array/array_udiff_assoc_variation4.phpt new file mode 100644 index 0000000..0bf3e2d --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_variation4.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_assoc($arr1, $arr2, $value, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_assoc(): Argument #3 is not an array in %sarray_udiff_assoc_variation4.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_assoc_variation5.phpt b/ext/standard/tests/array/array_udiff_assoc_variation5.phpt new file mode 100644 index 0000000..6938076 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_assoc_variation5.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_udiff_assoc() function : usage variation - incorrect comparison functions +--FILE-- +<?php +/* Prototype : array array_udiff_assoc(array arr1, array arr2 [, array ...], callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + + +echo "*** Testing array_udiff_assoc() : usage variation - differing comparison functions***\n"; + +$arr1 = array(1); +$arr2 = array(1,2); + +echo "\n-- comparison function with an incorrect return value --\n"; +function incorrect_return_value ($val1, $val2) { + return array(1); +} +var_dump(array_udiff_assoc($arr1, $arr2, 'incorrect_return_value')); + +echo "\n-- comparison function taking too many parameters --\n"; +function too_many_parameters ($val1, $val2, $val3) { + return 1; +} +var_dump(array_udiff_assoc($arr1, $arr2, 'too_many_parameters')); + +echo "\n-- comparison function taking too few parameters --\n"; +function too_few_parameters ($val1) { + return 1; +} +var_dump(array_udiff_assoc($arr1, $arr2, 'too_few_parameters')); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_assoc() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too many parameters -- + +Warning: Missing argument 3 for too_many_parameters() in %sarray_udiff_assoc_variation5.php on line %d +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too few parameters -- +array(1) { + [0]=> + int(1) +} +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_basic.phpt b/ext/standard/tests/array/array_udiff_basic.phpt new file mode 100644 index 0000000..3da1b60 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +array_udiff():Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_udiff ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_error.phpt b/ext/standard/tests/array/array_udiff_error.phpt new file mode 100644 index 0000000..dc96577 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_udiff() function : error conditions +--FILE-- +<?php +/* Prototype : array array_udiff(array arr1, array arr2 [, array ...], callback data_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments. Elements are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff() : error conditions ***\n"; + +$arr1 = array(1, 2); +$arr2 = array(1, 2); +include('compare_function.inc'); +$data_comp_func = 'compare_function'; +$extra_arg = 10; + + +//Test array_udiff with one more than the expected number of arguments +echo "\n-- Testing array_udiff() function with more than expected no. of arguments --\n"; +var_dump( array_udiff($arr1, $arr2, $data_comp_func, $extra_arg) ); + +// Testing array_udiff with one less than the expected number of arguments +echo "\n-- Testing array_udiff() function with less than expected no. of arguments --\n"; +var_dump( array_udiff($arr1, $arr2) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff() : error conditions *** + +-- Testing array_udiff() function with more than expected no. of arguments -- + +Warning: array_udiff() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_error.php on line %d +NULL + +-- Testing array_udiff() function with less than expected no. of arguments -- + +Warning: array_udiff(): at least 3 parameters are required, 2 given in %sarray_udiff_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_uassoc_basic.phpt b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt new file mode 100644 index 0000000..6095696 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +array_udiff_uassoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_udiff_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(23) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_uassoc_error.phpt b/ext/standard/tests/array/array_udiff_uassoc_error.phpt new file mode 100644 index 0000000..e7d27e6 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_error.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_udiff_uassoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : error conditions ***\n"; + + +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; +$key_comp_func = 'compare_function'; +$extra_arg = 10; + +//Test array_udiff_uassoc with one more than the expected number of arguments +echo "\n-- Testing array_udiff_uassoc() function with more than expected no. of arguments --\n"; +var_dump( array_udiff_uassoc($arr1, $arr2, $data_comp_func, $key_comp_func, $extra_arg) ); + +// Testing array_udiff_uassoc with one less than the expected number of arguments +echo "\n-- Testing array_udiff_uassoc() function with less than expected no. of arguments --\n"; +var_dump( array_udiff_uassoc($arr1, $arr2, $data_comp_func) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : error conditions *** + +-- Testing array_udiff_uassoc() function with more than expected no. of arguments -- + +Warning: array_udiff_uassoc() expects parameter 5 to be a valid callback, no array or string given in %sarray_udiff_uassoc_error.php on line %d +NULL + +-- Testing array_udiff_uassoc() function with less than expected no. of arguments -- + +Warning: array_udiff_uassoc(): at least 4 parameters are required, 3 given in %sarray_udiff_uassoc_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation1.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation1.phpt new file mode 100644 index 0000000..a48d56d --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_variation1.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_uassoc($value, $arr2, $data_comp_func, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_uassoc(): Argument #1 is not an array in %sarray_udiff_uassoc_variation1.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation2.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation2.phpt new file mode 100644 index 0000000..c205da7 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_variation2.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_uassoc($arr1, $value, $data_comp_func, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_uassoc(): Argument #2 is not an array in %sarray_udiff_uassoc_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation3.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation3.phpt new file mode 100644 index 0000000..76afda0 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_variation3.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for data_comp_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_uassoc($arr1, $arr2, $value, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--empty array-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--int indexed array-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--associative array-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--nested arrays-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation3.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation4.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation4.phpt new file mode 100644 index 0000000..0beb15f --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_variation4.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for key_comp_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_uassoc($arr1, $arr2, $data_comp_func, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--empty array-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--int indexed array-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--associative array-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, first array member is not a valid class name or object in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--nested arrays-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_udiff_uassoc_variation4.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation5.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation5.phpt new file mode 100644 index 0000000..87c7071 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_variation5.phpt @@ -0,0 +1,229 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; +$key_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff_uassoc($arr1, $arr2, $value, $data_comp_func, $key_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : usage variation *** + +--int 0-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--int 1-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--float .5-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL + +--unset var-- + +Warning: array_udiff_uassoc(): Argument #3 is not an array in %sarray_udiff_uassoc_variation5.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt b/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt new file mode 100644 index 0000000..ec752a3 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_uassoc_variation6.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_udiff_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff_uassoc(array arr1, array arr2 [, array ...], callback data_comp_func, callback key_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments but do additional checks whether the keys are equal. Keys and elements are compared by user supplied functions. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff_uassoc() : usage variation - differing comparison functions***\n"; + +$arr1 = array(1); +$arr2 = array(1); + +echo "\n-- comparison function with an incorrect return value --\n"; +function incorrect_return_value ($val1, $val2) { + return array(1); +} +var_dump(array_udiff_uassoc($arr1, $arr2, 'incorrect_return_value', 'incorrect_return_value')); + +echo "\n-- comparison function taking too many parameters --\n"; +function too_many_parameters ($val1, $val2, $val3) { + return 1; +} +var_dump(array_udiff_uassoc($arr1, $arr2, 'too_many_parameters', 'too_many_parameters')); + +echo "\n-- comparison function taking too few parameters --\n"; +function too_few_parameters ($val1) { + return 1; +} +var_dump(array_udiff_uassoc($arr1, $arr2, 'too_few_parameters', 'too_few_parameters')); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff_uassoc() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too many parameters -- + +Warning: Missing argument 3 for too_many_parameters() in %sarray_udiff_uassoc_variation6.php on line %d +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too few parameters -- +array(1) { + [0]=> + int(1) +} +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_variation1.phpt b/ext/standard/tests/array/array_udiff_variation1.phpt new file mode 100644 index 0000000..d2c0e24 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_variation1.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_udiff() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff(array arr1, array arr2 [, array ...], callback data_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments. Elements are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff($value, $arr2, $data_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff() : usage variation *** + +--int 0-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--int 1-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--float .5-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL + +--unset var-- + +Warning: array_udiff(): Argument #1 is not an array in %sarray_udiff_variation1.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_udiff_variation2.phpt b/ext/standard/tests/array/array_udiff_variation2.phpt new file mode 100644 index 0000000..fd2c12d --- /dev/null +++ b/ext/standard/tests/array/array_udiff_variation2.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_udiff() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff(array arr1, array arr2 [, array ...], callback data_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments. Elements are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff($arr1, $value, $data_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff() : usage variation *** + +--int 0-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--int 1-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--float .5-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL + +--unset var-- + +Warning: array_udiff(): Argument #2 is not an array in %sarray_udiff_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_variation3.phpt b/ext/standard/tests/array/array_udiff_variation3.phpt new file mode 100644 index 0000000..aeeee89 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_variation3.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test array_udiff() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff(array arr1, array arr2 [, array ...], callback data_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments. Elements are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for data_comp_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff($arr1, $arr2, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff() : usage variation *** + +--int 0-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--int 1-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--float .5-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--empty array-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_variation3.php on line %d +NULL + +--int indexed array-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_variation3.php on line %d +NULL + +--associative array-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %sarray_udiff_variation3.php on line %d +NULL + +--nested arrays-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_udiff_variation3.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_variation3.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_udiff_variation3.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_variation3.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_udiff_variation3.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_udiff_variation3.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_udiff_variation3.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL + +--unset var-- + +Warning: array_udiff() expects parameter 3 to be a valid callback, no array or string given in %sarray_udiff_variation3.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_variation4.phpt b/ext/standard/tests/array/array_udiff_variation4.phpt new file mode 100644 index 0000000..09dec4f --- /dev/null +++ b/ext/standard/tests/array/array_udiff_variation4.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_udiff() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff(array arr1, array arr2 [, array ...], callback data_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments. Elements are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_comp_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_udiff($arr1, $arr2, $value, $data_comp_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff() : usage variation *** + +--int 0-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--int 1-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--int 12345-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--int -12345-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--float 10.5-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--float -10.5-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--float .5-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--lowercase null-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--lowercase true-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--lowercase false-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--empty string DQ-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--empty string SQ-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--string DQ-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--string SQ-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--mixed case string-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--heredoc-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--undefined var-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL + +--unset var-- + +Warning: array_udiff(): Argument #3 is not an array in %sarray_udiff_variation4.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_udiff_variation5.phpt b/ext/standard/tests/array/array_udiff_variation5.phpt new file mode 100644 index 0000000..49405d4 --- /dev/null +++ b/ext/standard/tests/array/array_udiff_variation5.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_udiff() function : usage variation +--FILE-- +<?php +/* Prototype : array array_udiff(array arr1, array arr2 [, array ...], callback data_comp_func) + * Description: Returns the entries of arr1 that have values which are not present in any of the others arguments. Elements are compared by user supplied function. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_udiff() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1); +$arr2 = array(1); + +echo "\n-- comparison function with an incorrect return value --\n"; +function incorrect_return_value ($val1, $val2) { + return array(1); +} +var_dump(array_udiff($arr1, $arr2, 'incorrect_return_value')); + +echo "\n-- comparison function taking too many parameters --\n"; +function too_many_parameters ($val1, $val2, $val3) { + return 0; +} +var_dump(array_udiff($arr1, $arr2, 'too_many_parameters')); + +echo "\n-- comparison function taking too few parameters --\n"; +function too_few_parameters ($val1) { + return 0; +} +var_dump(array_udiff($arr1, $arr2, 'too_few_parameters')); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_udiff() : usage variation *** + +-- comparison function with an incorrect return value -- +array(1) { + [0]=> + int(1) +} + +-- comparison function taking too many parameters -- + +Warning: Missing argument 3 for too_many_parameters() in %sarray_udiff_variation5.php on line %d +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_assoc_basic.phpt b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt new file mode 100644 index 0000000..7e9fff7 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_basic.phpt @@ -0,0 +1,36 @@ +--TEST-- +array_uintersect_assoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_uintersect_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect_assoc($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_assoc_basic2.phpt b/ext/standard/tests/array/array_uintersect_assoc_basic2.phpt new file mode 100644 index 0000000..f0c7ecc --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_basic2.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_uintersect_assoc() function : basic functionality - testing with multiple array arguments +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: U + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : basic functionality - testing with multiple array arguments ***\n"; + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +// Initialise all required variables +$arr1 = array("one" => "one", "02" => "two", '3' => "three", "four", "0.5" => 5, 0.6 => 6, "0x7" => "seven"); +$arr2 = array("one" => "one", "02" => "two", '3' => "three"); +$arr3 = array("one" => "one", '3' => "three", "0.5" => 5); +$arr4 = array("one" => "one", '3' => "three", "0.5" => 5); + + +var_dump( array_uintersect_assoc($arr1, $arr2, $arr3, $arr4, $data_compare_function) ); + + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : basic functionality - testing with multiple array arguments *** +array(2) { + ["one"]=> + string(3) "one" + [3]=> + string(5) "three" +} +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_assoc_error.phpt b/ext/standard/tests/array/array_uintersect_assoc_error.phpt new file mode 100644 index 0000000..73fc61e --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test array_uintersect_assoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: U + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : error conditions ***\n"; + +//Test array_uintersect_assoc with one more than the expected number of arguments +echo "\n-- Testing array_uintersect_assoc() function with more than expected no. of arguments --\n"; +$arr1 = array(1, 2); +$arr2 = array(1, 2); +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +$extra_arg = 10; +var_dump( array_uintersect_assoc($arr1, $arr2, $data_compare_function, $extra_arg) ); + +// Testing array_uintersect_assoc with one less than the expected number of arguments +echo "\n-- Testing array_uintersect_assoc() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +$arr2 = array(1, 2); +var_dump( array_uintersect_assoc($arr1, $arr2) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : error conditions *** + +-- Testing array_uintersect_assoc() function with more than expected no. of arguments -- + +Warning: array_uintersect_assoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_assoc_error.php on line %d +NULL + +-- Testing array_uintersect_assoc() function with less than expected no. of arguments -- + +Warning: array_uintersect_assoc(): at least 3 parameters are required, 2 given in %sarray_uintersect_assoc_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_assoc_variation1.phpt b/ext/standard/tests/array/array_uintersect_assoc_variation1.phpt new file mode 100644 index 0000000..45d0a8d --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_variation1.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: U + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_assoc($value, $arr2, $data_compare_function) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_assoc(): Argument #1 is not an array in %sarray_uintersect_assoc_variation1.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_assoc_variation2.phpt b/ext/standard/tests/array/array_uintersect_assoc_variation2.phpt new file mode 100644 index 0000000..a421c25 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_variation2.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: U + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_assoc($arr1, $value, $data_compare_function) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_assoc(): Argument #2 is not an array in %sarray_uintersect_assoc_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_assoc_variation3.phpt b/ext/standard/tests/array/array_uintersect_assoc_variation3.phpt new file mode 100644 index 0000000..a76fca0 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_variation3.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: U + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for data_compare_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_assoc($arr1, $arr2, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--empty array-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--int indexed array-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--associative array-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--nested arrays-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_assoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_assoc_variation3.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_assoc_variation4.phpt b/ext/standard/tests/array/array_uintersect_assoc_variation4.phpt new file mode 100644 index 0000000..abff23a --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_variation4.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: U + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_assoc($arr1, $arr2, $value, $data_compare_function ) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_assoc(): Argument #3 is not an array in %sarray_uintersect_assoc_variation4.php on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt b/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt new file mode 100644 index 0000000..e2d7bd0 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_assoc_variation5.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_uintersect_assoc() function : usage variation - differing comparison functions +--FILE-- +<?php +/* Prototype : array array_uintersect_assoc(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_assoc() : usage variation - differing comparison functions***\n"; + +$arr1 = array(1); +$arr2 = array(1,2); + +echo "\n-- comparison function with an incorrect return value --\n"; +function incorrect_return_value ($val1, $val2) { + return array(1); +} +var_dump(array_uintersect_assoc($arr1, $arr2, 'incorrect_return_value')); + +echo "\n-- comparison function taking too many parameters --\n"; +function too_many_parameters ($val1, $val2, $val3) { + return 1; +} +var_dump(array_uintersect_assoc($arr1, $arr2, 'too_many_parameters')); + +echo "\n-- comparison function taking too few parameters --\n"; +function too_few_parameters ($val1) { + return 1; +} +var_dump(array_uintersect_assoc($arr1, $arr2, 'too_few_parameters')); + +?> + +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_assoc() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(0) { +} + +-- comparison function taking too many parameters -- + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_assoc_variation5.php on line %d +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} + +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_basic.phpt b/ext/standard/tests/array/array_uintersect_basic.phpt new file mode 100644 index 0000000..8d4b803 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_basic.phpt @@ -0,0 +1,41 @@ +--TEST-- +array_uintersect(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_uintersect ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect($a, $b, array("cr", "comp_func_cr")); +var_dump($result); +?> +--EXPECTF-- +array(3) { + ["0.1"]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(9) + } + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_error.phpt b/ext/standard/tests/array/array_uintersect_error.phpt new file mode 100644 index 0000000..1b25db4 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_uintersect() function : error conditions +--FILE-- +<?php +/* Prototype : array array_uintersect(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect() : error conditions ***\n"; + + +//Test array_uintersect with one more than the expected number of arguments +echo "\n-- Testing array_uintersect() function with more than expected no. of arguments --\n"; +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +$extra_arg = 10; +var_dump( array_uintersect($arr1, $arr2, $data_compare_function, $extra_arg) ); + +// Testing array_uintersect with one less than the expected number of arguments +echo "\n-- Testing array_uintersect() function with less than expected no. of arguments --\n"; +$arr1 = array(1, 2); +$arr2 = array(1, 2); +var_dump( array_uintersect($arr1, $arr2) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect() : error conditions *** + +-- Testing array_uintersect() function with more than expected no. of arguments -- + +Warning: array_uintersect() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_error.php on line %d +NULL + +-- Testing array_uintersect() function with less than expected no. of arguments -- + +Warning: array_uintersect(): at least 3 parameters are required, 2 given in %sarray_uintersect_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt new file mode 100644 index 0000000..a474bc7 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +array_uintersect_uassoc(): Test return type and value for expected input +--FILE-- +<?php +/* +* proto array array_uintersect_assoc ( array $array1, array $array2 [, array $ ..., callback $data_compare_func] ) +* Function is implemented in ext/standard/array.c +*/ +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_key($a, $b) { + if ($a === $b) return 0; + return ($a > $b) ? 1 : -1; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_uintersect_uassoc($a, $b, array("cr", "comp_func_cr"), array("cr", "comp_func_key")); +var_dump($result); +?> +--EXPECTF-- +array(2) { + [1]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member":"cr":private]=> + int(-15) + } +}
\ No newline at end of file diff --git a/ext/standard/tests/array/array_uintersect_uassoc_error.phpt b/ext/standard/tests/array/array_uintersect_uassoc_error.phpt new file mode 100644 index 0000000..c7391ee --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_uintersect_uassoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : error conditions ***\n"; + +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_func = 'compare_function'; +$key_compare_func = 'compare_function'; + +$extra_arg = 10; + + +//Test array_uintersect_uassoc with one more than the expected number of arguments +echo "\n-- Testing array_uintersect_uassoc() function with more than expected no. of arguments --\n"; +var_dump( array_uintersect_uassoc($arr1, $arr2, $data_compare_func, $key_compare_func, $extra_arg) ); + +// Testing array_uintersect_uassoc with one less than the expected number of arguments +echo "\n-- Testing array_uintersect_uassoc() function with less than expected no. of arguments --\n"; +var_dump( array_uintersect_uassoc($arr1, $arr2, $data_compare_func) ); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : error conditions *** + +-- Testing array_uintersect_uassoc() function with more than expected no. of arguments -- + +Warning: array_uintersect_uassoc() expects parameter 5 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_error.php on line %d +NULL + +-- Testing array_uintersect_uassoc() function with less than expected no. of arguments -- + +Warning: array_uintersect_uassoc(): at least 4 parameters are required, 3 given in %sarray_uintersect_uassoc_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation1.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation1.phpt new file mode 100644 index 0000000..764c584 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation1.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_func = 'compare_function'; +$key_compare_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_uassoc($value, $arr2, $data_compare_func, $key_compare_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_uassoc(): Argument #1 is not an array in %sarray_uintersect_uassoc_variation1.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation2.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation2.phpt new file mode 100644 index 0000000..2efa93d --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation2.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); + +include('compare_function.inc'); +$data_compare_func = 'compare_function'; +$key_compare_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_uassoc($arr1, $value, $data_compare_func, $key_compare_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_uassoc(): Argument #2 is not an array in %sarray_uintersect_uassoc_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation3.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation3.phpt new file mode 100644 index 0000000..860a166 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation3.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$key_compare_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for data_compare_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_uassoc($arr1, $arr2, $value, $key_compare_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--empty array-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--int indexed array-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--associative array-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--nested arrays-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation3.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation4.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation4.phpt new file mode 100644 index 0000000..a396318 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation4.phpt @@ -0,0 +1,254 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for key_compare_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_uassoc($arr1, $arr2, $data_compare_func, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--empty array-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--int indexed array-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--associative array-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, first array member is not a valid class name or object in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--nested arrays-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, array must have exactly two members in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %sarray_uintersect_uassoc_variation4.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation5.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation5.phpt new file mode 100644 index 0000000..061ac60 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation5.phpt @@ -0,0 +1,229 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_func = 'compare_function'; +$key_compare_func = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect_uassoc($arr1, $arr2, $value, $data_compare_func, $key_compare_func) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect_uassoc(): Argument #3 is not an array in %sarray_uintersect_uassoc_variation5.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt b/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt new file mode 100644 index 0000000..6ed86f8 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_uassoc_variation6.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test array_uintersect_uassoc() function : usage variation - incorrect callbacks +--FILE-- +<?php +/* Prototype : array array_uintersect_uassoc(array arr1, array arr2 [, array ...], callback data_compare_func, callback key_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Keys are used to do more restrictive check. Both data and keys are compared by using user-supplied callbacks. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect_uassoc() : usage variation - incorrect callbacks ***\n"; + +$arr1 = array(1); +$arr2 = array(1,2); + +echo "\n-- comparison function with an incorrect return value --\n"; +function incorrect_return_value ($val1, $val2) { + return array(1); +} +var_dump(array_uintersect_uassoc($arr1, $arr2, 'incorrect_return_value', 'incorrect_return_value')); + +echo "\n-- comparison function taking too many parameters --\n"; +function too_many_parameters ($val1, $val2, $val3) { + return 1; +} +var_dump(array_uintersect_uassoc($arr1, $arr2, 'too_many_parameters', 'too_many_parameters')); + +echo "\n-- comparison function taking too few parameters --\n"; +function too_few_parameters ($val1) { + return 1; +} +var_dump(array_uintersect_uassoc($arr1, $arr2, 'too_few_parameters', 'too_few_parameters')); + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect_uassoc() : usage variation - incorrect callbacks *** + +-- comparison function with an incorrect return value -- +array(0) { +} + +-- comparison function taking too many parameters -- + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_uassoc_variation6.php on line %d + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_uassoc_variation6.php on line %d + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_uassoc_variation6.php on line %d +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_variation1.phpt b/ext/standard/tests/array/array_uintersect_variation1.phpt new file mode 100644 index 0000000..0663a95 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_variation1.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_uintersect() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect($value, $arr2, $data_compare_function) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect() : usage variation *** + +--int 0-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect(): Argument #1 is not an array in %sarray_uintersect_variation1.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_variation2.phpt b/ext/standard/tests/array/array_uintersect_variation2.phpt new file mode 100644 index 0000000..79f4cd0 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_variation2.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_uintersect() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for arr2 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect($arr1, $value, $data_compare_function) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect() : usage variation *** + +--int 0-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect(): Argument #2 is not an array in %sarray_uintersect_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_variation3.phpt b/ext/standard/tests/array/array_uintersect_variation3.phpt new file mode 100644 index 0000000..707ba11 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_variation3.phpt @@ -0,0 +1,251 @@ +--TEST-- +Test array_uintersect() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for data_compare_func + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect($arr1, $arr2, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect() : usage variation *** + +--int 0-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--empty array-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_variation3.php on line %d +NULL + +--int indexed array-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_variation3.php on line %d +NULL + +--associative array-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, first array member is not a valid class name or object in %sarray_uintersect_variation3.php on line %d +NULL + +--nested arrays-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, array must have exactly two members in %sarray_uintersect_variation3.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_variation3.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, function '' not found or invalid function name in %sarray_uintersect_variation3.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_variation3.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, function 'string' not found or invalid function name in %sarray_uintersect_variation3.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, function 'sTrInG' not found or invalid function name in %sarray_uintersect_variation3.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, function 'hello world' not found or invalid function name in %sarray_uintersect_variation3.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect() expects parameter 3 to be a valid callback, no array or string given in %sarray_uintersect_variation3.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_variation4.phpt b/ext/standard/tests/array/array_uintersect_variation4.phpt new file mode 100644 index 0000000..45207b3 --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_variation4.phpt @@ -0,0 +1,228 @@ +--TEST-- +Test array_uintersect() function : usage variation +--FILE-- +<?php +/* Prototype : array array_uintersect(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$arr1 = array(1, 2); +$arr2 = array(1, 2); + +include('compare_function.inc'); +$data_compare_function = 'compare_function'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for ... + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_uintersect($arr1, $arr2, $value, $data_compare_function) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_uintersect() : usage variation *** + +--int 0-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--int 1-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--int 12345-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--int -12345-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--float 10.5-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--float -10.5-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--float .5-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--lowercase null-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--lowercase true-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--lowercase false-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--empty string DQ-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--empty string SQ-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--string DQ-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--string SQ-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--mixed case string-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--heredoc-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--undefined var-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL + +--unset var-- + +Warning: array_uintersect(): Argument #3 is not an array in %sarray_uintersect_variation4.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_uintersect_variation5.phpt b/ext/standard/tests/array/array_uintersect_variation5.phpt new file mode 100644 index 0000000..75cf08e --- /dev/null +++ b/ext/standard/tests/array/array_uintersect_variation5.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_uintersect() function : usage variation - differing comparison functions +--FILE-- +<?php +/* Prototype : array array_uintersect(array arr1, array arr2 [, array ...], callback data_compare_func) + * Description: Returns the entries of arr1 that have values which are present in all the other arguments. Data is compared by using an user-supplied callback. + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing array_uintersect() : usage variation - differing comparison functions***\n"; + +$arr1 = array(1); +$arr2 = array(1,2); + +echo "\n-- comparison function with an incorrect return value --\n"; +function incorrect_return_value ($val1, $val2) { + return array(1); +} +var_dump(array_uintersect($arr1, $arr2, 'incorrect_return_value')); + +echo "\n-- comparison function taking too many parameters --\n"; +function too_many_parameters ($val1, $val2, $val3) { + return 1; +} +var_dump(array_uintersect($arr1, $arr2, 'too_many_parameters')); + +echo "\n-- comparison function taking too few parameters --\n"; +function too_few_parameters ($val1) { + return 1; +} +var_dump(array_uintersect($arr1, $arr2, 'too_few_parameters')); + +?> + +===DONE=== +--EXPECTF-- +*** Testing array_uintersect() : usage variation - differing comparison functions*** + +-- comparison function with an incorrect return value -- +array(0) { +} + +-- comparison function taking too many parameters -- + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_variation5.php on line %d + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_variation5.php on line %d + +Warning: Missing argument 3 for too_many_parameters() in %sarray_uintersect_variation5.php on line %d +array(0) { +} + +-- comparison function taking too few parameters -- +array(0) { +} + +===DONE=== diff --git a/ext/standard/tests/array/array_unique_basic.phpt b/ext/standard/tests/array/array_unique_basic.phpt new file mode 100644 index 0000000..58d3acf --- /dev/null +++ b/ext/standard/tests/array/array_unique_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_unique() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_unique() : basic functionality ***\n"; + +// array with default keys +$input = array(1, 2, "1", '2'); +var_dump( array_unique($input) ); + +// associative array +$input = array("1" => "one", 1 => "one", 2 => "two", '2' => "two"); +var_dump( array_unique($input) ); + +// mixed array +$input = array("1" => "one", "two", "one", 2 => "two", "three"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : basic functionality *** +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [4]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_unique_error.phpt b/ext/standard/tests/array/array_unique_error.phpt new file mode 100644 index 0000000..9da3dfc --- /dev/null +++ b/ext/standard/tests/array/array_unique_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_unique() function : error conditions +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_unique() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_unique() function with zero arguments --\n"; +var_dump( array_unique() ); + +//Test array_unique with one more than the expected number of arguments +echo "\n-- Testing array_unique() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$extra_arg = 10; +var_dump( array_unique($input, SORT_NUMERIC, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : error conditions *** + +-- Testing array_unique() function with zero arguments -- + +Warning: array_unique() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing array_unique() function with more than expected no. of arguments -- + +Warning: array_unique() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_unique_variation1.phpt b/ext/standard/tests/array/array_unique_variation1.phpt new file mode 100644 index 0000000..a7774ef --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation1.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test array_unique() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Passing non array values to 'input' argument of array_unique() and see + * that the function outputs proper warning messages wherever expected. +*/ + +echo "*** Testing array_unique() : Passing non array values to \$input argument ***\n"; + +//get an unset variable +$unset_var = 10; +unset($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs and check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : Passing non array values to $input argument *** +-- Iteration 1 -- + +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_unique() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_unique() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_unique() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_unique() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_unique() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_unique() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_unique() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_unique_variation2.phpt b/ext/standard/tests/array/array_unique_variation2.phpt new file mode 100644 index 0000000..3cfcfba --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation2.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test array_unique() function : usage variations - different arrays for 'input' argument +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* +* Passing different arrays to $input argument and testing whether +* array_unique() behaves in an expected way. +*/ + +echo "*** Testing array_unique() : Passing different arrays to \$input argument ***\n"; + +/* Different heredoc strings passed as argument to arrays */ +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with quoted strings and numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $input argument +$inputs = array ( +/*1*/ array(1, 2, 2, 1), // with default keys and numeric values + array(1.1, 2.2, 1.1), // with default keys & float values + array(false, true, false), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL, null), // with NULL + array("a\v\f", "aaaa\r", "b", "aaaa\r", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', 'aaaa\r', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $blank_line), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 5 => 10), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "10" => "ten"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), +/*18*/ array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input, SORT_STRING) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(1) { + [0]=> + NULL +} +-- Iteration 6 -- +array(4) { + [0]=> + %unicode|string%(3) "a" + [1]=> + %unicode|string%(5) "aaaa
" + [2]=> + %unicode|string%(1) "b" + [4]=> + %unicode|string%(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(4) { + [0]=> + %unicode|string%(5) "a\v\f" + [1]=> + %unicode|string%(6) "aaaa\r" + [2]=> + %unicode|string%(1) "b" + [4]=> + %unicode|string%(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(3) { + [%b|u%"h1"]=> + %unicode|string%(1) " +" + [%b|u%"h2"]=> + %unicode|string%(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + [%b|u%"h3"]=> + %unicode|string%(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- Iteration 9 -- +array(2) { + [1]=> + %unicode|string%(3) "one" + [2]=> + %unicode|string%(3) "two" +} +-- Iteration 10 -- +array(2) { + [%b|u%"one"]=> + int(1) + [%b|u%"two"]=> + int(2) +} +-- Iteration 11 -- +array(3) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) +} +-- Iteration 12 -- +array(2) { + [%b|u%"one"]=> + %unicode|string%(3) "ten" + [%b|u%"two"]=> + %unicode|string%(6) "twenty" +} +-- Iteration 13 -- +array(3) { + [%b|u%"one"]=> + int(1) + [2]=> + %unicode|string%(3) "two" + [4]=> + %unicode|string%(4) "four" +} +-- Iteration 14 -- +array(2) { + [%b|u%""]=> + %unicode|string%(4) "null" + [%b|u%"NULL"]=> + NULL +} +-- Iteration 15 -- +array(4) { + [1]=> + %unicode|string%(4) "true" + [0]=> + %unicode|string%(5) "false" + [%b|u%"false"]=> + bool(false) + [%b|u%"true"]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + [%b|u%""]=> + %unicode|string%(6) "emptys" + [%b|u%"emptyd"]=> + %unicode|string%(0) "" +} +-- Iteration 17 -- +array(2) { + [1]=> + %unicode|string%(0) "" + [6]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [%b|u%""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation3.phpt b/ext/standard/tests/array/array_unique_variation3.phpt new file mode 100644 index 0000000..49103c8 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation3.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different keys +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing different + * associative arrays having different keys to $input argument. +*/ + +echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// different associative arrays to be passed to $input argument +$inputs = array ( +/*1*/ // arrays with integer keys + array(0 => "0", 1 => "0"), + array(1 => "1", 2 => "2", 3 => 1, 4 => "4"), + + // arrays with float keys +/*3*/ array(2.3333 => "float", 44.44 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"), + + // arrays with string keys +/*5*/ array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => "string", "string"), + + // array with object, unset variable and resource variable +/*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. keys passed to $input argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 2 -- +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [4]=> + string(1) "4" +} +-- Iteration 3 -- +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 4 -- +array(3) { + [1]=> + string(2) "f1" + [3]=> + string(2) "f2" + [3333333]=> + string(2) "f4" +} +-- Iteration 5 -- +array(3) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +-- Iteration 6 -- +array(3) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) +} +-- Iteration 7 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +array(2) { + [""]=> + string(5) "hello" + [0]=> + int(11) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation4.phpt b/ext/standard/tests/array/array_unique_variation4.phpt new file mode 100644 index 0000000..a1fc13e --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation4.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different values +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing different + * associative arrays having different values to $input argument. +*/ + +echo "*** Testing array_unique() : assoc. array with diff. values to \$input argument ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// associative arrays with different values +$inputs = array ( + // arrays with integer values +/*1*/ array('0' => 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("float1" => 2.3333, "float2" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), + + // arrays with string values +/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. values to $input argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 2 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 3 -- +array(1) { + ["float1"]=> + float(2.3333) +} +-- Iteration 4 -- +array(3) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) +} +-- Iteration 5 -- +array(3) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" +} +-- Iteration 6 -- +array(3) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" +} +-- Iteration 7 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 8 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation5.phpt b/ext/standard/tests/array/array_unique_variation5.phpt new file mode 100644 index 0000000..5e3f7c3 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation5.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_unique() function : usage variations - array with duplicate keys +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing + * array having duplicate keys as values. +*/ + +echo "*** Testing array_unique() : array with duplicate keys for \$input argument ***\n"; + +// initialize the array having duplicate keys +$input = array( 1 => "one", 2 => "two", 2 => "2", 3 => "three", 1 => "1", "1", "2"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with duplicate keys for $input argument *** +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation6.phpt b/ext/standard/tests/array/array_unique_variation6.phpt new file mode 100644 index 0000000..82442bd --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation6.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_unique() function : usage variations - array with reference variables +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing + * array having reference variables as values. +*/ + +echo "*** Testing array_unique() : array with reference variables for \$input argument ***\n"; + +$value1 = 10; +$value2 = "hello"; +$value3 = 0; +$value4 = &$value2; + +// input array containing elements as reference variables +$input = array( + 0 => 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + 5 => $value4 +); + +var_dump( array_unique($input, SORT_STRING) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with reference variables for $input argument *** +array(2) { + [0]=> + int(0) + [1]=> + &%unicode|string%(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation7.phpt b/ext/standard/tests/array/array_unique_variation7.phpt new file mode 100644 index 0000000..e998a73 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation7.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_unique() function : usage variations - binary safe checking +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing an array having binary values. +*/ + +echo "*** Testing array_unique() : array with binary data for \$input argument ***\n"; + +// array with binary values +$input = array( b"1", b"hello", "world", "str1" => "hello", "str2" => "world"); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with binary data for $input argument *** +array(3) { + [0]=> + string(1) "1" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation8.phpt b/ext/standard/tests/array/array_unique_variation8.phpt new file mode 100644 index 0000000..ee34dee --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation8.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_unique() function : usage variations - two dimensional arrays +--FILE-- +<?php +/* Prototype : array array_unique(array $input) + * Description: Removes duplicate values from array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unique() by passing + * two dimensional arrays for $input argument. +*/ + +echo "*** Testing array_unique() : two dimensional array for \$input argument ***\n"; + +// initialize the 2-d array +$input = array( + array(1, 2, 3, 1), + array("hello", "world", "str1" => "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +var_dump( array_unique($input, SORT_STRING) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : two dimensional array for $input argument *** + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d + +Notice: Array to string conversion in %sarray_unique_variation8.php on line %d +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +Done diff --git a/ext/standard/tests/array/array_unshift.phpt b/ext/standard/tests/array/array_unshift.phpt new file mode 100644 index 0000000..ebcf190 --- /dev/null +++ b/ext/standard/tests/array/array_unshift.phpt @@ -0,0 +1,40 @@ +--TEST-- +array_unshift() tests +--FILE-- +<?php + +$a = array(); +$s = ""; +var_dump(array_unshift($a, $s)); +var_dump($a); +var_dump(array_unshift($s, $a)); +var_dump($a); +var_dump(array_unshift($a, $a)); +var_dump($a); + +echo "Done\n"; +?> +--EXPECTF-- +int(1) +array(1) { + [0]=> + string(0) "" +} + +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +array(1) { + [0]=> + string(0) "" +} +int(2) +array(2) { + [0]=> + array(1) { + [0]=> + string(0) "" + } + [1]=> + string(0) "" +} +Done diff --git a/ext/standard/tests/array/array_unshift_basic1.phpt b/ext/standard/tests/array/array_unshift_basic1.phpt new file mode 100644 index 0000000..97ea895 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_basic1.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_unshift() function : basic functionality - array with default keys for 'array' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_unshift() by giving array with default keys for $array argument +*/ + +echo "*** Testing array_unshift() : basic functionality with default key array ***\n"; + +// Initialise the array +$array = array(1, 2); + +// Calling array_unshift() with default argument +$temp_array = $array; +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +var_dump( array_unshift($temp_array, 10) ); + +// dump the resulting array +var_dump($temp_array); + +// Calling array_unshift() with optional arguments +$temp_array = $array; +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +var_dump( array_unshift($temp_array, 222, "hello", 12.33) ); + +// dump the resulting array +var_dump($temp_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : basic functionality with default key array *** +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(222) + [1]=> + string(5) "hello" + [2]=> + float(12.33) + [3]=> + int(1) + [4]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/array_unshift_basic2.phpt b/ext/standard/tests/array/array_unshift_basic2.phpt new file mode 100644 index 0000000..e4fd2e0 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_basic2.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test array_unshift() function : basic functionality - associative arrays for 'array' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_unshift() by giving associative arrays for $array argument +*/ + +echo "*** Testing array_unshift() : basic functionality with associative array ***\n"; + +// Initialise the array +$array = array('f' => "first", "s" => 'second', 1 => "one", 2 => 'two'); + +// Calling array_unshift() with default argument +$temp_array = $array; +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +var_dump( array_unshift($temp_array, 10) ); + +// dump the resulting array +var_dump($temp_array); + +// Calling array_unshift() with optional arguments +$temp_array = $array; +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +var_dump( array_unshift($temp_array, 222, "hello", 12.33) ); + +// dump the resulting array +var_dump($temp_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : basic functionality with associative array *** +int(5) +array(5) { + [0]=> + int(10) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +int(7) +array(7) { + [0]=> + int(222) + [1]=> + string(5) "hello" + [2]=> + float(12.33) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + string(3) "one" + [4]=> + string(3) "two" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_unshift_error.phpt b/ext/standard/tests/array/array_unshift_error.phpt new file mode 100644 index 0000000..1381111 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_error.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test array_unshift() function : error conditions +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_unshift() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_unshift() function with Zero arguments --\n"; +var_dump( array_unshift() ); + +// Testing array_unshift with one less than the expected number of arguments +echo "\n-- Testing array_unshift() function with less than expected no. of arguments --\n"; +$array = array(1, 2); +var_dump( array_unshift($array) ); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : error conditions *** + +-- Testing array_unshift() function with Zero arguments -- + +Warning: array_unshift() expects at least 2 parameters, 0 given in %s on line %d +NULL + +-- Testing array_unshift() function with less than expected no. of arguments -- + +Warning: array_unshift() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_unshift_object.phpt b/ext/standard/tests/array/array_unshift_object.phpt new file mode 100644 index 0000000..e615537 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_object.phpt @@ -0,0 +1,287 @@ +--TEST-- +Test array_unshift() function : passing object for 'var' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by passing + * an object to the $var argument +*/ + +echo "*** Testing array_unshift() : Passing object to \$var argument ***\n"; + +// simple class with a variable and method +class SimpleClass +{ + public $var1 = 1; + public function fun1() { + return $var1; + } +} + +// class without members +class EmptyClass +{ +} + +// abstract class +abstract class AbstractClass +{ + protected $var2 = 5; + abstract function emptyFunction(); +} + +// class deriving the above abstract class +class ChildClass extends AbstractClass +{ + private $var3; + public function emptyFunction() { + echo "defined in child"; + } +} + +// class with final method +class FinalClass +{ + private $var4; + final function finalMethod() { + echo "This function can't be overloaded"; + } +} + +// class with static members +class StaticClass +{ + static $var5 = 2; + public static function staticMethod() { + echo "This is a static method"; + } +} + +// array to be passed to $array argument +$array = array('f' => "first", "s" => 'second', 1, 2.222); + +// array containing different types of objects as elements +$vars = array( + new SimpleClass(), + new EmptyClass(), + new ChildClass(), + new FinalClass(), + new StaticClass() +); + +// loop through the various elements of $arrays to check the functionality of array_unshift +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : Passing object to $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(1) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(SimpleClass)#%d (1) { + ["var1"]=> + int(1) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + object(EmptyClass)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(ChildClass)#%d (2) { + ["var3":"ChildClass":private]=> + NULL + ["var2":protected]=> + int(5) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(FinalClass)#%d (1) { + ["var4":"FinalClass":private]=> + NULL + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + object(StaticClass)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation1.phpt b/ext/standard/tests/array/array_unshift_variation1.phpt new file mode 100644 index 0000000..4d0c8c2 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation1.phpt @@ -0,0 +1,338 @@ +--TEST-- +Test array_unshift() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the behavior of array_unshift() by giving values + * other than array values for $array argument +*/ + +echo "*** Testing array_unshift() : unexpected values for \$array argument ***\n"; + +// Initialise $var argument +$var = 12; + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// array of unexpected values to be passed to $array argument +$arrays = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $arrays to test the functionality of array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "\n-- Iteration $iterator --"; + + /* with default arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +}; + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : unexpected values for $array argument *** + +-- Iteration 1 -- +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(0) + +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(0) + +-- Iteration 2 -- +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(1) + +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(1) + +-- Iteration 3 -- +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(12345) + +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(12345) + +-- Iteration 4 -- +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(-2345) + +Warning: array_unshift() expects parameter 1 to be array, integer given in %s on line %d +NULL +int(-2345) + +-- Iteration 5 -- +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(10.5) + +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(10.5) + +-- Iteration 6 -- +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(-10.5) + +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(-10.5) + +-- Iteration 7 -- +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(123456789000) + +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(123456789000) + +-- Iteration 8 -- +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(1.23456789E-9) + +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(1.23456789E-9) + +-- Iteration 9 -- +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(0.5) + +Warning: array_unshift() expects parameter 1 to be array, double given in %s on line %d +NULL +float(0.5) + +-- Iteration 10 -- +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +-- Iteration 11 -- +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +-- Iteration 12 -- +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(true) + +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(true) + +-- Iteration 13 -- +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(false) + +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(false) + +-- Iteration 14 -- +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(true) + +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(true) + +-- Iteration 15 -- +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(false) + +Warning: array_unshift() expects parameter 1 to be array, boolean given in %s on line %d +NULL +bool(false) + +-- Iteration 16 -- +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(0) "" + +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(0) "" + +-- Iteration 17 -- +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(0) "" + +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(0) "" + +-- Iteration 18 -- +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(6) "string" + +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(6) "string" + +-- Iteration 19 -- +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(6) "string" + +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(6) "string" + +-- Iteration 20 -- +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(11) "hello world" + +Warning: array_unshift() expects parameter 1 to be array, string given in %s on line %d +NULL +string(11) "hello world" + +-- Iteration 21 -- +Warning: array_unshift() expects parameter 1 to be array, object given in %s on line %d +NULL +object(classA)#1 (0) { +} + +Warning: array_unshift() expects parameter 1 to be array, object given in %s on line %d +NULL +object(classA)#1 (0) { +} + +-- Iteration 22 -- +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +-- Iteration 23 -- +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +Warning: array_unshift() expects parameter 1 to be array, null given in %s on line %d +NULL +NULL + +-- Iteration 24 -- +Warning: array_unshift() expects parameter 1 to be array, resource given in %s on line %d +NULL +resource(%d) of type (stream) + +Warning: array_unshift() expects parameter 1 to be array, resource given in %s on line %d +NULL +resource(%d) of type (stream) +Done diff --git a/ext/standard/tests/array/array_unshift_variation2.phpt b/ext/standard/tests/array/array_unshift_variation2.phpt new file mode 100644 index 0000000..064309b --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation2.phpt @@ -0,0 +1,1061 @@ +--TEST-- +Test array_unshift() function : usage variations - all possible values for 'var' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_unshift() by giving all the possible values for $var argument +*/ + +echo "*** Testing array_unshift() : all possible values for \$var argument ***\n"; + +// array to be passed to $array argument +$array = array('f' => "first", "s" => 'second', 1, 2.222); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// different types of values to be passed to $var argument +$vars = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + $heredoc, + + // object data +/*26*/ new classA(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + // resource variable +/*29*/ $fp +); + +// loop through each element of $vars to check the functionality of array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +// close the file resource used +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : all possible values for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + int(0) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + int(1) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(1) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + int(12345) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(12345) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(-2345) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + int(-2345) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + float(10.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(10.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + float(-10.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(-10.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + float(123456789000) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(123456789000) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + float(1.23456789E-9) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(1.23456789E-9) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 9 -- +int(5) +array(5) { + [0]=> + float(0.5) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + float(0.5) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + array(0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 11 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(0) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(0) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 12 -- +int(5) +array(5) { + [0]=> + array(1) { + [0]=> + int(1) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 13 -- +int(5) +array(5) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + array(2) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 15 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 16 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 17 -- +int(5) +array(5) { + [0]=> + bool(true) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 18 -- +int(5) +array(5) { + [0]=> + bool(false) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 19 -- +int(5) +array(5) { + [0]=> + bool(true) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(true) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 20 -- +int(5) +array(5) { + [0]=> + bool(false) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + bool(false) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 21 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 22 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 23 -- +int(5) +array(5) { + [0]=> + string(6) "string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(6) "string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 24 -- +int(5) +array(5) { + [0]=> + string(6) "string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(6) "string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 25 -- +int(5) +array(5) { + [0]=> + string(11) "hello world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(11) "hello world" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 26 -- +int(5) +array(5) { + [0]=> + object(classA)#%d (0) { + } + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + object(classA)#%d (0) { + } + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 27 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 28 -- +int(5) +array(5) { + [0]=> + NULL + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + NULL + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 29 -- +int(5) +array(5) { + [0]=> + resource(%d) of type (stream) + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + resource(%d) of type (stream) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation3.phpt b/ext/standard/tests/array/array_unshift_variation3.phpt new file mode 100644 index 0000000..286cb29 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation3.phpt @@ -0,0 +1,571 @@ +--TEST-- +Test array_unshift() function : usage variations - different array values for 'array' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the behavior of array_unshift() by passing different types of arrays + * to $array argument to which the $var arguments will be prepended +*/ + +echo "*** Testing array_unshift() : different arrays for \$array argument ***\n"; + +// initialize $var argument +$var = 10; + +// different arrays to be passed to $array argument +$arrays = array ( +/*1*/ array(1, 2), // array with default keys and numeric values + array(1.1, 2.2), // array with default keys & float values + array( array(2), array(1)), // sub arrays + array(false,true), // array with default keys and boolean values + array(), // empty array + array(NULL), // array with NULL + array("a","aaaa","b","bbbb","c","ccccc"), + + // associative arrays +/*8*/ array(1 => "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : different arrays for $array argument *** +-- Iteration 1 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + int(1) + [2]=> + int(2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(1) + [4]=> + int(2) +} +-- Iteration 2 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + float(1.1) + [2]=> + float(2.2) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + float(1.1) + [4]=> + float(2.2) +} +-- Iteration 3 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(1) + } +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + array(1) { + [0]=> + int(2) + } + [4]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + bool(false) + [2]=> + bool(true) +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + bool(false) + [4]=> + bool(true) +} +-- Iteration 5 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 6 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + NULL +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + NULL +} +-- Iteration 7 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(1) "a" + [2]=> + string(4) "aaaa" + [3]=> + string(1) "b" + [4]=> + string(4) "bbbb" + [5]=> + string(1) "c" + [6]=> + string(5) "ccccc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "a" + [4]=> + string(4) "aaaa" + [5]=> + string(1) "b" + [6]=> + string(4) "bbbb" + [7]=> + string(1) "c" + [8]=> + string(5) "ccccc" +} +-- Iteration 8 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(3) "one" + [4]=> + string(3) "two" + [5]=> + string(5) "three" +} +-- Iteration 9 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + int(10) + [2]=> + int(20) + [3]=> + int(40) + [4]=> + int(30) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(10) + [4]=> + int(20) + [5]=> + int(40) + [6]=> + int(30) +} +-- Iteration 11 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +int(4) +array(4) { + [0]=> + int(10) + ["one"]=> + int(1) + [1]=> + string(3) "two" + [2]=> + string(4) "four" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + [3]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(4) "true" + [2]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(4) "true" + [4]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(0) "" + [4]=> + string(0) "" + [5]=> + NULL + [6]=> + NULL + [7]=> + bool(false) + [8]=> + bool(true) +} +-- Iteration 17 -- +int(4) +array(4) { + [0]=> + int(10) + [""]=> + int(4) + [1]=> + int(5) + [2]=> + int(6) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + int(4) + [3]=> + int(5) + [4]=> + int(6) +} +-- Iteration 18 -- +int(4) +array(4) { + [0]=> + int(10) + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation4.phpt b/ext/standard/tests/array/array_unshift_variation4.phpt new file mode 100644 index 0000000..25c9159 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation4.phpt @@ -0,0 +1,390 @@ +--TEST-- +Test array_unshift() function : usage variations - assoc. array with diff. keys for 'array' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by passing different + * associative arrays having different possible keys to $array argument. + * The $var argument passed is a fixed value +*/ + +echo "*** Testing array_unshift() : associative array with different keys ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//get a class +class classA +{ + public function __toString(){ + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing $var argument +$var = 10; + +// different variations of associative arrays to be passed to $array argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer keys + array(0 => "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", + 4.89999922839999 => "f3", + 33333333.333333 => "f4"), + + // arrays with string keys +/*7*/ array('\tHello' => 111, 're\td' => "color", + '\v\fworld' => 2.2, 'pen\n' => 33), + array("\tHello" => 111, "re\td" => "color", + "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable + array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed keys +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : associative array with different keys *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(1) "0" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "0" +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(1) "1" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "1" +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(1) "1" + [4]=> + string(1) "2" + [5]=> + string(1) "3" + [6]=> + string(1) "4" +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + string(5) "float" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "float" +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(2) "f1" + [2]=> + string(2) "f2" + [3]=> + string(2) "f3" + [4]=> + string(2) "f4" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(2) "f1" + [4]=> + string(2) "f2" + [5]=> + string(2) "f3" + [6]=> + string(2) "f4" +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + ["world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +int(2) +array(2) { + [0]=> + int(10) + [""]=> + string(5) "hello" +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [""]=> + string(5) "hello" +} +-- Iteration 11 -- +int(7) +array(7) { + [0]=> + int(10) + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [1]=> + string(3) "int" + [2]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [3]=> + string(3) "int" + [4]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation5.phpt b/ext/standard/tests/array/array_unshift_variation5.phpt new file mode 100644 index 0000000..7f08369 --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation5.phpt @@ -0,0 +1,398 @@ +--TEST-- +Test array_unshift() function : usage variations - assoc. array with diff values for 'array' argument +--INI-- +precision=12 +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by passing different + * associative arrays having different possible values to $array argument. + * The $var argument passed is a fixed value +*/ + +echo "*** Testing array_unshift() : associative array with different values ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// get a heredoc string +$heredoc = <<<EOT +Hello world +EOT; + +// initializing $var argument +$var = 10; + +// different variations of associative arrays to be passed to $array argument +$arrays = array ( + + // empty array +/*1*/ array(), + + // arrays with integer values + array('0' => 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.333333), + + // arrays with string values +/*7*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", 'resource' => $fp, "int" => 133, "float" => 444.432, "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($arrays as $array) { + echo "-- Iteration $iterator --\n"; + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : associative array with different values *** +-- Iteration 1 -- +int(1) +array(1) { + [0]=> + int(10) +} +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +-- Iteration 2 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(0) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(0) +} +-- Iteration 3 -- +int(2) +array(2) { + [0]=> + int(10) + [1]=> + int(1) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + int(1) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + int(10) + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [1]=> + int(4) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [3]=> + int(4) +} +-- Iteration 5 -- +int(2) +array(2) { + [0]=> + int(10) + ["float"]=> + float(2.3333) +} +int(4) +array(4) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + int(10) + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [1]=> + float(4.8999992284) + ["f4"]=> + float(33333333.3333) +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(33333333.3333) +} +-- Iteration 7 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) "world" + [3]=> + string(4) "pen +" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [4]=> + string(7) "world" + [5]=> + string(4) "pen +" +} +-- Iteration 8 -- +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +int(7) +array(7) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [4]=> + string(9) "\v\fworld" + [5]=> + string(5) "pen\n" +} +-- Iteration 9 -- +int(3) +array(3) { + [0]=> + int(10) + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +int(5) +array(5) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +int(4) +array(4) { + [0]=> + int(10) + [1]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +int(9) +array(9) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [3]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +int(11) +array(11) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + string(5) "hello" + [4]=> + object(classA)#%d (0) { + } + [5]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation6.phpt b/ext/standard/tests/array/array_unshift_variation6.phpt new file mode 100644 index 0000000..47da53b --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation6.phpt @@ -0,0 +1,196 @@ +--TEST-- +Test array_unshift() function : usage variations - two dimensional arrays for 'array' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by giving two-dimensional + * arrays and also sub-arrays within the two-dimensional array for $array argument. + * The $var argument passed is a fixed value +*/ + +echo "*** Testing array_unshift() : two dimensional arrays for \$array argument ***\n"; + +// initializing $var argument +$var = 10; + +// two-dimensional array to be passed to $array argument +$two_dimensional_array = array( + + // associative array + array('color' => 'red', 'item' => 'pen', 'place' => 'LA'), + + // numeric array + array(1, 2, 3, 4, 5), + + // combination of numeric and associative arrays + array('a' => 'green', 'red', 'brown', 33, 88, 'orange', 'item' => 'ball') +); + +/* Passing the entire $two_dimensional_array to $array */ + +/* With default argument */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array; +var_dump( array_unshift($temp_array, $var) ); // whole 2-d array + +// dumps the resulting array +var_dump($temp_array); + +/* With optional arguments */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array; +var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // whole 2-d array + +// dumps the resulting array +var_dump($temp_array); + +/* Passing the sub-array within the $two_dimensional_array to $array argument */ + +/* With default argument */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array[0]; +var_dump( array_unshift($temp_array, $var) ); // sub array + +// dumps the resulting array +var_dump($temp_array); + +/* With optional arguments */ +// returns element count in the resulting array after arguments are pushed to +// beginning of the given array +$temp_array = $two_dimensional_array[0]; +var_dump( array_unshift($temp_array, $var, "hello", 'world') ); // sub array + +// dumps the resulting array +var_dump($temp_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : two dimensional arrays for $array argument *** +int(4) +array(4) { + [0]=> + int(10) + [1]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } + [2]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [3]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + [3]=> + array(3) { + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" + } + [4]=> + array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + } + [5]=> + array(7) { + ["a"]=> + string(5) "green" + [0]=> + string(3) "red" + [1]=> + string(5) "brown" + [2]=> + int(33) + [3]=> + int(88) + [4]=> + string(6) "orange" + ["item"]=> + string(4) "ball" + } +} +int(4) +array(4) { + [0]=> + int(10) + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" +} +int(6) +array(6) { + [0]=> + int(10) + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["color"]=> + string(3) "red" + ["item"]=> + string(3) "pen" + ["place"]=> + string(2) "LA" +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation7.phpt b/ext/standard/tests/array/array_unshift_variation7.phpt new file mode 100644 index 0000000..9a94eca --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation7.phpt @@ -0,0 +1,216 @@ +--TEST-- +Test array_unshift() function : usage variations - double quoted strings for 'var' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by passing different + * double quoted strings for $var argument that is prepended to the array + * passed through $array argument +*/ + +echo "*** Testing array_unshift() : double quoted strings for \$var argument ***\n"; + +// array to be passed to $array argument +$array = array('f' => "first", "s" => 'second', 1, 2.222); + +// different variations of double quoted strings to be passed to $var argument +$vars = array ( + "\$ -> This represents the dollar sign. hello dollar!!!", + "\t\r\v The quick brown fo\fx jumped over the lazy dog", + "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\", + "hello world\\t", + "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + +// dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : double quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(53) "$ -> This represents the dollar sign. hello dollar!!!" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(53) "$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(49) "
The quick brown fox jumped over the lazy dog" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(49) "
The quick brown fox jumped over the lazy dog" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(55) "This is a text with special chars: \!\@\#$\%\^\&\*\(\)\" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(13) "hello world\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(13) "hello world\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(70) "This is a text in bold letters
\s\malong with slashes + : HELLO WORLD " + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(70) "This is a text in bold letters
\s\malong with slashes + : HELLO WORLD " + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation8.phpt b/ext/standard/tests/array/array_unshift_variation8.phpt new file mode 100644 index 0000000..a64349c --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation8.phpt @@ -0,0 +1,214 @@ +--TEST-- +Test array_unshift() function : usage variations - single quoted strings for 'var' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by passing different + * single quoted strings for $var argument that is prepended to the array + * passed through $array argument +*/ + +echo "*** Testing array_unshift() : single quoted strings for \$var argument ***\n"; + +// array to be passed to $array argument +$array = array('f' => "first", "s" => 'second', 1, 2.222); + +// different variations of single quoted strings to be passed to $var argument +$vars = array ( + '\$ -> This represents the dollar sign. hello dollar!!!', + '\t\r\v The quick brown fo\fx jumped over the lazy dog', + 'This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\\', + 'hello world\\t', + 'This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t' +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with optional arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : single quoted strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(54) "\$ -> This represents the dollar sign. hello dollar!!!" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(54) "\$ -> This represents the dollar sign. hello dollar!!!" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(53) "\t\r\v The quick brown fo\fx jumped over the lazy dog" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(56) "This is a text with special chars: \!\@\#\$\%\^\&\*\(\)\" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(13) "hello world\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(13) "hello world\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(74) "This is \ta text in bold letters\r\s\malong with slashes\n : HELLO WORLD\t" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_unshift_variation9.phpt b/ext/standard/tests/array/array_unshift_variation9.phpt new file mode 100644 index 0000000..a667e6d --- /dev/null +++ b/ext/standard/tests/array/array_unshift_variation9.phpt @@ -0,0 +1,309 @@ +--TEST-- +Test array_unshift() function : usage variations - heredoc strings for 'var' argument +--FILE-- +<?php +/* Prototype : int array_unshift(array $array, mixed $var [, mixed ...]) + * Description: Pushes elements onto the beginning of the array + * Source code: ext/standard/array.c +*/ + +/* + * Testing the functionality of array_unshift() by passing different + * heredoc strings for $var argument that is prepended to the array + * passed through $array argument +*/ + +echo "*** Testing array_unshift() : heredoc strings for \$var argument ***\n"; + +// heredoc with empty value +$empty_string = <<<EOT +EOT; + +// heredoc with blank line +$blank_line = <<<EOT + + +EOT; + +// heredoc with multiline string +$multiline_string = <<<EOT +hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string +EOT; + +// heredoc with diferent whitespaces +$diff_whitespaces = <<<EOT +hello\r world\t +1111\t\t != 2222\v\v +heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces +EOT; + +// heredoc with numeric values +$numeric_string = <<<EOT +11 < 12. 123 >22 +2222 != 1111.\t 0000 = 0000\n +EOT; + +// heredoc with quote chars & slash +$quote_char_string = <<<EOT +This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes +EOT; + +// array to be passed to $array argument +$array = array('f' => "first", "s" => 'second', 1, 2.222); + +// different heredoc strings to be passed to $var argument +$vars = array( + $empty_string, + $blank_line, + $multiline_string, + $diff_whitespaces, + $numeric_string, + $quote_char_string +); + +// loop through the various elements of $arrays to test array_unshift() +$iterator = 1; +foreach($vars as $var) { + echo "-- Iteration $iterator --\n"; + $temp_array = $array; // assign $array to another temporary $temp_array + + /* with default argument */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + var_dump( array_unshift($temp_array, $var) ); + + // dump the resulting array + var_dump($temp_array); + + /* with all possible arguments */ + // returns element count in the resulting array after arguments are pushed to + // beginning of the given array + $temp_array = $array; + var_dump( array_unshift($temp_array, $var, "hello", 'world') ); + + // dump the resulting array + var_dump($temp_array); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unshift() : heredoc strings for $var argument *** +-- Iteration 1 -- +int(5) +array(5) { + [0]=> + string(0) "" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(0) "" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 2 -- +int(5) +array(5) { + [0]=> + string(1) " +" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(1) " +" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 3 -- +int(5) +array(5) { + [0]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(86) "hello world +The big brown fox jumped over; +the lazy dog +This is a double quoted string" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 4 -- +int(5) +array(5) { + [0]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(88) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 5 -- +int(5) +array(5) { + [0]=> + string(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(44) "11 < 12. 123 >22 +2222 != 1111. 0000 = 0000 +" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +-- Iteration 6 -- +int(5) +array(5) { + [0]=> + string(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [1]=> + int(1) + [2]=> + float(2.222) +} +int(7) +array(7) { + [0]=> + string(123) "This's a string with quotes: +"strings in double quote"; +'strings in single quote'; +this\line is single quoted /with\slashes" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" + ["f"]=> + string(5) "first" + ["s"]=> + string(6) "second" + [3]=> + int(1) + [4]=> + float(2.222) +} +Done diff --git a/ext/standard/tests/array/array_user_key_compare.phpt b/ext/standard/tests/array/array_user_key_compare.phpt new file mode 100644 index 0000000..7f82f71 --- /dev/null +++ b/ext/standard/tests/array/array_user_key_compare.phpt @@ -0,0 +1,19 @@ +--TEST-- +Fix UMR in array_user_key_compare (MOPB24) +--FILE-- +<?php +$arr = array("A" => 1, "B" => 1); + +function array_compare(&$key1, &$key2) + { + $GLOBALS['a'] = &$key2; + unset($key2); + return 1; + } + +uksort($arr, "array_compare"); +var_dump($a); + +?> +--EXPECTF-- +string(1) "A" diff --git a/ext/standard/tests/array/array_values.phpt b/ext/standard/tests/array/array_values.phpt Binary files differnew file mode 100644 index 0000000..e5e46ca --- /dev/null +++ b/ext/standard/tests/array/array_values.phpt diff --git a/ext/standard/tests/array/array_values_basic.phpt b/ext/standard/tests/array/array_values_basic.phpt new file mode 100644 index 0000000..9cbdf07 --- /dev/null +++ b/ext/standard/tests/array/array_values_basic.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_values() function : basic functionality +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of array_values() + */ + +echo "*** Testing array_values() : basic functionality ***\n"; + + +// Initialise all required variables +$input = array('zero', 'one', 'two', 'three' => 3, 10 => 'ten'); + +// Calling array_values() with all possible arguments +var_dump( array_values($input) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : basic functionality *** +array(5) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + int(3) + [4]=> + string(3) "ten" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_error.phpt b/ext/standard/tests/array/array_values_error.phpt new file mode 100644 index 0000000..07d682c --- /dev/null +++ b/ext/standard/tests/array/array_values_error.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_values() function : error conditions - Pass incorrect number of functions +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to array_values to test behaviour + */ + +echo "*** Testing array_values() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_values() function with Zero arguments --\n"; +var_dump( array_values() ); + +//Test array_values with one more than the expected number of arguments +echo "\n-- Testing array_values() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$extra_arg = 10; +var_dump( array_values($input, $extra_arg) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : error conditions *** + +-- Testing array_values() function with Zero arguments -- + +Warning: array_values() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing array_values() function with more than expected no. of arguments -- + +Warning: array_values() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/array_values_errors.phpt b/ext/standard/tests/array/array_values_errors.phpt new file mode 100644 index 0000000..c8133dd --- /dev/null +++ b/ext/standard/tests/array/array_values_errors.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_values() function (errors) +--INI-- +precision=14 +--FILE-- +<?php + +echo "\n*** Testing error conditions ***\n"; +/* Invalid number of args */ +var_dump( array_values() ); // Zero arguments +var_dump( array_values(array(1,2,3), "") ); // No. of args > expected +/* Invalid types */ +var_dump( array_values("") ); // Empty string +var_dump( array_values(100) ); // Integer +var_dump( array_values(new stdclass) ); // object + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing error conditions *** + +Warning: array_values() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: array_values() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: array_values() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_values() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_values() expects parameter 1 to be array, object given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_values_variation.phpt b/ext/standard/tests/array/array_values_variation.phpt new file mode 100644 index 0000000..15da1a6 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test array_values() function (variation) +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--INI-- +precision=14 +--FILE-- +<?php + +echo "\n*** Testing array_values() with resource type ***\n"; +$resource1 = fopen(__FILE__, "r"); // Creating a file resource +$resource2 = opendir("."); // Creating a dir resource + +/* creating an array with resources as elements */ +$arr_resource = array( "a" => $resource1, "b" => $resource2); +var_dump( array_values($arr_resource) ); + +echo "\n*** Testing array_values() with range checking ***\n"; +$arr_range = array( + 2147483647, + 2147483648, + -2147483647, + -2147483648, + -0, + 0, + -2147483649 +); +var_dump( array_values($arr_range) ); + +echo "\n*** Testing array_values() on an array created on the fly ***\n"; +var_dump( array_values(array(1,2,3)) ); +var_dump( array_values(array()) ); // null array + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing array_values() with resource type *** +array(2) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) +} + +*** Testing array_values() with range checking *** +array(7) { + [0]=> + int(2147483647) + [1]=> + float(2147483648) + [2]=> + int(-2147483647) + [3]=> + float(-2147483648) + [4]=> + int(0) + [5]=> + int(0) + [6]=> + float(-2147483649) +} + +*** Testing array_values() on an array created on the fly *** +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_values_variation1.phpt b/ext/standard/tests/array/array_values_variation1.phpt new file mode 100644 index 0000000..53d0b5a --- /dev/null +++ b/ext/standard/tests/array/array_values_variation1.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test array_values() function : usage variations - Pass different data types as $input arg +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $input argument to array_values() to test behaviour + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $input argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( array_values($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1 -- + +Warning: array_values() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_values() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_values() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_values() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_values() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_values() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_values() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_values() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_values() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_values() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_values() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_values() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_values() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_values() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_values() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_values() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_values() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_values() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_values() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_values() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_values() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_values() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_values() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_values() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation2.phpt b/ext/standard/tests/array/array_values_variation2.phpt new file mode 100644 index 0000000..c7e9ad3 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation2.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test array_values() function : usage variations - arrays of different data types +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types as $input argument to array_values() to test behaviour + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_values($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) + [3]=> + int(-2345) +} + +-- Iteration 2: float data -- +array(5) { + [0]=> + float(10.5) + [1]=> + float(-10.5) + [2]=> + float(123456789000) + [3]=> + float(1.23456789E-9) + [4]=> + float(0.5) +} + +-- Iteration 3: null data -- +array(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- Iteration 4: bool data -- +array(4) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} + +-- Iteration 5: empty string data -- +array(2) { + [0]=> + string(0) "" + [1]=> + string(0) "" +} + +-- Iteration 6: empty array data -- +array(0) { +} + +-- Iteration 7: string data -- +array(3) { + [0]=> + string(6) "string" + [1]=> + string(6) "string" + [2]=> + string(11) "hello world" +} + +-- Iteration 8: object data -- +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9: undefined data -- +array(1) { + [0]=> + NULL +} + +-- Iteration 10: unset data -- +array(1) { + [0]=> + NULL +} + +-- Iteration 11: resource data -- +array(1) { + [0]=> + resource(%d) of type (stream) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation3.phpt b/ext/standard/tests/array/array_values_variation3.phpt new file mode 100644 index 0000000..5c74c0d --- /dev/null +++ b/ext/standard/tests/array/array_values_variation3.phpt @@ -0,0 +1,200 @@ +--TEST-- +Test array_values() function : usage variations - array keys different data types +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where the keys are different data types as $input argument + * to array_values() to test behaviour + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed as $input +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e10 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of array_values() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( array_values($input) ); + $iterator++; +}; +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(8) "positive" + [3]=> + string(8) "negative" +} + +-- Iteration 2: float data -- +array(3) { + [0]=> + string(8) "positive" + [1]=> + string(8) "negative" + [2]=> + string(4) "half" +} + +-- Iteration 3: extreme floats data -- +array(2) { + [0]=> + string(5) "large" + [1]=> + string(5) "small" +} + +-- Iteration 4: null uppercase data -- +array(1) { + [0]=> + string(6) "null 1" +} + +-- Iteration 5: null lowercase data -- +array(1) { + [0]=> + string(6) "null 2" +} + +-- Iteration 6: bool lowercase data -- +array(2) { + [0]=> + string(6) "lowert" + [1]=> + string(6) "lowerf" +} + +-- Iteration 7: bool uppercase data -- +array(2) { + [0]=> + string(6) "uppert" + [1]=> + string(6) "upperf" +} + +-- Iteration 8: empty double quotes data -- +array(1) { + [0]=> + string(6) "emptyd" +} + +-- Iteration 9: empty single quotes data -- +array(1) { + [0]=> + string(6) "emptys" +} + +-- Iteration 10: string data -- +array(3) { + [0]=> + string(7) "stringd" + [1]=> + string(7) "strings" + [2]=> + string(7) "stringh" +} + +-- Iteration 11: undefined data -- +array(1) { + [0]=> + string(9) "undefined" +} + +-- Iteration 12: unset data -- +array(1) { + [0]=> + string(5) "unset" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation4.phpt b/ext/standard/tests/array/array_values_variation4.phpt new file mode 100644 index 0000000..9c35331 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation4.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_values() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test array_values when: + * 1. Passed a two-dimensional array as $input argument + * 2. Passed a sub-array as $input argument + * 3. Passed an infinitely recursive multi-dimensional array + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +$input = array ('zero' => 'zero', 'un' => 'one', 'sub' => array (1, 2, 3)); + +echo "\n-- Array values of a two-dimensional array --\n"; +var_dump(array_values($input)); + +echo "\n-- Array values of a sub-array --\n"; +var_dump(array_values($input['sub'])); + +// get an infinitely recursive array +$input[] = &$input; +echo "\n-- Array values of an infinitely recursive array --\n"; +var_dump(array_values($input)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Array values of a two-dimensional array -- +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Array values of a sub-array -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +-- Array values of an infinitely recursive array -- +array(4) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [3]=> + &array(4) { + ["zero"]=> + string(4) "zero" + ["un"]=> + string(3) "one" + ["sub"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + *RECURSION* + } +} +Done diff --git a/ext/standard/tests/array/array_values_variation5.phpt b/ext/standard/tests/array/array_values_variation5.phpt new file mode 100644 index 0000000..d65b467 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation5.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_values() function : usage variations - internal array pointer +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test the position of the internal array pointer after a call to array_values + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +$input = array ('one' => 'un', 'two' => 'deux', 'three' => 'trois'); + +echo "\n-- Call array_values() --\n"; +var_dump($result = array_values($input)); + +echo "-- Position of Internal Pointer in Result: --\n"; +echo key($result) . " => " . current($result) . "\n"; +echo "\n-- Position of Internal Pointer in Original Array: --\n"; +echo key($input) . " => " . current ($input) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- Call array_values() -- +array(3) { + [0]=> + string(2) "un" + [1]=> + string(4) "deux" + [2]=> + string(5) "trois" +} +-- Position of Internal Pointer in Result: -- +0 => un + +-- Position of Internal Pointer in Original Array: -- +one => un +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation6.phpt b/ext/standard/tests/array/array_values_variation6.phpt new file mode 100644 index 0000000..8c4479c --- /dev/null +++ b/ext/standard/tests/array/array_values_variation6.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_values() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Test array_values() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array by reference + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +$val1 = 'one'; +$val2 = 'two'; +$val3 = 'three'; + +echo "\n-- \$input is an array made up of referenced variables: --\n"; +$input = array(&$val1, &$val2, &$val3); +var_dump($result1 = array_values($input)); + +echo "Change \$val2 and check result of array_values():\n"; +$val2 = 'deux'; +var_dump($result1); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- $input is an array made up of referenced variables: -- +array(3) { + [0]=> + &string(3) "one" + [1]=> + &string(3) "two" + [2]=> + &string(5) "three" +} +Change $val2 and check result of array_values(): +array(3) { + [0]=> + &string(3) "one" + [1]=> + &string(4) "deux" + [2]=> + &string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_values_variation7.phpt b/ext/standard/tests/array/array_values_variation7.phpt new file mode 100644 index 0000000..b713064 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation7.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_values() function : usage variations - Internal order check +--FILE-- +<?php +/* Prototype : array array_values(array $input) + * Description: Return just the values from the input array + * Source code: ext/standard/array.c + */ + +/* + * Check that array_values is re-assigning keys according to the internal order of the array, + * and is not dependant on the \$input argument's keys + */ + +echo "*** Testing array_values() : usage variations ***\n"; + +// populate array with 'default' keys in reverse order +$input = array(3 => 'three', 2 => 'two', 1 => 'one', 0 => 'zero'); + +echo "\n-- \$input argument: --\n"; +var_dump($input); + +echo "\n-- Result of array_values() --\n"; +var_dump(array_values($input)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_values() : usage variations *** + +-- $input argument: -- +array(4) { + [3]=> + string(5) "three" + [2]=> + string(3) "two" + [1]=> + string(3) "one" + [0]=> + string(4) "zero" +} + +-- Result of array_values() -- +array(4) { + [0]=> + string(5) "three" + [1]=> + string(3) "two" + [2]=> + string(3) "one" + [3]=> + string(4) "zero" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/array_values_variation_64bit.phpt b/ext/standard/tests/array/array_values_variation_64bit.phpt new file mode 100644 index 0000000..8b1e2c0 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation_64bit.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test array_values() function +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--INI-- +precision=14 +--FILE-- +<?php + +echo "\n*** Testing array_values() with resource type ***\n"; +$resource1 = fopen(__FILE__, "r"); // Creating a file resource +$resource2 = opendir("."); // Creating a dir resource + +/* creating an array with resources as elements */ +$arr_resource = array( "a" => $resource1, "b" => $resource2); +var_dump( array_values($arr_resource) ); + +echo "\n*** Testing array_values() with range checking ***\n"; +$arr_range = array( + 2147483647, + 2147483648, + -2147483647, + -2147483648, + -0, + 0, + -2147483649 +); +var_dump( array_values($arr_range) ); + +echo "\n*** Testing array_values() on an array created on the fly ***\n"; +var_dump( array_values(array(1,2,3)) ); +var_dump( array_values(array()) ); // null array + +?> +--EXPECTF-- +*** Testing array_values() with resource type *** +array(2) { + [0]=> + resource(%d) of type (stream) + [1]=> + resource(%d) of type (stream) +} + +*** Testing array_values() with range checking *** +array(7) { + [0]=> + int(2147483647) + [1]=> + int(2147483648) + [2]=> + int(-2147483647) + [3]=> + int(-2147483648) + [4]=> + int(0) + [5]=> + int(0) + [6]=> + int(-2147483649) +} + +*** Testing array_values() on an array created on the fly *** +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +array(0) { +} diff --git a/ext/standard/tests/array/array_walk.phpt b/ext/standard/tests/array/array_walk.phpt new file mode 100644 index 0000000..35ef02e --- /dev/null +++ b/ext/standard/tests/array/array_walk.phpt @@ -0,0 +1,50 @@ +--TEST-- +array_walk() tests +--FILE-- +<?php + +var_dump(array_walk()); +$var = 1; +var_dump(array_walk($var,1)); +$var = array(); +var_dump(array_walk($var,"")); + +function foo($v1, $v2, $v3) { + var_dump($v1); + var_dump($v2); + var_dump($v3); +} + +$var = array(1,2); +var_dump(array_walk($var, "foo", "data")); + +function foo2($v1, $v2, $v3) { + throw new Exception($v3); +} + +try { + var_dump(array_walk($var,"foo2", "data")); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +int(1) +int(0) +string(4) "data" +int(2) +int(1) +string(4) "data" +bool(true) +string(4) "data" +Done diff --git a/ext/standard/tests/array/array_walk_basic1.phpt b/ext/standard/tests/array/array_walk_basic1.phpt new file mode 100644 index 0000000..e4bdf1b --- /dev/null +++ b/ext/standard/tests/array/array_walk_basic1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_walk() function : basic functionality - regular array +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk() : basic functionality ***\n"; + +// regular array +$fruits = array("lemon", "orange", "banana", "apple"); + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - item in key/item pair + * key - key in key/item pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} +function with_userdata($item, $key, $user_data) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($user_data); // user supplied data + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk() with default parameters to show array contents --\n"; +var_dump( array_walk($fruits, 'test_print')); + +echo "-- Using array_walk() with all parameters --\n"; +var_dump( array_walk($fruits, 'with_userdata', "Added")); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(1) + +string(6) "banana" +int(2) + +string(5) "apple" +int(3) + +bool(true) +-- Using array_walk() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(1) +string(5) "Added" + +string(6) "banana" +int(2) +string(5) "Added" + +string(5) "apple" +int(3) +string(5) "Added" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_basic2.phpt b/ext/standard/tests/array/array_walk_basic2.phpt new file mode 100644 index 0000000..e856b58 --- /dev/null +++ b/ext/standard/tests/array/array_walk_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test array_walk() function : basic functionality - associative array +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk() : basic functionality ***\n"; + +// associative array +$fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); + +// User defined callback functions +/* Prototype : test_alter(mixed $item, mixed $key, string $prefix) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * prefix - string to be added + * Description : alters the array values by appending prefix string + */ +function test_alter(&$item, $key, $prefix) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($prefix); // additional agument passed to callback function + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk with default parameters to show array contents --\n"; +var_dump(array_walk($fruits, 'test_print')); + +echo "-- Using array_walk with one optional parameter to modify contents --\n"; +var_dump (array_walk($fruits, 'test_alter', 'fruit')); + +echo "-- Using array_walk with default parameters to show modified array contents --\n"; +var_dump (array_walk($fruits, 'test_print')); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk with default parameters to show array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +-- Using array_walk with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "d" +string(5) "fruit" + +string(6) "orange" +string(1) "a" +string(5) "fruit" + +string(6) "banana" +string(1) "b" +string(5) "fruit" + +string(5) "apple" +string(1) "c" +string(5) "fruit" + +bool(true) +-- Using array_walk with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_error1.phpt b/ext/standard/tests/array/array_walk_error1.phpt new file mode 100644 index 0000000..334dfe4 --- /dev/null +++ b/ext/standard/tests/array/array_walk_error1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_walk() function : error conditions +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +$input = array(1, 2); + +/* Prototype : callback(mixed value, mixed key, mixed user_data) + * Parameters : value - value in key/value pair + * key - key in key/value pair + * user_data - extra parameter + */ +function callback ($value, $key, $user_data) { + echo "\ncallback() invoked \n"; +} + +echo "*** Testing array_walk() : error conditions ***\n"; + +echo "-- Testing array_walk() function with zero arguments --\n"; +var_dump( array_walk() ); + +echo "-- Testing array_walk() function with one argument --\n"; +var_dump( array_walk($input) ); + +echo "-- Testing array_walk() function with non existent callback function --\n"; +var_dump( array_walk($input, "non_existent") ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk() : error conditions *** +-- Testing array_walk() function with zero arguments -- + +Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d +NULL +-- Testing array_walk() function with one argument -- + +Warning: array_walk() expects at least 2 parameters, 1 given in %s on line %d +NULL +-- Testing array_walk() function with non existent callback function -- + +Warning: array_walk() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_error2.phpt b/ext/standard/tests/array/array_walk_error2.phpt new file mode 100644 index 0000000..654637a --- /dev/null +++ b/ext/standard/tests/array/array_walk_error2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk() function : error conditions - callback parameters +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() by passing more number of parameters to callback function + */ +$input = array(1); + +function callback1($value, $key, $user_data ) { + echo "\ncallback1() invoked \n"; +} + +function callback2($value, $key, $user_data1, $user_data2) { + echo "\ncallback2() invoked \n"; +} +echo "*** Testing array_walk() : error conditions - callback parameters ***\n"; + +// expected: Missing argument Warning +var_dump( array_walk($input, "callback1") ); +var_dump( array_walk($input, "callback2", 4) ); + +// expected: Warning is supressed +var_dump( @array_walk($input, "callback1") ); +var_dump( @array_walk($input, "callback2", 4) ); + +echo "-- Testing array_walk() function with too many callback parameters --\n"; +var_dump( array_walk($input, "callback1", 20, 10) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk() : error conditions - callback parameters *** + +Warning: Missing argument 3 for callback1() in %s on line %d + +callback1() invoked +bool(true) + +Warning: Missing argument 4 for callback2() in %s on line %d + +callback2() invoked +bool(true) + +callback1() invoked +bool(true) + +callback2() invoked +bool(true) +-- Testing array_walk() function with too many callback parameters -- + +Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_object1.phpt b/ext/standard/tests/array/array_walk_object1.phpt new file mode 100644 index 0000000..342e760 --- /dev/null +++ b/ext/standard/tests/array/array_walk_object1.phpt @@ -0,0 +1,67 @@ +--TEST-- +Test array_walk() function : object functionality +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Pasing object in place of 'input' argument to test object functionatlity +*/ + +echo "*** Testing array_walk() : object functionality ***\n"; + +/* + * Prototype : callback(mixed $value, mixed $key, int $addvalue + * Parameters : $value - values in given input array + * $key - keys in given input array + * $addvalue - value to be added + * Description : Function adds the addvalue to each element of an array +*/ + +function callback($value, $key, $user_data) +{ + var_dump($key); + var_dump($value); + var_dump($user_data); + echo "\n"; +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } +}; + +// object for 'input' argument +$input = new MyClass(10); + +var_dump( array_walk($input, "callback", 1)); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : object functionality *** +%unicode|string%(18) "%r\0%rMyClass%r\0%rpri_value" +int(10) +int(1) + +%unicode|string%(9) "pub_value" +int(10) +int(1) + +%unicode|string%(12) "%r\0%r*%r\0%rpro_value" +int(10) +int(1) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_object2.phpt b/ext/standard/tests/array/array_walk_object2.phpt new file mode 100644 index 0000000..61d0529 --- /dev/null +++ b/ext/standard/tests/array/array_walk_object2.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test array_walk() function : object functionality - array of objects +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_walk() with an array of objects +*/ + +echo "*** Testing array_walk() : array of objects ***\n"; + +/* + * Prototype : callback(mixed $value, mixed $key, int $addvalue + * Parameters : $value - values in given input array + * $key - keys in given input array + * $addvalue - value to be added + * Description : Function adds the addvalue to each element of an array +*/ +function callback_private($value, $key, $addValue) +{ + echo "value : "; + var_dump($value->getValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +// array containing objects of MyClass +$input = array ( + new MyClass(3), + new MyClass(10), + new MyClass(20), + new MyClass(-10) +); + +echo "-- For private member --\n"; +var_dump( array_walk($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk($input, "callback_protected")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(2) +value : int(-10) +key : int(3) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_objects.phpt b/ext/standard/tests/array/array_walk_objects.phpt new file mode 100644 index 0000000..506d1ca --- /dev/null +++ b/ext/standard/tests/array/array_walk_objects.phpt @@ -0,0 +1,44 @@ +--TEST-- +array_walk() and objects +--FILE-- +<?php + +function walk($key, $value) { + var_dump($value, $key); +} + +class test { + private $var_pri = "test_private"; + protected $var_pro = "test_protected"; + public $var_pub = "test_public"; +} + +$stdclass = new stdclass; +$stdclass->foo = "foo"; +$stdclass->bar = "bar"; +array_walk($stdclass, "walk"); + +$t = new test; +array_walk($t, "walk"); + +$var = array(); +array_walk($var, "walk"); +$var = ""; +array_walk($var, "walk"); + +echo "Done\n"; +?> +--EXPECTF-- +%unicode|string%(3) "foo" +%unicode|string%(3) "foo" +%unicode|string%(3) "bar" +%unicode|string%(3) "bar" +%unicode|string%(13) "%r\0%rtest%r\0%rvar_pri" +%unicode|string%(12) "test_private" +%unicode|string%(10) "%r\0%r*%r\0%rvar_pro" +%unicode|string%(14) "test_protected" +%unicode|string%(7) "var_pub" +%unicode|string%(11) "test_public" + +Warning: array_walk() expects parameter 1 to be array, %unicode_string_optional% given in %s on line %d +Done diff --git a/ext/standard/tests/array/array_walk_rec_objects.phpt b/ext/standard/tests/array/array_walk_rec_objects.phpt new file mode 100644 index 0000000..bbd30f3 --- /dev/null +++ b/ext/standard/tests/array/array_walk_rec_objects.phpt @@ -0,0 +1,44 @@ +--TEST-- +array_walk_recursive() and objects +--FILE-- +<?php + +function walk($key, $value) { + var_dump($value, $key); +} + +class test { + private $var_pri = "test_private"; + protected $var_pro = "test_protected"; + public $var_pub = "test_public"; +} + +$stdclass = new stdclass; +$stdclass->foo = "foo"; +$stdclass->bar = "bar"; +array_walk_recursive($stdclass, "walk"); + +$t = new test; +array_walk_recursive($t, "walk"); + +$var = array(); +array_walk_recursive($var, "walk"); +$var = ""; +array_walk_recursive($var, "walk"); + +echo "Done\n"; +?> +--EXPECTF-- +%unicode|string%(3) "foo" +%unicode|string%(3) "foo" +%unicode|string%(3) "bar" +%unicode|string%(3) "bar" +%unicode|string%(13) "%r\0%rtest%r\0%rvar_pri" +%unicode|string%(12) "test_private" +%unicode|string%(10) "%r\0%r*%r\0%rvar_pro" +%unicode|string%(14) "test_protected" +%unicode|string%(7) "var_pub" +%unicode|string%(11) "test_public" + +Warning: array_walk_recursive() expects parameter 1 to be array, %unicode_string_optional% given in %s on line %d +Done diff --git a/ext/standard/tests/array/array_walk_recursive.phpt b/ext/standard/tests/array/array_walk_recursive.phpt new file mode 100644 index 0000000..c3b37c3 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test array_walk_recursive() +--FILE-- +<?php +function foo($value) { + echo $value . " foo\n"; +} + +function bar($value) { + echo $value . " bar\n"; +} + +$arr = array (1,2,3); +var_dump (array_walk_recursive ($arr, 'foo')); +var_dump (array_walk_recursive ($arr, 'bar')); + +?> +--EXPECTF-- +1 foo +2 foo +3 foo +bool(true) +1 bar +2 bar +3 bar +bool(true) diff --git a/ext/standard/tests/array/array_walk_recursive1.phpt b/ext/standard/tests/array/array_walk_recursive1.phpt new file mode 100644 index 0000000..65939d5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive1.phpt @@ -0,0 +1,56 @@ +--TEST-- +array_walk_recursive() tests +--FILE-- +<?php + +var_dump(array_walk_recursive()); +$var = 1; +var_dump(array_walk_recursive($var,1)); +$var = array(); +var_dump(array_walk_recursive($var,"")); + +function foo($v1, $v2, $v3) { + var_dump($v1); + var_dump($v2); + var_dump($v3); +} + +$var = array(1,2, array(2,3)); +var_dump(array_walk_recursive($var, "foo", "data")); + +function foo2($v1, $v2, $v3) { + throw new Exception($v3); +} + +try { + var_dump(array_walk_recursive($var,"foo2", "data")); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +int(1) +int(0) +string(4) "data" +int(2) +int(1) +string(4) "data" +int(2) +int(0) +string(4) "data" +int(3) +int(1) +string(4) "data" +bool(true) +string(4) "data" +Done diff --git a/ext/standard/tests/array/array_walk_recursive_basic1.phpt b/ext/standard/tests/array/array_walk_recursive_basic1.phpt new file mode 100644 index 0000000..df192b6 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_basic1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - regular array +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk_recursive() : basic functionality ***\n"; + +// regular array +$fruits = array("lemon", array("orange", "banana"), array("apple")); + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - item in key/item pair + * key - key in key/item pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} +function with_userdata($item, $key, $user_data) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($user_data); // user supplied data + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk_recursive() with default parameters to show array contents --\n"; +var_dump( array_walk_recursive($fruits, 'test_print')); + +echo "-- Using array_walk_recursive() with all parameters --\n"; +var_dump( array_walk_recursive($fruits, 'with_userdata', "Added")); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(0) + +string(6) "banana" +int(1) + +string(5) "apple" +int(0) + +bool(true) +-- Using array_walk_recursive() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(0) +string(5) "Added" + +string(6) "banana" +int(1) +string(5) "Added" + +string(5) "apple" +int(0) +string(5) "Added" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_basic2.phpt b/ext/standard/tests/array/array_walk_recursive_basic2.phpt new file mode 100644 index 0000000..c71d92b --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - associative array +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_walk_recursive() : basic functionality ***\n"; + +// associative array +$fruits = array("a" => "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple")); + +// User defined callback functions +/* Prototype : test_alter(mixed $item, mixed $key, string $prefix) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * prefix - string to be added + * Description : alters the array values by appending prefix string + */ +function test_alter(&$item, $key, $prefix) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($prefix); // additional agument passed to callback function + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk_recursive with default parameters to show array contents --\n"; +var_dump(array_walk_recursive($fruits, 'test_print')); + +echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n"; +var_dump (array_walk_recursive($fruits, 'test_alter', 'fruit')); + +echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n"; +var_dump (array_walk_recursive($fruits, 'test_print')); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive with default parameters to show array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +-- Using array_walk_recursive with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "a" +string(5) "fruit" + +string(6) "orange" +string(1) "c" +string(5) "fruit" + +string(6) "banana" +string(1) "d" +string(5) "fruit" + +string(5) "apple" +string(1) "f" +string(5) "fruit" + +bool(true) +-- Using array_walk_recursive with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_error1.phpt b/ext/standard/tests/array/array_walk_recursive_error1.phpt new file mode 100644 index 0000000..75966e8 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error1.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_walk_recursive() function : error conditions +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +$input = array(1, 2); + +/* Prototype : callback(mixed value, mixed key, mixed user_data) + * Parameters : value - value in key/value pair + * key - key in key/value pair + * user_data - extra parameter + */ +function callback ($value, $key, $user_data) { + echo "\ncallback() invoked \n"; +} + +echo "*** Testing array_walk_recursive() : error conditions ***\n"; + +echo "-- Testing array_walk_recursive() function with zero arguments --\n"; +var_dump( array_walk_recursive() ); + +echo "-- Testing array_walk_recursive() function with one argument --\n"; +var_dump( array_walk_recursive($input) ); + +$input = array( array(1, 2), array(3), array(4, 5)); +echo "-- Testing array_walk_recursive() function with non existent callback function --\n"; +var_dump( array_walk_recursive($input, "non_existent") ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk_recursive() : error conditions *** +-- Testing array_walk_recursive() function with zero arguments -- + +Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d +NULL +-- Testing array_walk_recursive() function with one argument -- + +Warning: array_walk_recursive() expects at least 2 parameters, 1 given in %s on line %d +NULL +-- Testing array_walk_recursive() function with non existent callback function -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_error2.phpt b/ext/standard/tests/array/array_walk_recursive_error2.phpt new file mode 100644 index 0000000..d628e93 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk_recursive() function : error conditions - callback parameters +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() by passing more number of parameters to callback function + */ +$input = array(1); + +function callback1($value, $key, $user_data ) { + echo "\ncallback1() invoked \n"; +} + +function callback2($value, $key, $user_data1, $user_data2) { + echo "\ncallback2() invoked \n"; +} +echo "*** Testing array_walk_recursive() : error conditions - callback parameters ***\n"; + +// expected: Missing argument Warning +var_dump( array_walk_recursive($input, "callback1") ); +var_dump( array_walk_recursive($input, "callback2", 4) ); + +// expected: Warning is supressed +var_dump( @array_walk_recursive($input, "callback1") ); +var_dump( @array_walk_recursive($input, "callback2", 4) ); + +echo "-- Testing array_walk_recursive() function with too many callback parameters --\n"; +var_dump( array_walk_recursive($input, "callback1", 20, 10) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_walk_recursive() : error conditions - callback parameters *** + +Warning: Missing argument 3 for callback1() in %s on line %d + +callback1() invoked +bool(true) + +Warning: Missing argument 4 for callback2() in %s on line %d + +callback2() invoked +bool(true) + +callback1() invoked +bool(true) + +callback2() invoked +bool(true) +-- Testing array_walk_recursive() function with too many callback parameters -- + +Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_object1.phpt b/ext/standard/tests/array/array_walk_recursive_object1.phpt new file mode 100644 index 0000000..7ddced7 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_object1.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test array_walk_recursive() function : object functionality +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* Passing object in place of an 'input' argument to test object functionality + */ +echo "*** Testing array_walk_recursive() : object functionality ***\n"; + +/* + * Prototype : callback(mixed $value, mixed $key, int $addvalue + * Parameters : $value - values in given input array + * $key - keys in given input array + * $addvalue - value to be added + * Description : Function adds the addvalue to each element of an array +*/ + +function callback($value, $key, $user_data) +{ + var_dump($key); + var_dump($value); + var_dump($user_data); + echo "\n"; +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } +}; + +// object for 'input' argument +$input = new MyClass(10); + +var_dump( array_walk_recursive($input, "callback", 1)); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : object functionality *** +%unicode|string%(18) "%r\0%rMyClass%r\0%rpri_value" +int(10) +int(1) + +%unicode|string%(9) "pub_value" +int(10) +int(1) + +%unicode|string%(12) "%r\0%r*%r\0%rpro_value" +int(10) +int(1) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_object2.phpt b/ext/standard/tests/array/array_walk_recursive_object2.phpt new file mode 100644 index 0000000..aa12fe8 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_object2.phpt @@ -0,0 +1,106 @@ +--TEST-- +Test array_walk_recursive() function : object functionality - array of objects +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_walk_recursive() with an array of objects +*/ + +echo "*** Testing array_walk_recursive() : array of objects ***\n"; + +/* + * Prototype : callback(mixed $value, mixed $key, int $addvalue + * Parameters : $value - values in given input array + * $key - keys in given input array + * $addvalue - value to be added + * Description : Function adds the addvalue to each element of an array +*/ +function callback_private($value, $key, $addValue) +{ + echo "value : "; + var_dump($value->getValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +// array containing objects of MyClass +$input = array ( + array( + new MyClass(3), + new MyClass(10), + ), + new MyClass(20), + array(new MyClass(-10)) +); + +echo "-- For private member --\n"; +var_dump( array_walk_recursive($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk_recursive($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk_recursive($input, "callback_protected")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(1) +value : int(-10) +key : int(0) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation1.phpt b/ext/standard/tests/array/array_walk_recursive_variation1.phpt new file mode 100644 index 0000000..16044e2 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation1.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'input' argument +*/ + +echo "*** Testing array_walk_recursive() : unexpected values for 'input' argument ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values given in input array + * $key - keys given in input array + * Description : Function prints each element of an array with key + */ +function callback($value, $key) +{ + echo "key : "; + var_dump($key); + echo "value : "; + var_dump($value); +} + +// extra parameter passed to array_walk_recursive() +$user_data = 10; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// different scalar/nonscalar values to be used in place of an 'input' argument +$input_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/* 10*/ NULL, + null, + + // boolean data +/* 12*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 16*/ "", + '', + + // string data +/* 18*/ "string", + 'string', + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/* 22*/ @$unset_var, +); + + +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input_values[$count], "callback") ); + var_dump( array_walk_recursive($input_values[$count], "callback", $user_data) ); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : unexpected values for 'input' argument *** +-- Iteration 1 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, resource given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation2.phpt b/ext/standard/tests/array/array_walk_recursive_variation2.phpt new file mode 100644 index 0000000..bef44b5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation2.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values in place of 'funcname' argument +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'funcname' argument +*/ + +echo "*** Testing array_walk_recursive() : unexpected values for 'funcname' argument ***\n"; + +$input = array(1, array(2, 3)); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$user_data = 20; + +// class definition +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +// different scalar/nonscalar values to be used in place of callback function +$funcname_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/* 10*/ array(), + array(0), + array(1), + array('color' => 'red', 'item' => 'pen'), + + // null data +/* 14*/ NULL, + null, + + // boolean data +/* 16*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 20*/ "", + '', + + // object data + new MyClass(), + + // resource data +/* 23*/ $fp = fopen(__FILE__, 'r'), + + // undefined data + @$undefined_var, + + // unset data +/* 25*/ @$unset_var, +); + +for($count = 0; $count < count($funcname_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input, $funcname_values[$count]) ); + var_dump( array_walk_recursive($input, $funcname_values[$count], $user_data )); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : unexpected values for 'funcname' argument *** +-- Iteration 1 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 25 -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation3.phpt b/ext/standard/tests/array/array_walk_recursive_variation3.phpt new file mode 100644 index 0000000..9abdc0b --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation3.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with different values +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() with following types of 'input' arrays: + * integer, float, string, bool, null, empty & mixed +*/ + +// callback function +/* + * Prototype : print_value(mixed $value, int $key, int $count) + * Parameters : $value - array entries(values) + * $key - keys in given input array + * $count - extra parameter used as an index + * Description : prints the array values with keys and count value + */ +function print_value($value, $key, $count) +{ + echo $count." : ".$key." ".$value."\n"; +} + +echo "*** Testing array_walk_recursive() : 'input' array with different values***\n"; + +// different arrays as input +$input_values = array( + + // integer values +/*1*/ array(array(1, 0, -10), array(023, -041), array(0x5A, 0X1F, -0x6E)), + + // float value + array(array(3.4, 0.8, -2.9), array(6.25e2, 8.20E-3)), + + // string values + array('Mango', array("Apple", 'Orange', "Lemon")), + + // bool values +/*4*/ array( array(true, false), array(TRUE, FALSE)), + + // null values + array( array(null), array(NULL)), + + // empty array + array(), + + // binary array + array(array(b'binary')), + + // mixed array +/*8*/ array(16, 8.345, array("Fruits"), array(true, null), array(FALSE), array(-98, 0.005, 'banana')) +); + +for($count = 0; $count < count($input_values); $count++) { + echo "\n-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input_values[$count], "print_value", $count+1)); +} +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 0 19 +1 : 1 -33 +1 : 0 90 +1 : 1 31 +1 : 2 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 0 625 +2 : 1 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 0 Apple +3 : 1 Orange +3 : 2 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 0 1 +4 : 1 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 0 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 0 Fruits +8 : 0 1 +8 : 1 +8 : 0 +8 : 0 -98 +8 : 1 0.005 +8 : 2 banana +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation4.phpt b/ext/standard/tests/array/array_walk_recursive_variation4.phpt new file mode 100644 index 0000000..4db3497 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation4.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with subarray +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() with an array having subarrays as elements +*/ + +echo "*** Testing array_walk_recursive() : array with subarray ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values in given 'input' array + * $key - keys in given 'input' array + * Description : It prints the count of an array elements, passed as argument + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +$input = array( + array(), + array(1), + array(1,2,3), + array("Mango", "Orange"), + array(array(1, 2, 3), array(1)) +); + +var_dump( array_walk_recursive( $input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array with subarray *** +int(0) +int(1) + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +string(5) "Mango" + +int(1) +string(6) "Orange" + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +int(1) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation5.phpt b/ext/standard/tests/array/array_walk_recursive_variation5.phpt new file mode 100644 index 0000000..688da57 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation5.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument containing reference variables +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk_recursive() with an array having reference variables +*/ + +echo "*** Testing array_walk_recursive() : array with references ***\n"; + +$value1 = 10; +$value2 = -20; +$value3 = &$value1; +$value4 = 50; + +// 'input' array containing references to above variables +$input = array(&$value1, array(&$value2, -35), array(&$value3, 0), array(&$value4)); + +// callback function +/* Prototype : callback(int $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : function checks for the value whether positive or negative and displays according to that + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +var_dump( array_walk_recursive($input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array with references *** +int(0) +int(10) + +int(0) +int(-20) + +int(1) +int(-35) + +int(0) +int(10) + +int(1) +int(0) + +int(0) +int(50) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation6.phpt b/ext/standard/tests/array/array_walk_recursive_variation6.phpt new file mode 100644 index 0000000..747eb74 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation6.phpt @@ -0,0 +1,147 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing 'input' argument as an associative array + * with Numeric & string keys +*/ + +echo "*** Testing array_walk_recursive() : 'input' as an associative array ***\n"; + +// callback functions +/* Prototype : for_numeric( int $value, int $key, int $user_data) + * Parameters : $value - value from key/value pair of the array + * $key - key from key/value pair of the array + * $user_data - data to be added to 'value' + * Description : Function adds values with keys & user_data + */ +function for_numeric($value, $key, $user_data) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + var_dump($user_data); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_string( string $value, string $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function appends key to the value + */ +function for_string($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_mixed( mixed $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function displays each element of an array with keys + */ +function for_mixed($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +// Numeric keys +$input = array( 0 => array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30)); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk_recursive($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange")); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// binary key +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk_recursive($input, "for_mixed")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(12) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +int(5) +int(30) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation7.phpt b/ext/standard/tests/array/array_walk_recursive_variation7.phpt new file mode 100644 index 0000000..0cdd6d2 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation7.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - anonymous callback function +--FILE-- +<?php +/* Prototype : proto bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Passing anonymous(run-time) callback function with following variations: +* with one parameter +* two parameters +* three parameters +* extra parameters +* without parameters +*/ + +echo "*** Testing array_walk_recursive() : anonymous function as callback ***\n"; + +$input = array( array(2, 5), array(10, 0)); + +echo "-- Anonymous function with one argument --\n"; +var_dump( array_walk_recursive($input, create_function('$value', 'var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with two arguments --\n"; +var_dump( array_walk_recursive($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with three arguments --\n"; +var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10)); + +echo "-- Anonymous function with one more argument --\n"; +var_dump( array_walk_recursive($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); + +echo "-- Anonymous function with null argument --\n"; +var_dump( array_walk_recursive( $input, create_function(null, 'echo "1\n";'))); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(0) +int(10) + +int(1) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(0) +int(10) +int(10) + +int(1) +int(0) +int(10) + +bool(true) +-- Anonymous function with one more argument -- + +Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d +NULL +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation8.phpt b/ext/standard/tests/array/array_walk_recursive_variation8.phpt new file mode 100644 index 0000000..671fcdb --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - buit-in function as callback +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different buit-in functionns as callback function + * pow function + * min function + * echo language construct +*/ + +echo "*** Testing array_walk_recursive() : built-in function as callback ***\n"; + +$input = array(array(2 => 1, 65), array(98, 100), array(6 => -4)); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk_recursive($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk_recursive($input, "min")); + +echo "-- With 'echo' language construct --\n"; +var_dump( array_walk_recursive($input, "echo")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- + +Warning: array_walk_recursive() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation9.phpt b/ext/standard/tests/array/array_walk_recursive_variation9.phpt new file mode 100644 index 0000000..f18fe24 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - different callback functions +--FILE-- +<?php +/* Prototype : bool array_walk_recursive(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different types of callback functions to array_walk_recursive() + * without parameters + * with less and more parameters +*/ + +echo "*** Testing array_walk_recursive() : callback function variation ***\n"; + +$input = array(array('Apple', 'Banana'), 'Mango', array('Orange')); + +echo "-- callback function with both parameters --\n"; +function callback_two_parameter($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk_recursive($input, 'callback_two_parameter')); + +echo "-- callback function with only one parameter --\n"; +function callback_one_parameter($value) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk_recursive($input, 'callback_one_parameter')); + +echo "-- callback function without parameters --\n"; +function callback_no_parameter() +{ + echo "callback3() called\n"; +} +var_dump( array_walk_recursive($input, 'callback_no_parameter')); + +echo "-- passing one more parameter to function with two parameters --\n"; +var_dump( array_walk_recursive($input, 'callback_two_parameter', 10)); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation1.phpt b/ext/standard/tests/array/array_walk_variation1.phpt new file mode 100644 index 0000000..d1c91bb --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation1.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test array_walk() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'input' argument +*/ + +echo "*** Testing array_walk() : unexpected values for 'input' argument ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values given in input array + * $key - keys given in input array + * Description : Function prints each element of an array with key + */ +function callback($value, $key) +{ + echo "key : "; + var_dump($key); + echo "value : "; + var_dump($value); +} + +// extra parameter passed to array_walk() +$user_data = 10; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// different scalar/nonscalar values to be used in place of an 'input' argument +$input_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/* 10*/ NULL, + null, + + // boolean data +/* 12*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 16*/ "", + '', + + // string data +/* 18*/ "string", + 'string', + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/* 22*/ @$unset_var, +); + + +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk($input_values[$count], "callback") ); + var_dump( array_walk($input_values[$count], "callback", $user_data) ); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : unexpected values for 'input' argument *** +-- Iteration 1 -- + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_walk() expects parameter 1 to be array, resource given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_walk() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_variation2.phpt b/ext/standard/tests/array/array_walk_variation2.phpt new file mode 100644 index 0000000..5cfee36 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation2.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_walk() function : usage variations - unexpected values in place of 'funcname' argument +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different scalar/nonscalar values in place of 'funcname' argument +*/ + +echo "*** Testing array_walk() : unexpected values for 'funcname' argument ***\n"; + +$input = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$user_data = 20; + +// class definition +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +// different scalar/nonscalar values to be used in place of callback function +$funcname_values = array( + + // int data +/* 1*/ 0, + 1, + 12345, + -2345, + + // float data +/* 5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/* 10*/ array(), + array(0), + array(1), + array('color' => 'red', 'item' => 'pen'), + + // null data +/* 14*/ NULL, + null, + + // boolean data +/* 16*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 20*/ "", + '', + + // object data + new MyClass(), + + // resource data +/* 23*/ $fp = fopen(__FILE__, 'r'), + + // undefined data + @$undefined_var, + + // unset data +/* 25*/ @$unset_var, +); + +for($count = 0; $count < count($funcname_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk($input, $funcname_values[$count]) ); + var_dump( array_walk($input, $funcname_values[$count], $user_data )); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : unexpected values for 'funcname' argument *** +-- Iteration 1 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 25 -- + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_walk() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_variation3.phpt b/ext/standard/tests/array/array_walk_variation3.phpt new file mode 100644 index 0000000..9ff7d5d --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation3.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with different values +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() with following types of 'input' arrays: + * integer, float, string, bool, null, empty & mixed +*/ + +// callback function +/* + * Prototype : print_value(mixed $value, int $key, int $count) + * Parameters : $value - array entries(values) + * $key - keys in given input array + * $count - extra parameter used as an index + * Description : prints the array values with keys and count value + */ +function print_value($value, $key, $count) +{ + echo $count." : ".$key." ".$value."\n"; +} + +echo "*** Testing array_walk() : 'input' array with different values***\n"; + +// different arrays as input +$input_values = array( + + // integer values +/*1*/ array(1, 0, -10, 023, -041, 0x5A, 0X1F, -0x6E), + + // float value + array(3.4, 0.8, -2.9, 6.25e2, 8.20E-3), + + // string values + array('Mango', "Apple", 'Orange', "Lemon"), + + // bool values +/*4*/ array(true, false, TRUE, FALSE), + + // null values + array(null, NULL), + + // empty array + array(), + + // binary array + array(b"binary"), + + // mixed array +/*8*/ array(16, 8.345, "Fruits", true, null, FALSE, -98, 0.005, 'banana') +); + +for($count = 0; $count < count($input_values); $count++) { + echo "\n-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk($input_values[$count], "print_value", $count+1)); +} +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 3 19 +1 : 4 -33 +1 : 5 90 +1 : 6 31 +1 : 7 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 3 625 +2 : 4 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 1 Apple +3 : 2 Orange +3 : 3 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 2 1 +4 : 3 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 1 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 2 Fruits +8 : 3 1 +8 : 4 +8 : 5 +8 : 6 -98 +8 : 7 0.005 +8 : 8 banana +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation4.phpt b/ext/standard/tests/array/array_walk_variation4.phpt new file mode 100644 index 0000000..868732d --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation4.phpt @@ -0,0 +1,87 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with subarray +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() with an array having subarrays as elements +*/ + +echo "*** Testing array_walk() : array with subarray ***\n"; + +// callback function +/* Prototype : callback(mixed $value, mixed $key) + * Parameters : $value - values in given 'input' array + * $key - keys in given 'input' array + * Description : It prints the count of an array elements, passed as argument + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +$input = array( + array(), + array(1), + array(1,2,3), + array("Mango", "Orange"), + array(array(1, 2, 3)) +); + +var_dump( array_walk( $input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array with subarray *** +int(0) +array(0) { +} + +int(1) +array(1) { + [0]=> + int(1) +} + +int(2) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +int(3) +array(2) { + [0]=> + string(5) "Mango" + [1]=> + string(6) "Orange" +} + +int(4) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation5.phpt b/ext/standard/tests/array/array_walk_variation5.phpt new file mode 100644 index 0000000..b5d262a --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation5.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument containing reference variables +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_walk() with an array having reference variables +*/ + +echo "*** Testing array_walk() : array with references ***\n"; + +$value1 = 10; +$value2 = -20; +$value3 = &$value1; +$value4 = 50; + +// 'input' array containing references to above variables +$input = array(&$value1, &$value2, -35, &$value3, 0, &$value4); + +// callback function +/* Prototype : callback(int $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : function checks for the value whether positive or negative and displays according to that + */ +function callback($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} + +var_dump( array_walk($input, "callback")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array with references *** +int(0) +int(10) + +int(1) +int(-20) + +int(2) +int(-35) + +int(3) +int(10) + +int(4) +int(0) + +int(5) +int(50) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation6.phpt b/ext/standard/tests/array/array_walk_variation6.phpt new file mode 100644 index 0000000..c1f2323 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation6.phpt @@ -0,0 +1,143 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing 'input' argument as an associative array + * with Numeric & string keys +*/ + +echo "*** Testing array_walk() : 'input' as an associative array ***\n"; + +// callback functions +/* Prototype : for_numeric( int $value, int $key, int $user_data) + * Parameters : $value - value from key/value pair of the array + * $key - key from key/value pair of the array + * $user_data - data to be added to 'value' + * Description : Function adds values with keys & user_data + */ +function for_numeric($value, $key, $user_data) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + var_dump($user_data); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_string( string $value, string $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function appends key to the value + */ +function for_string($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : for_mixed( mixed $value, mixed $key) + * Parameters : $value - values in given input array + * $key - keys in given input array + * Description : Function displays each element of an array with keys + */ +function for_mixed($value, $key) +{ + // dump the input values to see if they are + // passed with correct type + var_dump($key); + var_dump($value); + echo "\n"; // new line to separate the output between each element +} + +// Numeric keys +$input = array( 1 => 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange"); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk($input, "for_string")); + +// binary keys +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk($input, "for_mixed")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(30) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation7.phpt b/ext/standard/tests/array/array_walk_variation7.phpt new file mode 100644 index 0000000..da85958 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation7.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_walk() function : usage variations - anonymous callback function +--FILE-- +<?php +/* Prototype : proto bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* +* Passing anonymous(run-time) callback function with following variations: +* with one parameter +* two parameters +* three parameters +* extra parameters +* without parameters +*/ + +echo "*** Testing array_walk() : anonymous function as callback ***\n"; + +$input = array(2, 5, 10, 0); + +echo "-- Anonymous function with one argument --\n"; +var_dump( array_walk($input, create_function('$value', 'var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with two arguments --\n"; +var_dump( array_walk($input, create_function('$value, $key', 'var_dump($key); var_dump($value); echo "\n";'))); + +echo "-- Anonymous function with three arguments --\n"; +var_dump( array_walk($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 10)); + +echo "-- Anonymous function with one more argument --\n"; +var_dump( array_walk($input, create_function('$value, $key, $user_data', 'var_dump($key); var_dump($value); var_dump($user_data); echo "\n";'), 20, 30)); + +echo "-- Anonymous function with null argument --\n"; +var_dump( array_walk( $input, create_function(null, 'echo "1\n";'))); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(2) +int(10) + +int(3) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(2) +int(10) +int(10) + +int(3) +int(0) +int(10) + +bool(true) +-- Anonymous function with one more argument -- + +Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d +NULL +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation8.phpt b/ext/standard/tests/array/array_walk_variation8.phpt new file mode 100644 index 0000000..56a60e6 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_walk() function : usage variations - buit-in function as callback +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different buit-in functionns as callback function + * pow function + * min function + * echo language construct +*/ + +echo "*** Testing array_walk() : built-in function as callback ***\n"; + +$input = array(2 => 1, 65, 98, 100, 6 => -4); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk($input, "min")); + +echo "-- With 'echo' language construct --\n"; +var_dump( array_walk($input, "echo")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- + +Warning: array_walk() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_variation9.phpt b/ext/standard/tests/array/array_walk_variation9.phpt new file mode 100644 index 0000000..3707784 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_walk() function : usage variations - different callback functions +--FILE-- +<?php +/* Prototype : bool array_walk(array $input, string $funcname [, mixed $userdata]) + * Description: Apply a user function to every member of an array + * Source code: ext/standard/array.c +*/ + +/* + * Passing different types of callback functions to array_walk() + * without parameters + * with less and more parameters +*/ + +echo "*** Testing array_walk() : callback function variation ***\n"; + +$input = array('Apple', 'Banana', 'Mango', 'Orange'); + +echo "-- callback function with both parameters --\n"; +function callback_two_parameter($value, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($key); // key + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk($input, 'callback_two_parameter')); + +echo "-- callback function with only one parameter --\n"; +function callback_one_parameter($value) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($value); // value + echo "\n"; // new line to separate the output between each element +} +var_dump( array_walk($input, 'callback_one_parameter')); + +echo "-- callback function without parameters --\n"; +function callback_no_parameter() +{ + echo "callback3() called\n"; +} +var_dump( array_walk($input, 'callback_no_parameter')); + +echo "-- passing one more parameter to function with two parameters --\n"; +var_dump( array_walk($input, 'callback_two_parameter', 10)); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +Done diff --git a/ext/standard/tests/array/arsort_basic.phpt b/ext/standard/tests/array/arsort_basic.phpt new file mode 100644 index 0000000..24799ab --- /dev/null +++ b/ext/standard/tests/array/arsort_basic.phpt @@ -0,0 +1,245 @@ +--TEST-- +Test arsort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing integer/string arrays to check the basic functionality + * with following flag values. + * flag value as default + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing arsort() : basic functionality ***\n"; + +// an array containing unsorted string values with indices +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 ); + +echo "\n-- Testing arsort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( arsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : basic functionality *** + +-- Testing arsort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [3]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [4]=> + int(22) +} + +-- Testing arsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [3]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [4]=> + int(22) +} + +-- Testing arsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing arsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing arsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing arsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [3]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [4]=> + int(22) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_error.phpt b/ext/standard/tests/array/arsort_error.phpt new file mode 100644 index 0000000..676d826 --- /dev/null +++ b/ext/standard/tests/array/arsort_error.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test arsort() function : error conditions +--FILE-- +<?php +/* Prototype : bool arsort(array &array_arg [, int sort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing arsort() function with all possible error conditions +*/ + +echo "*** Testing arsort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing arsort() function with Zero arguments --\n"; +var_dump( arsort() ); + +//Test arsort with more than the expected number of arguments +echo "\n-- Testing arsort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and setting all possible flag values +foreach($flags as $key => $flag){ + echo "\nSort flag = $key\n"; + var_dump( arsort($array_arg,$flag, $extra_arg) ); + + // dump the input array to ensure that it wasn't changed + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : error conditions *** + +-- Testing arsort() function with Zero arguments -- + +Warning: arsort() expects at least 1 parameter, 0 given in %sarsort_error.php on line %d +bool(false) + +-- Testing arsort() function with more than expected no. of arguments -- + +Sort flag = SORT_REGULAR + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_STRING + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_NUMERIC + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_object1.phpt b/ext/standard/tests/array/arsort_object1.phpt new file mode 100644 index 0000000..8fd80f9 --- /dev/null +++ b/ext/standard/tests/array/arsort_object1.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test arsort() function : object functionality - sort objects +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing integer/string object arrays with following flag values + * 1. Defualt flag value + * 2. SORT_REGULAR - compare items normally +*/ + +echo "*** Testing arsort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_arsort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class for_string_arsort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array ( + 1 => new for_integer_arsort(11), 2 => new for_integer_asort(66), + 3 => new for_integer_arsort(23), 4 => new for_integer_asort(-5), + 5 => new for_integer_arsort(0.001), 6 => new for_integer_asort(0) +); + +// array of string objects +$unsorted_str_obj = array ( + "a" => new for_string_arsort("axx"), "b" => new for_string_asort("t"), + "c" => new for_string_arsort("w"), "d" => new for_string_asort("py"), + "e" => new for_string_arsort("apple"), "f" => new for_string_asort("Orange"), + "g" => new for_string_arsort("Lemon"), "h" => new for_string_asort("aPPle") +); + + +echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing arsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +// testing arsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing arsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing arsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : object functionality *** + +Fatal error: Class 'for_integer_asort' not found in %sarsort_object1.php on line %d
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_object2.phpt b/ext/standard/tests/array/arsort_object2.phpt new file mode 100644 index 0000000..24da657 --- /dev/null +++ b/ext/standard/tests/array/arsort_object2.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test arsort() function : object functionality - sorting objects with diff. accessibility of member vars +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing integer/string object arrays with following flag values + * 1. Defualt flag value + 2. SORT_REGULAR - compare items normally +*/ + +echo "*** Testing arsort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_arsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + +} + +// class declaration for string objects +class for_string_arsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->value; + } +} + +// array of integer objects +$unsorted_int_obj = array ( + 1 => new for_integer_arsort(11, 33,2), 2 => new for_integer_asort(44, 66,3), + 3 => new for_integer_arsort(23, 32,6), 4 => new for_integer_asort(-88, -5,-4), +); + +// array of string objects +$unsorted_str_obj = array ( + "a" => new for_string_arsort("axx","AXX","d"), "b" => new for_string_asort("T", "t","q"), + "c" => new for_string_arsort("w", "W","c"), "d" => new for_string_asort("PY", "py","s"), +); + + +echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is default --\n"; + +// testing arsort() function by supplying integer object array, flag value is default +$temp_array = $unsorted_int_obj; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +// testing arsort() function by supplying string object array, flag value is default +$temp_array = $unsorted_str_obj; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing arsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing arsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : object functionality *** + +Fatal error: Class 'for_integer_asort' not found in %sarsort_object2.php on line %d
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation1.phpt b/ext/standard/tests/array/arsort_variation1.phpt new file mode 100644 index 0000000..1545abe --- /dev/null +++ b/ext/standard/tests/array/arsort_variation1.phpt @@ -0,0 +1,399 @@ +--TEST-- +Test arsort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool arsort(array &array_arg [, int sort_flags]) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different unexpected values for array argument with following flag values. + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +//array of values with indices to iterate over +$unexpected_values = array ( + + // int data + 0 => 0, + 1 => 1, + 2 => 12345, + 3 => -2345, + + // float data + 4 => 10.5, + 5 => -10.5, + 6 => 10.5e3, + 7 => 10.6E-2, + 8 => .5, + + // null data + 9 => NULL, + 10 => null, + + // boolean data + 11 => true, + 12 => false, + 13 => TRUE, + 14 => FALSE, + + // empty data + 15 => "", + 16 => '', + + // string data + 17 => "string", + 18 => 'string', + + // object data + 19 => new stdclass(), + + // undefined data + 20 => @undefined_var, + + // unset data + 21 => @unset_var, + + // resource variable + 22 => $fp + +); + +// loop though each element of the array and check the working of arsort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing arsort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( arsort($value) ); // expecting : bool(false) + var_dump( arsort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( arsort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( arsort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 2 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 3 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 4 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 5 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 6 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 7 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 8 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 9 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 10 -- + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 11 -- + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 12 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 13 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 14 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 15 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 16 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 17 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 18 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 19 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 20 -- + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 21 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 22 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 23 -- + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation10.phpt b/ext/standard/tests/array/arsort_variation10.phpt new file mode 100644 index 0000000..ec483df --- /dev/null +++ b/ext/standard/tests/array/arsort_variation10.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test arsort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different octal array for $array argument with following flag values + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// an array contains unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01235, 0321 => 0321, 0345 => 0345, 066 => 066, 0772 => 0772, + 077 => 077, -066 => -066, -0345 => -0345, 0 => 0 +); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation11.phpt b/ext/standard/tests/array/arsort_variation11.phpt Binary files differnew file mode 100644 index 0000000..e8bfd77 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation11.phpt diff --git a/ext/standard/tests/array/arsort_variation2.phpt b/ext/standard/tests/array/arsort_variation2.phpt new file mode 100644 index 0000000..b856530 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation2.phpt @@ -0,0 +1,308 @@ +--TEST-- +Test arsort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : proto bool arsort(array &array_arg [, int sort_flags]) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// temperory array for checking unexpected behavior +$unsorted_values = array(1 => 10, 2 => 2, 3 => 45); + +//array of values to iterate over +$unexpected_values = array( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of arsort() +// when $flag arugment is supplied with different values from $unexpected_values +echo "\n-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( arsort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 2 -- +bool(true) +array(3) { + [3]=> + int(45) + [2]=> + int(2) + [1]=> + int(10) +} +-- Iteration 3 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 4 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 5 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 6 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 7 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 8 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 9 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 10 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 11 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 12 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 13 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 14 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 15 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 16 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 17 -- + +Warning: arsort() expects parameter 2 to be long, object given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 18 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 19 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 20 -- + +Warning: arsort() expects parameter 2 to be long, resource given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/arsort_variation3.phpt b/ext/standard/tests/array/arsort_variation3.phpt new file mode 100644 index 0000000..609155c --- /dev/null +++ b/ext/standard/tests/array/arsort_variation3.phpt @@ -0,0 +1,326 @@ +--TEST-- +Test arsort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing different integer/float value arrays for $array argument with following values + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// group of various arrays with indices +$various_arrays = array( + // negative/posative integer array + array(1 => 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41), + + // float value array + array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1), + + // mixed value array + array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33), + + // array values contains minimum and maximum ranges + array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing arsort() by supplying various integer/float arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [7]=> + int(0) + [2]=> + int(-11) + [4]=> + int(-21) + [6]=> + int(-31) + [10]=> + int(-41) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [3]=> + float(1050) + [1]=> + float(10.5) + [5]=> + float(0.5) + [4]=> + float(0.106) + [6]=> + float(0.0001) + [7]=> + float(-0.1) + [2]=> + float(-10.5) +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [7]=> + int(2) + [9]=> + float(0.106) + [6]=> + float(0.09) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [5]=> + int(0) + [3]=> + float(-0.01) + [10]=> + float(-0.106) + [8]=> + float(-0.9) + [4]=> + int(-1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [6]=> + int(0) + [5]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [6]=> + int(0) + [5]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [2]=> + %s(2147483648) + [1]=> + int(2147483647) + [6]=> + int(0) + [5]=> + int(0) + [3]=> + int(-2147483647) + [4]=> + %s(-2147483648) + [7]=> + %s(-2147483649) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation4.phpt b/ext/standard/tests/array/arsort_variation4.phpt new file mode 100644 index 0000000..a76a180 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test arsort() function : usage variations - sort reference variables +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing reference variable array with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() :usage variations ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +// an array containing integer references +$unsorted_numerics = array( 1 => &$value1 , 2 => &$value2, 3 => &$value3); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() :usage variations *** + +-- Testing arsort() by supplying reference variable array, 'flag' value is defualt -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation5.phpt b/ext/standard/tests/array/arsort_variation5.phpt new file mode 100644 index 0000000..187d43c --- /dev/null +++ b/ext/standard/tests/array/arsort_variation5.phpt @@ -0,0 +1,247 @@ +--TEST-- +Test arsort() function : usage variations - sort strings +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different string arrays for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +$various_arrays = array ( + // group of escape sequences + array ("null"=> null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array contains combination of capital/small letters + array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", + 'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing arsort() by supplying various string arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +Done diff --git a/ext/standard/tests/array/arsort_variation6.phpt b/ext/standard/tests/array/arsort_variation6.phpt new file mode 100644 index 0000000..687b20a --- /dev/null +++ b/ext/standard/tests/array/arsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test arsort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing different hexa-decimal array for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// an array contains unsorted hexadecimal values +// There are multiple keys which are duplicate and the later should be picked +$unsorted_hex_array = array ( 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa + ); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation7.phpt b/ext/standard/tests/array/arsort_variation7.phpt new file mode 100644 index 0000000..97195b7 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation7.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test arsort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: This function arsorts an array. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing bool value array for $array argument with following flag values. + * flag value as defualt + * SORT_REGULAR - compare items normally +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// bool value array +$bool_values = array (1 => true, 2 => false, 3 => TRUE, 4 => FALSE); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying bool value array, 'flag' value is defualt -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation8.phpt b/ext/standard/tests/array/arsort_variation8.phpt new file mode 100644 index 0000000..c247316 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation8.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test arsort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing arsort() by providing arrays contains sub arrays for $array argument with flowing flag values + * flag value as default + * SORT_REGULAR - compare items normally + * Note: arrays are sorted based on total count of elements inside it, when all the elements are arrays +*/ + +echo "*** Testing arsort() : usage variations ***\n"; + +// array of arrays +$various_arrays = array ( + // null array + "array[0]" => array(), + + // array contains null sub array + "array[1]" => array( "sub_array[1][0]" => array() ), + + // array of arrays along with some values + "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ), + + // array contains sub arrays + "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11), + "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() ) +); + + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing arsort() function by supplying different arrays, flag value is default + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // testing arsort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(0) { +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation9.phpt b/ext/standard/tests/array/arsort_variation9.phpt new file mode 100644 index 0000000..a034db5 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation9.phpt @@ -0,0 +1,258 @@ +--TEST-- +Test arsort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool arsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from highest to lowest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing arsort() by providing arrays with key values for $array argument with following flag values. + * 1.flag value as default + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing arsort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), +); + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays with key values --\n"; + +// loop through to test arsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With default sort_flag - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With default sort_flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With default sort_flag - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/asort_basic.phpt b/ext/standard/tests/array/asort_basic.phpt new file mode 100644 index 0000000..b80d31d --- /dev/null +++ b/ext/standard/tests/array/asort_basic.phpt @@ -0,0 +1,245 @@ +--TEST-- +Test asort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing asort() by providing integer/string arrays to check the basic functionality + * with following flag values. + * flag value as default + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing asort() : basic functionality ***\n"; + +// an array containing unsorted string values with indices +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 1 => 100, 2 => 33, 3 => 555, 4 => 22 ); + +echo "\n-- Testing asort() by supplying string array, 'flag' value is default --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying numeric array, 'flag' value is default --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( asort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : basic functionality *** + +-- Testing asort() by supplying string array, 'flag' value is default -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying numeric array, 'flag' value is default -- +bool(true) +array(4) { + [4]=> + int(22) + [2]=> + int(33) + [1]=> + int(100) + [3]=> + int(555) +} + +-- Testing asort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [4]=> + int(22) + [2]=> + int(33) + [1]=> + int(100) + [3]=> + int(555) +} + +-- Testing asort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" +} + +-- Testing asort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["o2"]=> + string(7) "orange2" + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" +} + +-- Testing asort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [4]=> + int(22) + [2]=> + int(33) + [1]=> + int(100) + [3]=> + int(555) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/asort_error.phpt b/ext/standard/tests/array/asort_error.phpt new file mode 100644 index 0000000..ef23295 --- /dev/null +++ b/ext/standard/tests/array/asort_error.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test asort() function : error conditions +--FILE-- +<?php +/* Prototype : bool asort(array &array_arg [, int sort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing asort() function with all possible error conditions +*/ + +echo "*** Testing asort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing asort() function with Zero arguments --\n"; +var_dump( asort() ); + +//Test asort with more than the expected number of arguments +echo "\n-- Testing asort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and setting all possible flag values +foreach($flags as $key => $flag){ + echo "\nSort flag = $key\n"; + var_dump( asort($array_arg,$flag, $extra_arg) ); + + // dump the input array to ensure that it wasn't changed + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing asort() : error conditions *** + +-- Testing asort() function with Zero arguments -- + +Warning: asort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing asort() function with more than expected no. of arguments -- + +Sort flag = SORT_REGULAR + +Warning: asort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_STRING + +Warning: asort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_NUMERIC + +Warning: asort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/asort_object1.phpt b/ext/standard/tests/array/asort_object1.phpt new file mode 100644 index 0000000..ad54675 --- /dev/null +++ b/ext/standard/tests/array/asort_object1.phpt @@ -0,0 +1,245 @@ +--TEST-- +Test asort() function : object functionality - sort objects +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing integer/string object arrays with following flag values + * 1. Defualt flag value + * 2. SORT_REGULAR - compare items normally +*/ + +echo "*** Testing asort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_asort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class for_string_asort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array ( + 1 => new for_integer_asort(11), 2 => new for_integer_asort(66), + 3 => new for_integer_asort(23), 4 => new for_integer_asort(-5), + 5 => new for_integer_asort(0.001), 6 => new for_integer_asort(0) +); + +// array of string objects +$unsorted_str_obj = array ( + "a" => new for_string_asort("axx"), "b" => new for_string_asort("t"), + "c" => new for_string_asort("w"), "d" => new for_string_asort("py"), + "e" => new for_string_asort("apple"), "f" => new for_string_asort("Orange"), + "g" => new for_string_asort("Lemon"), "h" => new for_string_asort("aPPle") +); + + +echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing asort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(asort($temp_array) ); +var_dump($temp_array); + +// testing asort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(asort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing asort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing asort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : object functionality *** + +-- Testing asort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [4]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(-5) + } + [6]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [1]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["g"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["f"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["h"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["e"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["a"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["d"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["b"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["c"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [4]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(-5) + } + [6]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [1]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_asort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["g"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["f"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["h"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["e"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["a"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["d"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["b"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["c"]=> + object(for_string_asort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/ext/standard/tests/array/asort_object2.phpt b/ext/standard/tests/array/asort_object2.phpt new file mode 100644 index 0000000..be76120 --- /dev/null +++ b/ext/standard/tests/array/asort_object2.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test asort() function : object functionality - sorting objects with diff. accessibility of member vars +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing integer/string object arrays with following flag values + * 1. Defualt flag value + 2. SORT_REGULAR - compare items normally +*/ + +echo "*** Testing asort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_asort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + +} + +// class declaration for string objects +class for_string_asort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->value; + } +} + +// array of integer objects +$unsorted_int_obj = array ( + 1 => new for_integer_asort(11, 33,2), 2 => new for_integer_asort(44, 66,3), + 3 => new for_integer_asort(23, 32,6), 4 => new for_integer_asort(-88, -5,-4), +); + +// array of string objects +$unsorted_str_obj = array ( + "a" => new for_string_asort("axx","AXX","d"), "b" => new for_string_asort("T", "t","q"), + "c" => new for_string_asort("w", "W","c"), "d" => new for_string_asort("PY", "py","s"), +); + + +echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is default --\n"; + +// testing asort() function by supplying integer object array, flag value is default +$temp_array = $unsorted_int_obj; +var_dump(asort($temp_array) ); +var_dump($temp_array); + +// testing asort() function by supplying string object array, flag value is default +$temp_array = $unsorted_str_obj; +var_dump(asort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing asort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing asort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : object functionality *** + +-- Testing asort() by supplying various object arrays, 'flag' value is default -- +bool(true) +array(4) { + [4]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_asort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(-4) + } + [1]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_asort":private]=> + int(33) + ["protected_class_value":protected]=> + int(2) + } + [3]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(23) + ["private_class_value":"for_integer_asort":private]=> + int(32) + ["protected_class_value":protected]=> + int(6) + } + [2]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(44) + ["private_class_value":"for_integer_asort":private]=> + int(66) + ["protected_class_value":protected]=> + int(3) + } +} +bool(true) +array(4) { + ["d"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(2) "PY" + ["private_class_value":"for_string_asort":private]=> + string(2) "py" + ["protected_class_value":protected]=> + string(1) "s" + } + ["b"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "T" + ["private_class_value":"for_string_asort":private]=> + string(1) "t" + ["protected_class_value":protected]=> + string(1) "q" + } + ["a"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_asort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(1) "d" + } + ["c"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_asort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} + +-- Testing asort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [4]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_asort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(-4) + } + [1]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_asort":private]=> + int(33) + ["protected_class_value":protected]=> + int(2) + } + [3]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(23) + ["private_class_value":"for_integer_asort":private]=> + int(32) + ["protected_class_value":protected]=> + int(6) + } + [2]=> + object(for_integer_asort)#%d (3) { + ["public_class_value"]=> + int(44) + ["private_class_value":"for_integer_asort":private]=> + int(66) + ["protected_class_value":protected]=> + int(3) + } +} +bool(true) +array(4) { + ["d"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(2) "PY" + ["private_class_value":"for_string_asort":private]=> + string(2) "py" + ["protected_class_value":protected]=> + string(1) "s" + } + ["b"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "T" + ["private_class_value":"for_string_asort":private]=> + string(1) "t" + ["protected_class_value":protected]=> + string(1) "q" + } + ["a"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_asort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(1) "d" + } + ["c"]=> + object(for_string_asort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_asort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} +Done diff --git a/ext/standard/tests/array/asort_variation1.phpt b/ext/standard/tests/array/asort_variation1.phpt new file mode 100644 index 0000000..5420f05 --- /dev/null +++ b/ext/standard/tests/array/asort_variation1.phpt @@ -0,0 +1,399 @@ +--TEST-- +Test asort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool asort(array &array_arg [, int sort_flags]) + * Description: Sort an array and maintain index association + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing different unexpected values for array argument with following flag values. + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +//array of values with indices to iterate over +$unexpected_values = array ( + + // int data + 0 => 0, + 1 => 1, + 2 => 12345, + 3 => -2345, + + // float data + 4 => 10.5, + 5 => -10.5, + 6 => 10.5e3, + 7 => 10.6E-2, + 8 => .5, + + // null data + 9 => NULL, + 10 => null, + + // boolean data + 11 => true, + 12 => false, + 13 => TRUE, + 14 => FALSE, + + // empty data + 15 => "", + 16 => '', + + // string data + 17 => "string", + 18 => 'string', + + // object data + 19 => new stdclass(), + + // undefined data + 20 => @undefined_var, + + // unset data + 21 => @unset_var, + + // resource variable + 22 => $fp + +); + +// loop though each element of the array and check the working of asort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing asort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( asort($value) ); // expecting : bool(false) + var_dump( asort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( asort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( asort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: asort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: asort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: asort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/asort_variation10.phpt b/ext/standard/tests/array/asort_variation10.phpt new file mode 100644 index 0000000..f51945b --- /dev/null +++ b/ext/standard/tests/array/asort_variation10.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test asort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing different octal array for $array argument with following flag values + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +// an array contains unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01235, 0321 => 0321, 0345 => 0345, 066 => 066, 0772 => 0772, + 077 => 077, -066 => -066, -0345 => -0345, 0 => 0 +); + +echo "\n-- Testing asort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [-229]=> + int(-229) + [-54]=> + int(-54) + [0]=> + int(0) + [54]=> + int(54) + [63]=> + int(63) + [209]=> + int(209) + [229]=> + int(229) + [506]=> + int(506) + [669]=> + int(669) +} + +-- Testing asort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-229]=> + int(-229) + [-54]=> + int(-54) + [0]=> + int(0) + [54]=> + int(54) + [63]=> + int(63) + [209]=> + int(209) + [229]=> + int(229) + [506]=> + int(506) + [669]=> + int(669) +} + +-- Testing asort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-229]=> + int(-229) + [-54]=> + int(-54) + [0]=> + int(0) + [54]=> + int(54) + [63]=> + int(63) + [209]=> + int(209) + [229]=> + int(229) + [506]=> + int(506) + [669]=> + int(669) +} +Done diff --git a/ext/standard/tests/array/asort_variation11.phpt b/ext/standard/tests/array/asort_variation11.phpt Binary files differnew file mode 100644 index 0000000..fca91a9 --- /dev/null +++ b/ext/standard/tests/array/asort_variation11.phpt diff --git a/ext/standard/tests/array/asort_variation2.phpt b/ext/standard/tests/array/asort_variation2.phpt new file mode 100644 index 0000000..6cce644 --- /dev/null +++ b/ext/standard/tests/array/asort_variation2.phpt @@ -0,0 +1,308 @@ +--TEST-- +Test asort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : proto bool asort(array &array_arg [, int sort_flags]) + * Description: Sort an array and maintain index association + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing asort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// temperory array for checking unexpected behavior +$unsorted_values = array(1 => 10, 2 => 2, 3 => 45); + +//array of values to iterate over +$unexpected_values = array( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of asort() +// when $flag arugment is supplied with different values from $unexpected_values +echo "\n-- Testing asort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( asort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 2 -- +bool(true) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 3 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 4 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 5 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 6 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 7 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 8 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 9 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 10 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 11 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 12 -- +bool(true) +array(3) { + [2]=> + int(2) + [1]=> + int(10) + [3]=> + int(45) +} +-- Iteration 13 -- + +Warning: asort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 14 -- + +Warning: asort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 15 -- + +Warning: asort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 16 -- + +Warning: asort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 17 -- + +Warning: asort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 18 -- + +Warning: asort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 19 -- + +Warning: asort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 20 -- + +Warning: asort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/asort_variation3.phpt b/ext/standard/tests/array/asort_variation3.phpt new file mode 100644 index 0000000..25f40d3 --- /dev/null +++ b/ext/standard/tests/array/asort_variation3.phpt @@ -0,0 +1,326 @@ +--TEST-- +Test asort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing asort() by providing different integer/float value arrays for $array argument with following values + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +// group of various arrays with indices +$various_arrays = array( + // negative/posative integer array + array(1 => 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41), + + // float value array + array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1), + + // mixed value array + array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33), + + // array values contains minimum and maximum ranges + array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing asort() by supplying various integer/float arrays --\n"; + +// loop through to test asort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(asort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(9) { + [10]=> + int(-41) + [6]=> + int(-31) + [4]=> + int(-21) + [2]=> + int(-11) + [7]=> + int(0) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [8]=> + int(41) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(9) { + [10]=> + int(-41) + [6]=> + int(-31) + [4]=> + int(-21) + [2]=> + int(-11) + [7]=> + int(0) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [8]=> + int(41) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(9) { + [10]=> + int(-41) + [6]=> + int(-31) + [4]=> + int(-21) + [2]=> + int(-11) + [7]=> + int(0) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(7) { + [2]=> + float(-10.5) + [7]=> + float(-0.1) + [6]=> + float(0.0001) + [4]=> + float(0.106) + [5]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [2]=> + float(-10.5) + [7]=> + float(-0.1) + [6]=> + float(0.0001) + [4]=> + float(0.106) + [5]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [2]=> + float(-10.5) + [7]=> + float(-0.1) + [6]=> + float(0.0001) + [4]=> + float(0.106) + [5]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(11) { + [4]=> + int(-1) + [8]=> + float(-0.9) + [10]=> + float(-0.106) + [3]=> + float(-0.01) + [5]=> + int(0) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [6]=> + float(0.09) + [9]=> + float(0.106) + [7]=> + int(2) + [11]=> + int(33) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(11) { + [4]=> + int(-1) + [8]=> + float(-0.9) + [10]=> + float(-0.106) + [3]=> + float(-0.01) + [5]=> + int(0) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [6]=> + float(0.09) + [9]=> + float(0.106) + [7]=> + int(2) + [11]=> + int(33) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(11) { + [4]=> + int(-1) + [8]=> + float(-0.9) + [10]=> + float(-0.106) + [3]=> + float(-0.01) + [5]=> + int(0) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [6]=> + float(0.09) + [9]=> + float(0.106) + [7]=> + int(2) + [11]=> + int(33) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(7) { + [7]=> + %s(-2147483649) + [4]=> + %s(-2147483648) + [3]=> + int(-2147483647) + [6]=> + int(0) + [5]=> + int(0) + [1]=> + int(2147483647) + [2]=> + %s(2147483648) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(7) { + [7]=> + %s(-2147483649) + [4]=> + %s(-2147483648) + [3]=> + int(-2147483647) + [6]=> + int(0) + [5]=> + int(0) + [1]=> + int(2147483647) + [2]=> + %s(2147483648) +} +- Sort_flag = SORT_NUMERIC - +bool(true) +array(7) { + [7]=> + %s(-2147483649) + [4]=> + %s(-2147483648) + [3]=> + int(-2147483647) + [6]=> + int(0) + [5]=> + int(0) + [1]=> + int(2147483647) + [2]=> + %s(2147483648) +} +Done diff --git a/ext/standard/tests/array/asort_variation4.phpt b/ext/standard/tests/array/asort_variation4.phpt new file mode 100644 index 0000000..9fd7600 --- /dev/null +++ b/ext/standard/tests/array/asort_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test asort() function : usage variations - sort reference variables +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing asort() by providing reference variable array with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing asort() :usage variations ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +// an array containing integer references +$unsorted_numerics = array( 1 => &$value1 , 2 => &$value2, 3 => &$value3); + +echo "\n-- Testing asort() by supplying reference variable array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( asort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() :usage variations *** + +-- Testing asort() by supplying reference variable array, 'flag' value is defualt -- +bool(true) +array(3) { + [2]=> + &int(33) + [1]=> + &int(100) + [3]=> + &int(555) +} + +-- Testing asort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [2]=> + &int(33) + [1]=> + &int(100) + [3]=> + &int(555) +} + +-- Testing asort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [2]=> + &int(33) + [1]=> + &int(100) + [3]=> + &int(555) +} +Done diff --git a/ext/standard/tests/array/asort_variation5.phpt b/ext/standard/tests/array/asort_variation5.phpt new file mode 100644 index 0000000..3d6a12e --- /dev/null +++ b/ext/standard/tests/array/asort_variation5.phpt @@ -0,0 +1,247 @@ +--TEST-- +Test asort() function : usage variations - sort strings +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing different string arrays for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +$various_arrays = array ( + // group of escape sequences + array ("null"=> null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array contains combination of capital/small letters + array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", + 'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing asort() by supplying various string arrays --\n"; + +// loop through to test asort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(asort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(12) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["null"]=> + NULL + ["NULL"]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(12) { + ["B"]=> + string(6) "BANANA" + ["O"]=> + string(6) "Orange" + ["T"]=> + string(4) "TTTT" + ["Te"]=> + string(4) "Test" + ["X"]=> + string(1) "X" + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemoN" + ["o"]=> + string(6) "oraNGe" + ["t"]=> + string(3) "ttt" + ["w"]=> + string(2) "ww" + ["x"]=> + string(1) "x" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["B"]=> + string(6) "BANANA" + ["O"]=> + string(6) "Orange" + ["T"]=> + string(4) "TTTT" + ["Te"]=> + string(4) "Test" + ["X"]=> + string(1) "X" + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemoN" + ["o"]=> + string(6) "oraNGe" + ["t"]=> + string(3) "ttt" + ["w"]=> + string(2) "ww" + ["x"]=> + string(1) "x" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["B"]=> + string(6) "BANANA" + ["O"]=> + string(6) "Orange" + ["T"]=> + string(4) "TTTT" + ["Te"]=> + string(4) "Test" + ["X"]=> + string(1) "X" + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemoN" + ["o"]=> + string(6) "oraNGe" + ["t"]=> + string(3) "ttt" + ["w"]=> + string(2) "ww" + ["x"]=> + string(1) "x" +} +Done diff --git a/ext/standard/tests/array/asort_variation6.phpt b/ext/standard/tests/array/asort_variation6.phpt new file mode 100644 index 0000000..117f30d --- /dev/null +++ b/ext/standard/tests/array/asort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test asort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $asort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing different hexa-decimal array for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +// an array contains unsorted hexadecimal values +// There are multiple keys which are duplicate and the later should be picked +$unsorted_hex_array = array ( 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa + ); + +echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(asort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(asort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(asort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing asort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} +Done diff --git a/ext/standard/tests/array/asort_variation7.phpt b/ext/standard/tests/array/asort_variation7.phpt new file mode 100644 index 0000000..6050b86 --- /dev/null +++ b/ext/standard/tests/array/asort_variation7.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test asort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: This function asorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing bool value array for $array argument with following flag values. + * flag value as defualt + * SORT_REGULAR - compare items normally +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +// bool value array +$bool_values = array (1 => true, 2 => false, 3 => TRUE, 4 => FALSE); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing asort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(asort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying bool value array, 'flag' value is defualt -- +bool(true) +array(4) { + [4]=> + bool(false) + [2]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing asort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [4]=> + bool(false) + [2]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing asort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [4]=> + bool(false) + [2]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing asort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [4]=> + bool(false) + [2]=> + bool(false) + [1]=> + bool(true) + [3]=> + bool(true) +} +Done diff --git a/ext/standard/tests/array/asort_variation8.phpt b/ext/standard/tests/array/asort_variation8.phpt new file mode 100644 index 0000000..561cc7d --- /dev/null +++ b/ext/standard/tests/array/asort_variation8.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test asort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing asort() by providing arrays contains sub arrays for $array argument with flowing flag values + * flag value as default + * SORT_REGULAR - compare items normally + * Note: arrays are sorted based on total count of elements inside it, when all the elements are arrays +*/ + +echo "*** Testing asort() : usage variations ***\n"; + +// array of arrays +$various_arrays = array ( + // null array + "array[0]" => array(), + + // array contains null sub array + "array[1]" => array( "sub_array[1][0]" => array() ), + + // array of arrays along with some values + "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ), + + // array contains sub arrays + "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11), + "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() ) +); + + +$count = 1; +echo "\n-- Testing asort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test asort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing asort() function by supplying different arrays, flag value is default + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); + var_dump($temp_array); + + // testing asort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(asort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(0) { +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(3) { + ["data[2,1]"]=> + int(11) + ["data[2,0]"]=> + int(44) + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["data[2,1]"]=> + int(11) + ["data[2,0]"]=> + int(44) + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(4) { + ["sub_array[3][3]"]=> + array(0) { + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["sub_array[3][3]"]=> + array(0) { + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/ext/standard/tests/array/asort_variation9.phpt b/ext/standard/tests/array/asort_variation9.phpt new file mode 100644 index 0000000..d79b6fc --- /dev/null +++ b/ext/standard/tests/array/asort_variation9.phpt @@ -0,0 +1,258 @@ +--TEST-- +Test asort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool asort ( array &$array [, int $sort_flags] ) + * Description: Sort an array and maintain index association. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing asort() by providing arrays with key values for $array argument with following flag values. + * 1.flag value as default + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing asort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), +); + +$count = 1; +echo "\n-- Testing asort() by supplying various arrays with key values --\n"; + +// loop through to test asort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(asort($temp_array) ); + var_dump($temp_array); + + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(asort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing asort() : usage variations *** + +-- Testing asort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(5) { + [9]=> + int(11) + [7]=> + int(22) + [8]=> + int(33) + [5]=> + int(55) + [6]=> + int(66) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(5) { + [9]=> + int(11) + [7]=> + int(22) + [8]=> + int(33) + [5]=> + int(55) + [6]=> + int(66) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" +} + +-- Iteration 5 -- +- With default sort_flag - +bool(true) +array(6) { + [4]=> + int(1) + [0]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [9]=> + int(19) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [4]=> + int(1) + [0]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [9]=> + int(19) +} + +-- Iteration 6 -- +- With default sort_flag - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} + +-- Iteration 7 -- +- With default sort_flag - +bool(true) +array(4) { + ["a"]=> + int(1) + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["a"]=> + int(1) + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/bug12776.phpt b/ext/standard/tests/array/bug12776.phpt new file mode 100644 index 0000000..54c6f6f --- /dev/null +++ b/ext/standard/tests/array/bug12776.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #12776 (array_walk crash) +--FILE-- +<?php + +function test($val,$key) +{ + global $globalArray; + $globalArray[]=$key; // this will end up crashing + $globalArray[]=(string)$key; // this will end up OK + print "val: $val; key: $key\n"; flush(); +} + +$arr=array('k'=>'v'); +array_walk($arr,'test'); + +print "First value: ".$globalArray[0]; + +print "\nDone\n"; + +?> +--EXPECT-- +val: v; key: k +First value: k +Done diff --git a/ext/standard/tests/array/bug14580.phpt b/ext/standard/tests/array/bug14580.phpt new file mode 100644 index 0000000..bf0121a --- /dev/null +++ b/ext/standard/tests/array/bug14580.phpt @@ -0,0 +1,11 @@ +--TEST--n +Bug #14580 (key() not binary safe) +--FILE-- +<?php + $arr = array (b"foo\0bar" => b"foo\0bar"); + $key = key($arr); + echo strlen($key), ': '; + echo urlencode($key), "\n"; +?> +--EXPECT-- +7: foo%00bar diff --git a/ext/standard/tests/array/bug20381.phpt b/ext/standard/tests/array/bug20381.phpt new file mode 100644 index 0000000..1adaa86 --- /dev/null +++ b/ext/standard/tests/array/bug20381.phpt @@ -0,0 +1,79 @@ +--TEST-- +Bug #20381 (array_merge_recursive mangles input arrays) +--FILE-- +<?php +$a = array( + 'a1' => 1, + 'a2' => array( 1, 2, 3 ), + 'a3' => array( + 'a' => array( 10, 20, 30 ), + 'b' => 'b' + ) + ); +$b = array( 'a1' => 2, + 'a2' => array( 3, 4, 5 ), + 'a3' => array( + 'c' => 'cc', + 'a' => array( 10, 40 ) + ) + ); + +var_dump($a); +array_merge_recursive( $a, $b ); +var_dump($a); +?> +--EXPECT-- +array(3) { + ["a1"]=> + int(1) + ["a2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["a3"]=> + array(2) { + ["a"]=> + array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + } + ["b"]=> + string(1) "b" + } +} +array(3) { + ["a1"]=> + int(1) + ["a2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["a3"]=> + array(2) { + ["a"]=> + array(3) { + [0]=> + int(10) + [1]=> + int(20) + [2]=> + int(30) + } + ["b"]=> + string(1) "b" + } +} diff --git a/ext/standard/tests/array/bug20865.phpt b/ext/standard/tests/array/bug20865.phpt new file mode 100644 index 0000000..f1edbab --- /dev/null +++ b/ext/standard/tests/array/bug20865.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #20865 (array_key_exists and NULL key) +--FILE-- +<?php + $ta = array(1, 2, 3); + $ta[NULL] = "Null Value"; + + var_dump(array_key_exists(NULL, $ta)); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/array/bug21182.phpt b/ext/standard/tests/array/bug21182.phpt new file mode 100644 index 0000000..af4602a --- /dev/null +++ b/ext/standard/tests/array/bug21182.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #21182 (range modifies arguments) +--FILE-- +<?php +$a = "20"; $b = "30"; +echo "a1: $a\n"; +$result = range($a, $b); +echo "a2: $a : type : " . gettype($a) . "\n"; +?> +--EXPECT-- +a1: 20 +a2: 20 : type : string diff --git a/ext/standard/tests/array/bug21918.phpt b/ext/standard/tests/array/bug21918.phpt new file mode 100644 index 0000000..1c9d746 --- /dev/null +++ b/ext/standard/tests/array/bug21918.phpt @@ -0,0 +1,55 @@ +--TEST-- +Bug #21918 (different handling of positive vs. negative array indexes) +--FILE-- +<?php + +echo "==Mixed==\n"; +$a = array(-1=>'a', '-2'=>'b', 3=>'c', '4'=>'d', 5=>'e', '6001'=>'f', '07'=>'g'); + +foreach($a as $k => $v) { + var_dump($k); + var_dump($v); +} + +echo "==Normal==\n"; +$b = array(); +$b[] = 'a'; + +foreach($b as $k => $v) { + var_dump($k); + var_dump($v); +} + +echo "==Negative==\n"; +$c = array('-2' => 'a'); + +foreach($c as $k => $v) { + var_dump($k); + var_dump($v); +} + +echo "==Done==\n"; +?> +--EXPECT-- +==Mixed== +int(-1) +string(1) "a" +int(-2) +string(1) "b" +int(3) +string(1) "c" +int(4) +string(1) "d" +int(5) +string(1) "e" +int(6001) +string(1) "f" +string(2) "07" +string(1) "g" +==Normal== +int(0) +string(1) "a" +==Negative== +int(-2) +string(1) "a" +==Done== diff --git a/ext/standard/tests/array/bug21998.phpt b/ext/standard/tests/array/bug21998.phpt new file mode 100644 index 0000000..aa52dc5 --- /dev/null +++ b/ext/standard/tests/array/bug21998.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #21998 (array_pop() does not reset the current array position) +--FILE-- +<?php + +$a = array("a", "b", "c"); + +var_dump(key($a)); +var_dump(array_pop($a)); +var_dump(key($a)); +var_dump(array_pop($a)); +var_dump(key($a)); +var_dump(array_pop($a)); +var_dump(key($a)); + +?> +--EXPECT-- +int(0) +string(1) "c" +int(0) +string(1) "b" +int(0) +string(1) "a" +NULL diff --git a/ext/standard/tests/array/bug22088.phpt b/ext/standard/tests/array/bug22088.phpt new file mode 100644 index 0000000..4352cff --- /dev/null +++ b/ext/standard/tests/array/bug22088.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #22088 (array_shift() leaves next index to be +1 too much) +--FILE-- +<?php + +$a = array('a', 'b', 'c'); +$last = array_shift ($a); +$a[] = 'a'; +var_dump($a); + +$a = array('a' => 1, 'b' => 2, 'c' => 3); +$last = array_shift ($a); +$a[] = 'a'; +var_dump($a); + +?> +--EXPECT-- +array(3) { + [0]=> + string(1) "b" + [1]=> + string(1) "c" + [2]=> + string(1) "a" +} +array(3) { + ["b"]=> + int(2) + ["c"]=> + int(3) + [0]=> + string(1) "a" +} diff --git a/ext/standard/tests/array/bug22463.phpt b/ext/standard/tests/array/bug22463.phpt new file mode 100644 index 0000000..dcede51 --- /dev/null +++ b/ext/standard/tests/array/bug22463.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #22463 (array_reduce() segfaults) +--FILE-- +<?php + +function a($ary) { + return (is_array($ary) ? array_reduce($ary, 'cb', 0) : 1); +} + +function cb($v, $elem) { + return $v + a($elem); +} + +$ary = array( + array( + array( + array( + array( + array(0, 1, 2, 3, 4) + ) + ) + ) + ) +); + +var_dump(a($ary)); +?> +--EXPECT-- +int(5) diff --git a/ext/standard/tests/array/bug23581.phpt b/ext/standard/tests/array/bug23581.phpt new file mode 100644 index 0000000..06e1e38 --- /dev/null +++ b/ext/standard/tests/array/bug23581.phpt @@ -0,0 +1,44 @@ +--TEST-- +Bug #23581 (array_map(NULL, array, array, ...) yields an undefined result) +--FILE-- +<?php +var_dump( + array_map( + NULL, + array(1,2,3), + array(4,5,6), + array(7,8,9) + ) +); +?> +--EXPECT-- +array(3) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(7) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + int(5) + [2]=> + int(8) + } + [2]=> + array(3) { + [0]=> + int(3) + [1]=> + int(6) + [2]=> + int(9) + } +} + diff --git a/ext/standard/tests/array/bug23788.phpt b/ext/standard/tests/array/bug23788.phpt new file mode 100644 index 0000000..022b3ce --- /dev/null +++ b/ext/standard/tests/array/bug23788.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #23788 (*_replace() clobbers referenced array elements) +--FILE-- +<?php +$numeric = 123; +$bool = true; +$foo = array(&$numeric, &$bool); +var_dump($foo); +str_replace("abc", "def", $foo); +var_dump($foo); +?> +--EXPECT-- +array(2) { + [0]=> + &int(123) + [1]=> + &bool(true) +} +array(2) { + [0]=> + &int(123) + [1]=> + &bool(true) +} diff --git a/ext/standard/tests/array/bug24198.phpt b/ext/standard/tests/array/bug24198.phpt new file mode 100644 index 0000000..b1cd523 --- /dev/null +++ b/ext/standard/tests/array/bug24198.phpt @@ -0,0 +1,25 @@ +--TEST--n +Bug #24198 (array_merge_recursive() invalid recursion detection) +--FILE-- +<?php +$c = array('a' => 'aa','b' => 'bb'); + +var_dump(array_merge_recursive($c, $c)); +?> +--EXPECT-- +array(2) { + ["a"]=> + array(2) { + [0]=> + string(2) "aa" + [1]=> + string(2) "aa" + } + ["b"]=> + array(2) { + [0]=> + string(2) "bb" + [1]=> + string(2) "bb" + } +} diff --git a/ext/standard/tests/array/bug24220.phpt b/ext/standard/tests/array/bug24220.phpt new file mode 100644 index 0000000..c8e2570 --- /dev/null +++ b/ext/standard/tests/array/bug24220.phpt @@ -0,0 +1,91 @@ +--TEST--n +Bug #24220 (range() numeric string handling) +--FILE-- +<?php + var_dump(range("2003", "2004")); + var_dump(range("a", "z")); + var_dump(range("1", "10")); +?> +--EXPECT-- +array(2) { + [0]=> + int(2003) + [1]=> + int(2004) +} +array(26) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + [5]=> + string(1) "f" + [6]=> + string(1) "g" + [7]=> + string(1) "h" + [8]=> + string(1) "i" + [9]=> + string(1) "j" + [10]=> + string(1) "k" + [11]=> + string(1) "l" + [12]=> + string(1) "m" + [13]=> + string(1) "n" + [14]=> + string(1) "o" + [15]=> + string(1) "p" + [16]=> + string(1) "q" + [17]=> + string(1) "r" + [18]=> + string(1) "s" + [19]=> + string(1) "t" + [20]=> + string(1) "u" + [21]=> + string(1) "v" + [22]=> + string(1) "w" + [23]=> + string(1) "x" + [24]=> + string(1) "y" + [25]=> + string(1) "z" +} +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} diff --git a/ext/standard/tests/array/bug24766.phpt b/ext/standard/tests/array/bug24766.phpt new file mode 100644 index 0000000..d6f82f3 --- /dev/null +++ b/ext/standard/tests/array/bug24766.phpt @@ -0,0 +1,45 @@ +--TEST-- +Bug #24766 (strange result array from unpack) +--FILE-- +<?php + +error_reporting(E_ALL); + +$a = unpack('C2', "\0224V"); +$b = array(1 => 18, 2 => 52); +debug_zval_dump($a, $b); +$k = array_keys($a); +$l = array_keys($b); +debug_zval_dump($k, $l); +$i=$k[0]; +var_dump($a[$i]); +$i=$l[0]; +var_dump($b[$i]); +?> +--EXPECT-- +array(2) refcount(2){ + [1]=> + long(18) refcount(1) + [2]=> + long(52) refcount(1) +} +array(2) refcount(2){ + [1]=> + long(18) refcount(1) + [2]=> + long(52) refcount(1) +} +array(2) refcount(2){ + [0]=> + long(1) refcount(1) + [1]=> + long(2) refcount(1) +} +array(2) refcount(2){ + [0]=> + long(1) refcount(1) + [1]=> + long(2) refcount(1) +} +int(18) +int(18) diff --git a/ext/standard/tests/array/bug24897.phpt b/ext/standard/tests/array/bug24897.phpt new file mode 100644 index 0000000..45bcde3 --- /dev/null +++ b/ext/standard/tests/array/bug24897.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #24897 (inconsistent behaviour or shuffle() & array_multisort()) +--FILE-- +<?php +$a = array(1 => 2); +shuffle($a); +var_dump($a); + +$a = array(1 => 2); +array_multisort($a); +var_dump($a); +?> +--EXPECT-- +array(1) { + [0]=> + int(2) +} +array(1) { + [0]=> + int(2) +} diff --git a/ext/standard/tests/array/bug24980.phpt b/ext/standard/tests/array/bug24980.phpt new file mode 100644 index 0000000..b9e04fd --- /dev/null +++ b/ext/standard/tests/array/bug24980.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #24980 (array_reduce() uses first element as default running total) +--FILE-- +<?php +/* test #1: numeric data */ +function add_up($running_total, $current_value) +{ + echo "running_total is ".(int)$running_total.", current_value is {$current_value}\n"; + $running_total += $current_value * $current_value; + return $running_total; +} + +$numbers = array (2,3,5,7); +$total = array_reduce($numbers, 'add_up'); +print "Total is $total\n"; + +/* test #2: string data */ +$a = array("a", "b", "c"); +function foo ($a, $b) +{ + return $a . $b; +} +var_dump(array_reduce($a, "foo")); + +/* test #3: basic test (used to leak memory) */ +function rsum($v, $w) +{ + $v += $w; + return $v; +} +function rmul($v, $w) +{ + $v *= $w; + return $v; +} +$a = array(1, 2, 3, 4, 5); +$x = array(); +$b = array_reduce($a, "rsum"); +$c = array_reduce($a, "rmul", 10); +$d = array_reduce($x, "rsum", 1); + +var_dump($b, $c, $d); +?> +--EXPECT-- +running_total is 0, current_value is 2 +running_total is 4, current_value is 3 +running_total is 13, current_value is 5 +running_total is 38, current_value is 7 +Total is 87 +string(3) "abc" +int(15) +int(1200) +int(1) diff --git a/ext/standard/tests/array/bug25359.phpt b/ext/standard/tests/array/bug25359.phpt new file mode 100644 index 0000000..0b9b89a --- /dev/null +++ b/ext/standard/tests/array/bug25359.phpt @@ -0,0 +1,32 @@ +--TEST-- +Bug #25359 (array_multisort() does not work in a function if array is global or reference) +--FILE-- +<?php + +function does_not_work() +{ + global $data; // Remove this line to make array_multisort() work + + $data = array('first', 'fifth', 'second', 'forth', 'third'); + $sort = array(1, 5, 2, 4, 3); + array_multisort($sort, $data); + + var_dump($data); +} + +does_not_work(); + +?> +--EXPECT-- +array(5) { + [0]=> + string(5) "first" + [1]=> + string(6) "second" + [2]=> + string(5) "third" + [3]=> + string(5) "forth" + [4]=> + string(5) "fifth" +} diff --git a/ext/standard/tests/array/bug25708.phpt b/ext/standard/tests/array/bug25708.phpt new file mode 100644 index 0000000..d3da3e3 --- /dev/null +++ b/ext/standard/tests/array/bug25708.phpt @@ -0,0 +1,223 @@ +--TEST-- +Bug #25708 (extract($GLOBALS, EXTR_REFS) mangles $GLOBALS) +--FILE-- +<?php +function foo($ref, $alt) { + unset($GLOBALS['a']); + unset($GLOBALS['b']); + $GLOBALS['a'] = 1; + $GLOBALS['b'] = 2; + + $org_a = $GLOBALS['a']; + $org_b = $GLOBALS['b']; + + if ($ref) { + global $a, $b; + } else { + /* zval temp_var(NULL); // refcount = 1 + * a = temp_var[x] // refcount = 2 + */ + $a = NULL; + $b = NULL; + } + + debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); + echo "--\n"; + if ($alt) { + $a = &$GLOBALS['a']; + $b = &$GLOBALS['b']; + } else { + extract($GLOBALS, EXTR_REFS); + } + debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); + echo "--\n"; + $a = &$GLOBALS['a']; + $b = &$GLOBALS['b']; + debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); + echo "--\n"; + $GLOBALS['b'] = 3; + debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); + echo "--\n"; + $a = 4; + debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b']); + echo "--\n"; + $c = $b; + debug_zval_dump($b, $GLOBALS['b'], $c); + echo "--\n"; + $b = 'x'; + debug_zval_dump($a, $b, $GLOBALS['a'], $GLOBALS['b'], $c); + echo "--\n"; + debug_zval_dump($org_a, $org_b); + echo "----"; + if ($ref) echo 'r'; + if ($alt) echo 'a'; + echo "\n"; +} + +$a = 'ok'; +$b = 'ok'; +$_a = $a; +$_b = $b; + +foo(false, true); +foo(true, true); +foo(false, false); +foo(true, false); + +debug_zval_dump($_a, $_b); +?> +--EXPECT-- +NULL refcount(2) +NULL refcount(2) +long(1) refcount(3) +long(2) refcount(3) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(3) refcount(1) +long(1) refcount(1) +long(3) refcount(1) +-- +long(4) refcount(1) +long(3) refcount(1) +long(4) refcount(1) +long(3) refcount(1) +-- +long(3) refcount(1) +long(3) refcount(1) +long(3) refcount(2) +-- +long(4) refcount(1) +string(1) "x" refcount(1) +long(4) refcount(1) +string(1) "x" refcount(1) +long(3) refcount(2) +-- +long(1) refcount(2) +long(2) refcount(2) +----a +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(3) refcount(1) +long(1) refcount(1) +long(3) refcount(1) +-- +long(4) refcount(1) +long(3) refcount(1) +long(4) refcount(1) +long(3) refcount(1) +-- +long(3) refcount(1) +long(3) refcount(1) +long(3) refcount(2) +-- +long(4) refcount(1) +string(1) "x" refcount(1) +long(4) refcount(1) +string(1) "x" refcount(1) +long(3) refcount(2) +-- +long(1) refcount(2) +long(2) refcount(2) +----ra +NULL refcount(2) +NULL refcount(2) +long(1) refcount(3) +long(2) refcount(3) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(3) refcount(1) +long(1) refcount(1) +long(3) refcount(1) +-- +long(4) refcount(1) +long(3) refcount(1) +long(4) refcount(1) +long(3) refcount(1) +-- +long(3) refcount(1) +long(3) refcount(1) +long(3) refcount(2) +-- +long(4) refcount(1) +string(1) "x" refcount(1) +long(4) refcount(1) +string(1) "x" refcount(1) +long(3) refcount(2) +-- +long(1) refcount(2) +long(2) refcount(2) +---- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(2) refcount(1) +long(1) refcount(1) +long(2) refcount(1) +-- +long(1) refcount(1) +long(3) refcount(1) +long(1) refcount(1) +long(3) refcount(1) +-- +long(4) refcount(1) +long(3) refcount(1) +long(4) refcount(1) +long(3) refcount(1) +-- +long(3) refcount(1) +long(3) refcount(1) +long(3) refcount(2) +-- +long(4) refcount(1) +string(1) "x" refcount(1) +long(4) refcount(1) +string(1) "x" refcount(1) +long(3) refcount(2) +-- +long(1) refcount(2) +long(2) refcount(2) +----r +string(2) "ok" refcount(2) +string(2) "ok" refcount(2) diff --git a/ext/standard/tests/array/bug25758.phpt b/ext/standard/tests/array/bug25758.phpt new file mode 100644 index 0000000..ff97d2e --- /dev/null +++ b/ext/standard/tests/array/bug25758.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #25758 (var_export does not escape ' & \ inside array keys) +--FILE-- +<?php + $a = array ("quote'" => array("quote'")); + echo var_export($a, true); +?> +--EXPECT-- +array ( + 'quote\'' => + array ( + 0 => 'quote\'', + ), +) diff --git a/ext/standard/tests/array/bug26458.phpt b/ext/standard/tests/array/bug26458.phpt Binary files differnew file mode 100644 index 0000000..ecd12ba --- /dev/null +++ b/ext/standard/tests/array/bug26458.phpt diff --git a/ext/standard/tests/array/bug28739.phpt b/ext/standard/tests/array/bug28739.phpt new file mode 100644 index 0000000..f753097 --- /dev/null +++ b/ext/standard/tests/array/bug28739.phpt @@ -0,0 +1,58 @@ +--TEST-- +Bug #28739 (*diff() and *intersect() not clearing the fci cache before work) +--FILE-- +<?php +class p { + public $x; + function __construct($x){$this->x=$x;} +} +function a(&$a, &$b){var_dump(__FUNCTION__);return $a->x - $b->x;} +function b(&$a, &$b){var_dump(__FUNCTION__);return $a->x - $b->x;} + +$p1 = array(new p(2), new p(1), new p(0)); +$p2 = array(new p(0), new p(2), new p(3)); + +uasort($p1, 'a'); +print_r($p1); +echo "Now diffing:\n"; +print_r(array_udiff($p1,$p2, 'b')); +?> +--EXPECT-- +string(1) "a" +string(1) "a" +Array +( + [2] => p Object + ( + [x] => 0 + ) + + [1] => p Object + ( + [x] => 1 + ) + + [0] => p Object + ( + [x] => 2 + ) + +) +Now diffing: +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +string(1) "b" +Array +( + [1] => p Object + ( + [x] => 1 + ) + +) diff --git a/ext/standard/tests/array/bug28974.phpt b/ext/standard/tests/array/bug28974.phpt new file mode 100644 index 0000000..a2bd86f --- /dev/null +++ b/ext/standard/tests/array/bug28974.phpt @@ -0,0 +1,89 @@ +--TEST-- +Bug #28974 (array_(p)slice() treats large lengths incorrectly - overflow) +--FILE-- +<?php +$a = $b = $c = array(0,1,2,3,4,5); +print_r($a); +// this is ok: +print_r(array_slice($a,2,2147483645)); + +// this is wrong: +print_r(array_slice($a,2,2147483646)); +echo 'print_r(array_splice($a,2,1));'."\n"; +print_r(array_splice($a,2,1)); +echo "\$a is :"; +print_r($a); +echo 'print_r(array_splice($b,2,2147483645));'."\n"; +print_r(array_splice($b,2,2147483645)); +echo "\$b is :"; +print_r($b); + +// this is wrong: +echo 'print_r(array_splice($c,2,2147483646));'."\n"; +print_r(array_splice($c,2,2147483646)); +echo "\$c is :"; +print_r($c); +?> +--EXPECT-- +Array +( + [0] => 0 + [1] => 1 + [2] => 2 + [3] => 3 + [4] => 4 + [5] => 5 +) +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +print_r(array_splice($a,2,1)); +Array +( + [0] => 2 +) +$a is :Array +( + [0] => 0 + [1] => 1 + [2] => 3 + [3] => 4 + [4] => 5 +) +print_r(array_splice($b,2,2147483645)); +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +$b is :Array +( + [0] => 0 + [1] => 1 +) +print_r(array_splice($c,2,2147483646)); +Array +( + [0] => 2 + [1] => 3 + [2] => 4 + [3] => 5 +) +$c is :Array +( + [0] => 0 + [1] => 1 +) diff --git a/ext/standard/tests/array/bug29253.phpt b/ext/standard/tests/array/bug29253.phpt new file mode 100644 index 0000000..4be9839 --- /dev/null +++ b/ext/standard/tests/array/bug29253.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #29253 (array_diff with $GLOBALS argument fails) +--FILE-- +<?php +$zz = $GLOBALS; +$gg = 'afad'; +var_dump(@array_diff_assoc($GLOBALS, $zz)); +var_dump($gg); +?> +--EXPECTF-- +array(0) { +} +string(4) "afad" diff --git a/ext/standard/tests/array/bug29493.phpt b/ext/standard/tests/array/bug29493.phpt new file mode 100644 index 0000000..0cfe459 --- /dev/null +++ b/ext/standard/tests/array/bug29493.phpt @@ -0,0 +1,115 @@ +--TEST-- +Bug #29493 (extract(EXTR_REFS) fails if array has multiple referrals) +--FILE-- +<?php +function t1() +{ + $a = array('foo' => 'aaa'); + // refcount($a) = 1 + // refcount($a['foo']) = 1 + $b = $a; + // refcount($a) = 2 + // refcount($a['foo']) = 1 + $b['foo'] = 'bbb'; + // refcount($a) = 1 + // refcount($a['foo']) = 1 + + var_dump($a, $b); + + extract($a, EXTR_REFS); + + $foo = 'noo'; + + var_dump($a, $b); +} + +function t2() +{ + $a = array('foo' => 'aaa'); + // refcount($a) = 1 + // refcount($a['foo']) = 1 + $b = &$a; + // refcount($a) = 2 + // is_ref($a) = true + // refcount($a['foo']) = 1 + $b['foo'] = 'bbb'; + // refcount($a) = 2 + // refcount($a['foo']) = 1 + + var_dump($a, $b); + + extract($a, EXTR_REFS); + + $foo = 'noo'; + + var_dump($a, $b); +} + +function t3() +{ + $a = array('foo' => 'aaa'); + // refcount($a) = 1 + // refcount($a['foo']) = 1 + $b = &$a; + // refcount($a) = 2 + // is_ref($a) = true + // refcount($a['foo']) = 1 + unset($b); + // refcount($a) = 1 + // is_ref($a) = true + // refcount($a['foo']) = 1 + + var_dump($a); + + extract($a, EXTR_REFS); + + $foo = 'noo'; + + var_dump($a); +} + +t1(); +t2(); +t3(); +?> +--EXPECT-- +array(1) { + ["foo"]=> + string(3) "aaa" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + string(3) "bbb" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} +array(1) { + ["foo"]=> + string(3) "aaa" +} +array(1) { + ["foo"]=> + &string(3) "noo" +} diff --git a/ext/standard/tests/array/bug30074.phpt b/ext/standard/tests/array/bug30074.phpt new file mode 100644 index 0000000..7720fe0 --- /dev/null +++ b/ext/standard/tests/array/bug30074.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #30074 (EG(uninitialized_zval_ptr) gets set to reference using EXTR_REFS, affecting later values) +--FILE-- +<?php +error_reporting(E_ALL & ~E_NOTICE); // We don't want the notice for $undefined +$result = extract(array('a'=>$undefined), EXTR_REFS); +var_dump(array($a)); +echo "Done\n"; +?> +--EXPECT-- +array(1) { + [0]=> + NULL +} +Done diff --git a/ext/standard/tests/array/bug30266.phpt b/ext/standard/tests/array/bug30266.phpt new file mode 100644 index 0000000..8f7c3d2 --- /dev/null +++ b/ext/standard/tests/array/bug30266.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #30266 (Invalid opcode 137/1/8) and array_walk +--FILE-- +<?php +class testc +{ + public $b = "c"; + + function crash($val) + { + $this->b = $val; + throw new Exception("Error"); + } +} + +$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple"); + +$myobj = new testc(); + +function test($item2, $key, $userd) +{ + $userd->crash($item2); +} + +try +{ + array_walk($fruits, 'test', $myobj); +} +catch(Exception $e) +{ + echo "Caught: " . $e->getMessage() . "\n"; +} +?> +===DONE=== +--EXPECT-- +Caught: Error +===DONE=== diff --git a/ext/standard/tests/array/bug30833.phpt b/ext/standard/tests/array/bug30833.phpt new file mode 100644 index 0000000..728a659 --- /dev/null +++ b/ext/standard/tests/array/bug30833.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #30833 (array_count_values() modifies input array) +--FILE-- +<?php + +$foo = array('abc', '0000'); +var_dump($foo); + +$count = array_count_values( $foo ); +var_dump($count); + +var_dump($foo); + +echo "Done\n"; +?> +--EXPECT-- +array(2) { + [0]=> + string(3) "abc" + [1]=> + string(4) "0000" +} +array(2) { + ["abc"]=> + int(1) + ["0000"]=> + int(1) +} +array(2) { + [0]=> + string(3) "abc" + [1]=> + string(4) "0000" +} +Done diff --git a/ext/standard/tests/array/bug31158.phpt b/ext/standard/tests/array/bug31158.phpt new file mode 100644 index 0000000..e672a10 --- /dev/null +++ b/ext/standard/tests/array/bug31158.phpt @@ -0,0 +1,17 @@ +--TEST-- +Bug #31158 (array_splice on $GLOBALS crashes) +--FILE-- +<?php +function __(){ + $GLOBALS['a'] = "bug\n"; + array_splice($GLOBALS,0,count($GLOBALS)); + /* All global variables including $GLOBALS are removed */ + echo $GLOBALS['a']; +} +__(); +echo "ok\n"; +?> +--EXPECTF-- +Notice: Undefined variable: GLOBALS in %sbug31158.php on line 6 +ok + diff --git a/ext/standard/tests/array/bug31213.phpt b/ext/standard/tests/array/bug31213.phpt new file mode 100644 index 0000000..6aa31d5 --- /dev/null +++ b/ext/standard/tests/array/bug31213.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug #31213 (Sideeffects caused by bug #29493) +--FILE-- +<?php +function test($use_extract) { + $a = 1; + $b = 1; + + $arr = array( + '_a' => $a, + '_b' => &$b + ); + + var_dump($a, $b); + + if ($use_extract) { + extract($arr, EXTR_REFS); + } else { + $_a = &$arr['_a']; + $_b = &$arr['_b']; + } + + $_a++; + $_b++; + + var_dump($a, $b, $_a, $_b, $arr); +} + +test(false); +test(true); + +?> +--EXPECT-- +int(1) +int(1) +int(1) +int(2) +int(2) +int(2) +array(2) { + ["_a"]=> + &int(2) + ["_b"]=> + &int(2) +} +int(1) +int(1) +int(1) +int(2) +int(2) +int(2) +array(2) { + ["_a"]=> + &int(2) + ["_b"]=> + &int(2) +} diff --git a/ext/standard/tests/array/bug32021.phpt b/ext/standard/tests/array/bug32021.phpt new file mode 100644 index 0000000..5d3b421 --- /dev/null +++ b/ext/standard/tests/array/bug32021.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #32021 (Crash caused by range('', 'z')) +--FILE-- +<?php +$foo = range('', 'z'); +var_dump($foo); +?> +ALIVE +--EXPECT-- +array(1) { + [0]=> + int(0) +} +ALIVE diff --git a/ext/standard/tests/array/bug33382.phpt b/ext/standard/tests/array/bug33382.phpt new file mode 100644 index 0000000..e54b984 --- /dev/null +++ b/ext/standard/tests/array/bug33382.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #33382 (array_reverse() fails after *sort() ) +--FILE-- +<?php + +$array = array(1,2,3,4,5); + +sort($array); + +var_dump(array_reverse($array)); + +echo "Done\n"; +?> +--EXPECT-- +array(5) { + [0]=> + int(5) + [1]=> + int(4) + [2]=> + int(3) + [3]=> + int(2) + [4]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/bug33989.phpt b/ext/standard/tests/array/bug33989.phpt new file mode 100644 index 0000000..ccef172 --- /dev/null +++ b/ext/standard/tests/array/bug33989.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #33989 (extract($GLOBALS,EXTR_REFS) crashes PHP) +--FILE-- +<?php +$a="a"; +extract($GLOBALS, EXTR_REFS); +echo "ok\n"; +?> +--EXPECT-- +ok diff --git a/ext/standard/tests/array/bug34066.phpt b/ext/standard/tests/array/bug34066.phpt new file mode 100644 index 0000000..31f6b4c --- /dev/null +++ b/ext/standard/tests/array/bug34066.phpt @@ -0,0 +1,804 @@ +--TEST-- +Bug #34066 (recursive array_walk causes segfault) +--FILE-- +<?php + + $order = array( + "DocID" => "1", + "DocDate" => "19.09.06", + "ReSubmissionDate" => "", + "DocTyp" => "Stapelauftrag", + "CustID" => "00000", + "CustomerAddress" => array( + array( + "Name1" => 'name1', + "Name2" => 'name2', + "Name3" => "", + "City" => 'city', + "Street" => 'street', + "Postal" => 'postcode', + "IATA" => "90", + "Country" => "Deutschland", + "ShortName" => 'short', + "ContactKey" => "", + "EMail" => 'email@example.com', + ) + ), + "Text1" => "", + "Text2" => "", + "Wildcard1" => "", + "Wildcard2" => "", + "Dispatch" => "Paketdienst", + "Weight" => "0,0", + "BillingCustID" => "4300200000", + "ExtDocNr" => "00000000003", + "AnalysisLock" => "", + "PrintFlag" => "", + "FormType" => "0", + "Curr" => "EUR", + "ExChangeRate" => "1,0000", + "WIRRate" => "0", + "OneTimeCustomer" => array( + array( + "BankCode" => "", + "BankAccount" => "" + ) + ), + "Language" => "0", + "PriceGroup" => "1", + "PrFlag" => "0", + "SalesTaxKey" => "1", + "ProceedKey" => "0", + "CustDiscountGroup" => "0", + "Discount" => array( + array( + "FinDisc1" => "0,00", + "Disc1Base" => "145,72", + "Disc1Value" => "0,00", + "FinDisc2" => "0,00", + "Disc2Base" => "145,72", + "Disc2Value" => "0,00", + "FinDisc3" => "0,00", + "Disc3Base" => "145,72", + "Disc3Value" => "0,00", + "ValueSummary" => "0,00" + ) + ), + "Contact" => array( + array( + "Repr" => "999", + "Region" => "99", + "Commission" => "0,00", + "Agent" => "000000" + ) + ), + "Booking" => array( + array( + "CostUnit" => "0000000000", + "CostCentre" => "0000000000", + "AccountingArea"=> "01" + ) + ), + "InvoiceCycleKey" => "0", + "AnalysisKey" => "", + "OrderNumber" => "", + "OrderDate" => "", + "OrderCode" => "", + "DocItems" => array( + "DocItem" => array( + "PosType" => "1", + "ItemRef" => "1002", + "CRef" => "", + "Desc1" => "Pr�sentation Niederlande per", + "Desc2" => "", + "ArticleGroup" => "102", + "PosTypeVersion" => "E", + "Delivery" => array( + array( + "DelWeek" => "", + "DelDay" => "", + "DelTime" => "" + ) + ), + "PricePu" => "145,72", + "PriceUnit" => "0", + "PriceCalculation" => "0", + "ItemVal" => "145,72", + "InputKey" => "0", + "AveragePurchasePrice" => "0", + "Tax" => array( + array( + "TaxCode" => "00", + "TaxBra" => "000", + "TaxBraAccess" => "0", + "TaxSumIndex" => "0" + ) + ), + "DiscountArticle" => array( + array( + "DiscPC" => "0,00", + "DiscKey" => "1" + ) + ), + "ProceedKeyArticle" => "01", + "ActionKey" => "00", + "ContactCommissionArticle"=> "0,00", + "QuantDependantPriceKey"=> "", + "Quant" => "1", + "QuantUnit" => "", + "Meas" => array( + array( + "Count" => "1", + "Length" => "0,000", + "Width" => "0,000", + "Height" => "0,000" + ) + ), + "DecimalPlace" => "0", + "MultiplierQuant" => "1,000000", + "DifferingQuantUnit" => "", + "DecimalPlaceConversion"=> "0", + "WeightArticle" => array( + array( + "Amount" => "0", + "Unit" => "0" + ) + ), + "Wreath" => "0,000", + "Stock" => "1", + "CostUnitArticle" => "", + "SerialNbKey" => "0", + "TextComplementKey" => "0", + "PartsListPrintKey" => "", + "Prod" => "0000000000" + ) + ), + "Payment" => array( + "PaymentKey" => "0", + "ReminderKey" => "00", + "PayTerms" => array( + array( + "PayTerm" => "1", + "PayDays" => "000", + "CashDiscDays1" => "000", + "CashDiscDays2" => "000", + "CashDiscPer1" => "0,00", + "CashDiscPer2" => "0,00" + ), + array( + "PayTerm" => "2", + "PayDays" => "000", + "CashDiscDays1" => "000", + "CashDiscDays2" => "000", + "CashDiscPer1" => "0,00", + "CashDiscPer2" => "0,00" + ) + ) + ), + "NetAmountByTurnOverTax" => array( + array( + "TurnOverTaxFree" => "145,72", + "TurnOverTax1" => "0,00", + "TurnOverTax2" => "0,00", + "TurnOverTax3" => "0,00", + "TurnOverTax4" => "0,00", + "TurnOverTax5" => "0,00", + "TurnOverTax6" => "0,00", + "TurnOverTax7" => "0,00", + "TurnOverTax8" => "0,00" + ), + ), + "GrossAmount" => "145,72", + "ProceedAmount" => "145,72", + "NetAmountByPayTerm2" => array( + array( + "Sum0" => "0,00", + "Sum1" => "0,00", + "Sum2" => "0,00", + "Sum3" => "0,00", + "Sum4" => "0,00", + "Sum5" => "0,00", + "Sum6" => "0,00", + "Sum7" => "0,00", + "Sum8" => "0,00" + ), + ), + "TaxCodes" => array( + array( + "TaxCode1" => "0", + "TaxCode2" => "0", + "TaxCode3" => "0", + "TaxCode4" => "0", + "TaxCode5" => "0", + "TaxCode6" => "0", + "TaxCode7" => "0", + "TaxCode8" => "0" + ) + ) + ); + $docs = array( + array( + "Version" => "1.0", + "ProducerName" => "xxxxxxxx", + "ProductName" => "Classic Line", + "xmlns" => "x-schema:CL310_DezABFSchema.XML" + ), + "Company" => array( + array( + "MandateNumber" => "111", + "MandateName" => "xxx xxxxxxx-xxxxx xxxxxxx", + "MandateCurr" => "EUR" + ), + ), + "Doc" => $order + ); + + dump2xml($docs); + + +function dump2xml($array) { + // output of this goes through 2xml + array_walk($array, "gen_xml", "/Docs/"); +} +function gen_xml($val, $key, $prefix) +{ + global $xml_fd; + print "gen_xml(prefix=$prefix)\n"; + if (is_array($val)) { + if (preg_match('/^\d+$/', $key)) { + if ($key == 1) { + print substr($prefix, 0, -1) . "\n"; + } + array_walk($val, "gen_xml", "$prefix@"); + } + else { + array_walk($val, "gen_xml", "$prefix$key/"); + } + } + else { + if (strlen($val) > 0) + print "$prefix$key=$val\n"; + else + print "$prefix$key\n"; + } + print "gen_xml(prefix=$prefix) end\n"; +} +echo "Done\n"; +?> +--EXPECTF-- +gen_xml(prefix=/Docs/) +gen_xml(prefix=/Docs/@) +/Docs/@Version=1.0 +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/@) +/Docs/@ProducerName=xxxxxxxx +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/@) +/Docs/@ProductName=Classic Line +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/@) +/Docs/@xmlns=x-schema:CL310_DezABFSchema.XML +gen_xml(prefix=/Docs/@) end +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +gen_xml(prefix=/Docs/Company/) +gen_xml(prefix=/Docs/Company/@) +/Docs/Company/@MandateNumber=111 +gen_xml(prefix=/Docs/Company/@) end +gen_xml(prefix=/Docs/Company/@) +/Docs/Company/@MandateName=xxx xxxxxxx-xxxxx xxxxxxx +gen_xml(prefix=/Docs/Company/@) end +gen_xml(prefix=/Docs/Company/@) +/Docs/Company/@MandateCurr=EUR +gen_xml(prefix=/Docs/Company/@) end +gen_xml(prefix=/Docs/Company/) end +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/DocID=1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/DocDate=19.09.06 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ReSubmissionDate +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/DocTyp=Stapelauftrag +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/CustID=00000 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/CustomerAddress/) +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Name1=name1 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Name2=name2 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Name3 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@City=city +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Street=street +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Postal=postcode +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@IATA=90 +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@Country=Deutschland +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@ShortName=short +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@ContactKey +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) +/Docs/Doc/CustomerAddress/@EMail=email@example.com +gen_xml(prefix=/Docs/Doc/CustomerAddress/@) end +gen_xml(prefix=/Docs/Doc/CustomerAddress/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Text1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Text2 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Wildcard1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Wildcard2 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Dispatch=Paketdienst +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Weight=0,0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/BillingCustID=4300200000 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ExtDocNr=00000000003 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/AnalysisLock +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/PrintFlag +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/FormType=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Curr=EUR +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ExChangeRate=1,0000 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/WIRRate=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/) +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) +/Docs/Doc/OneTimeCustomer/@BankCode +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) end +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) +/Docs/Doc/OneTimeCustomer/@BankAccount +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/@) end +gen_xml(prefix=/Docs/Doc/OneTimeCustomer/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/Language=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/PriceGroup=1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/PrFlag=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/SalesTaxKey=1 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ProceedKey=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/CustDiscountGroup=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Discount/) +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@FinDisc1=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc1Base=145,72 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc1Value=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@FinDisc2=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc2Base=145,72 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc2Value=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@FinDisc3=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc3Base=145,72 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@Disc3Value=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/@) +/Docs/Doc/Discount/@ValueSummary=0,00 +gen_xml(prefix=/Docs/Doc/Discount/@) end +gen_xml(prefix=/Docs/Doc/Discount/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Contact/) +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Repr=999 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Region=99 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Commission=0,00 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/@) +/Docs/Doc/Contact/@Agent=000000 +gen_xml(prefix=/Docs/Doc/Contact/@) end +gen_xml(prefix=/Docs/Doc/Contact/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Booking/) +gen_xml(prefix=/Docs/Doc/Booking/@) +/Docs/Doc/Booking/@CostUnit=0000000000 +gen_xml(prefix=/Docs/Doc/Booking/@) end +gen_xml(prefix=/Docs/Doc/Booking/@) +/Docs/Doc/Booking/@CostCentre=0000000000 +gen_xml(prefix=/Docs/Doc/Booking/@) end +gen_xml(prefix=/Docs/Doc/Booking/@) +/Docs/Doc/Booking/@AccountingArea=01 +gen_xml(prefix=/Docs/Doc/Booking/@) end +gen_xml(prefix=/Docs/Doc/Booking/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/InvoiceCycleKey=0 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/AnalysisKey +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/OrderNumber +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/OrderDate +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/OrderCode +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/DocItems/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PosType=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ItemRef=1002 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/CRef +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Desc1=Pr�sentation Niederlande per +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Desc2 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ArticleGroup=102 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PosTypeVersion=E +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) +/Docs/Doc/DocItems/DocItem/Delivery/@DelWeek +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) +/Docs/Doc/DocItems/DocItem/Delivery/@DelDay +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) +/Docs/Doc/DocItems/DocItem/Delivery/@DelTime +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Delivery/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PricePu=145,72 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PriceUnit=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PriceCalculation=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ItemVal=145,72 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/InputKey=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/AveragePurchasePrice=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxCode=00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxBra=000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxBraAccess=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) +/Docs/Doc/DocItems/DocItem/Tax/@TaxSumIndex=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Tax/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) +/Docs/Doc/DocItems/DocItem/DiscountArticle/@DiscPC=0,00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) +/Docs/Doc/DocItems/DocItem/DiscountArticle/@DiscKey=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/DiscountArticle/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ProceedKeyArticle=01 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ActionKey=00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/ContactCommissionArticle=0,00 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/QuantDependantPriceKey +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Quant=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/QuantUnit +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Count=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Length=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Width=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) +/Docs/Doc/DocItems/DocItem/Meas/@Height=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/Meas/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/DecimalPlace=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/MultiplierQuant=1,000000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/DifferingQuantUnit +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/DecimalPlaceConversion=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/) +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) +/Docs/Doc/DocItems/DocItem/WeightArticle/@Amount=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) +/Docs/Doc/DocItems/DocItem/WeightArticle/@Unit=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/@) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/WeightArticle/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Wreath=0,000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Stock=1 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/CostUnitArticle +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/SerialNbKey=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/TextComplementKey=0 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/PartsListPrintKey +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) +/Docs/Doc/DocItems/DocItem/Prod=0000000000 +gen_xml(prefix=/Docs/Doc/DocItems/DocItem/) end +gen_xml(prefix=/Docs/Doc/DocItems/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/Payment/) +/Docs/Doc/Payment/PaymentKey=0 +gen_xml(prefix=/Docs/Doc/Payment/) end +gen_xml(prefix=/Docs/Doc/Payment/) +/Docs/Doc/Payment/ReminderKey=00 +gen_xml(prefix=/Docs/Doc/Payment/) end +gen_xml(prefix=/Docs/Doc/Payment/) +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayTerm=1 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayDays=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays1=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays2=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer1=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer2=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) +/Docs/Doc/Payment/PayTerms +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayTerm=2 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@PayDays=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays1=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscDays2=000 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer1=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) +/Docs/Doc/Payment/PayTerms/@CashDiscPer2=0,00 +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/@) end +gen_xml(prefix=/Docs/Doc/Payment/PayTerms/) end +gen_xml(prefix=/Docs/Doc/Payment/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/) +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTaxFree=145,72 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax1=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax2=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax3=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax4=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax5=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax6=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax7=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) +/Docs/Doc/NetAmountByTurnOverTax/@TurnOverTax8=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByTurnOverTax/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/GrossAmount=145,72 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +/Docs/Doc/ProceedAmount=145,72 +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/) +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum0=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum1=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum2=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum3=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum4=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum5=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum6=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum7=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) +/Docs/Doc/NetAmountByPayTerm2/@Sum8=0,00 +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/@) end +gen_xml(prefix=/Docs/Doc/NetAmountByPayTerm2/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/Doc/) +gen_xml(prefix=/Docs/Doc/TaxCodes/) +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode1=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode2=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode3=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode4=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode5=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode6=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode7=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/@) +/Docs/Doc/TaxCodes/@TaxCode8=0 +gen_xml(prefix=/Docs/Doc/TaxCodes/@) end +gen_xml(prefix=/Docs/Doc/TaxCodes/) end +gen_xml(prefix=/Docs/Doc/) end +gen_xml(prefix=/Docs/) end +Done diff --git a/ext/standard/tests/array/bug34066_1.phpt b/ext/standard/tests/array/bug34066_1.phpt new file mode 100644 index 0000000..edc16ef --- /dev/null +++ b/ext/standard/tests/array/bug34066_1.phpt @@ -0,0 +1,731 @@ +--TEST-- +Bug #34066 (recursive array_walk causes segfault) +--FILE-- +<?php + + $order = array( + "DocID" => "1", + "DocDate" => "19.09.06", + "ReSubmissionDate" => "", + "DocTyp" => "Stapelauftrag", + "CustID" => "00000", + "CustomerAddress" => array( + array( + "Name1" => 'name1', + "Name2" => 'name2', + "Name3" => "", + "City" => 'city', + "Street" => 'street', + "Postal" => 'postcode', + "IATA" => "90", + "Country" => "Deutschland", + "ShortName" => 'short', + "ContactKey" => "", + "EMail" => 'email@example.com', + ) + ), + "Text1" => "", + "Text2" => "", + "Wildcard1" => "", + "Wildcard2" => "", + "Dispatch" => "Paketdienst", + "Weight" => "0,0", + "BillingCustID" => "4300200000", + "ExtDocNr" => "00000000003", + "AnalysisLock" => "", + "PrintFlag" => "", + "FormType" => "0", + "Curr" => "EUR", + "ExChangeRate" => "1,0000", + "WIRRate" => "0", + "OneTimeCustomer" => array( + array( + "BankCode" => "", + "BankAccount" => "" + ) + ), + "Language" => "0", + "PriceGroup" => "1", + "PrFlag" => "0", + "SalesTaxKey" => "1", + "ProceedKey" => "0", + "CustDiscountGroup" => "0", + "Discount" => array( + array( + "FinDisc1" => "0,00", + "Disc1Base" => "145,72", + "Disc1Value" => "0,00", + "FinDisc2" => "0,00", + "Disc2Base" => "145,72", + "Disc2Value" => "0,00", + "FinDisc3" => "0,00", + "Disc3Base" => "145,72", + "Disc3Value" => "0,00", + "ValueSummary" => "0,00" + ) + ), + "Contact" => array( + array( + "Repr" => "999", + "Region" => "99", + "Commission" => "0,00", + "Agent" => "000000" + ) + ), + "Booking" => array( + array( + "CostUnit" => "0000000000", + "CostCentre" => "0000000000", + "AccountingArea"=> "01" + ) + ), + "InvoiceCycleKey" => "0", + "AnalysisKey" => "", + "OrderNumber" => "", + "OrderDate" => "", + "OrderCode" => "", + "DocItems" => array( + "DocItem" => array( + "PosType" => "1", + "ItemRef" => "1002", + "CRef" => "", + "Desc1" => "Pr�sentation Niederlande per", + "Desc2" => "", + "ArticleGroup" => "102", + "PosTypeVersion" => "E", + "Delivery" => array( + array( + "DelWeek" => "", + "DelDay" => "", + "DelTime" => "" + ) + ), + "PricePu" => "145,72", + "PriceUnit" => "0", + "PriceCalculation" => "0", + "ItemVal" => "145,72", + "InputKey" => "0", + "AveragePurchasePrice" => "0", + "Tax" => array( + array( + "TaxCode" => "00", + "TaxBra" => "000", + "TaxBraAccess" => "0", + "TaxSumIndex" => "0" + ) + ), + "DiscountArticle" => array( + array( + "DiscPC" => "0,00", + "DiscKey" => "1" + ) + ), + "ProceedKeyArticle" => "01", + "ActionKey" => "00", + "ContactCommissionArticle"=> "0,00", + "QuantDependantPriceKey"=> "", + "Quant" => "1", + "QuantUnit" => "", + "Meas" => array( + array( + "Count" => "1", + "Length" => "0,000", + "Width" => "0,000", + "Height" => "0,000" + ) + ), + "DecimalPlace" => "0", + "MultiplierQuant" => "1,000000", + "DifferingQuantUnit" => "", + "DecimalPlaceConversion"=> "0", + "WeightArticle" => array( + array( + "Amount" => "0", + "Unit" => "0" + ) + ), + "Wreath" => "0,000", + "Stock" => "1", + "CostUnitArticle" => "", + "SerialNbKey" => "0", + "TextComplementKey" => "0", + "PartsListPrintKey" => "", + "Prod" => "0000000000" + ) + ), + "Payment" => array( + "PaymentKey" => "0", + "ReminderKey" => "00", + "PayTerms" => array( + array( + "PayTerm" => "1", + "PayDays" => "000", + "CashDiscDays1" => "000", + "CashDiscDays2" => "000", + "CashDiscPer1" => "0,00", + "CashDiscPer2" => "0,00" + ), + array( + "PayTerm" => "2", + "PayDays" => "000", + "CashDiscDays1" => "000", + "CashDiscDays2" => "000", + "CashDiscPer1" => "0,00", + "CashDiscPer2" => "0,00" + ) + ) + ), + "NetAmountByTurnOverTax" => array( + array( + "TurnOverTaxFree" => "145,72", + "TurnOverTax1" => "0,00", + "TurnOverTax2" => "0,00", + "TurnOverTax3" => "0,00", + "TurnOverTax4" => "0,00", + "TurnOverTax5" => "0,00", + "TurnOverTax6" => "0,00", + "TurnOverTax7" => "0,00", + "TurnOverTax8" => "0,00" + ), + ), + "GrossAmount" => "145,72", + "ProceedAmount" => "145,72", + "NetAmountByPayTerm2" => array( + array( + "Sum0" => "0,00", + "Sum1" => "0,00", + "Sum2" => "0,00", + "Sum3" => "0,00", + "Sum4" => "0,00", + "Sum5" => "0,00", + "Sum6" => "0,00", + "Sum7" => "0,00", + "Sum8" => "0,00" + ), + ), + "TaxCodes" => array( + array( + "TaxCode1" => "0", + "TaxCode2" => "0", + "TaxCode3" => "0", + "TaxCode4" => "0", + "TaxCode5" => "0", + "TaxCode6" => "0", + "TaxCode7" => "0", + "TaxCode8" => "0" + ) + ) + ); + $docs = array( + array( + "Version" => "1.0", + "ProducerName" => "xxxxxxxx", + "ProductName" => "Classic Line", + "xmlns" => "x-schema:CL310_DezABFSchema.XML" + ), + "Company" => array( + array( + "MandateNumber" => "111", + "MandateName" => "xxx xxxxxxx-xxxxx xxxxxxx", + "MandateCurr" => "EUR" + ), + ), + "Doc" => $order + ); + + dump2xml($docs); + + +function dump2xml($array) { + // output of this goes through 2xml + array_walk_recursive($array, "gen_xml", "/Docs/"); +} +function gen_xml($val, $key, $prefix) +{ + global $xml_fd; + print "gen_xml(prefix=$prefix)\n"; + if (is_array($val)) { + if (preg_match('/^\d+$/', $key)) { + if ($key == 1) { + print substr($prefix, 0, -1) . "\n"; + } + array_walk_recursive($val, "gen_xml", "$prefix@"); + } + else { + array_walk_recursive($val, "gen_xml", "$prefix$key/"); + } + } + else { + if (strlen($val) > 0) + print "$prefix$key=$val\n"; + else + print "$prefix$key\n"; + } + print "gen_xml(prefix=$prefix) end\n"; +} +echo "Done\n"; +?> +--EXPECTF-- +gen_xml(prefix=/Docs/) +/Docs/Version=1.0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProducerName=xxxxxxxx +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProductName=Classic Line +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/xmlns=x-schema:CL310_DezABFSchema.XML +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MandateNumber=111 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MandateName=xxx xxxxxxx-xxxxx xxxxxxx +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MandateCurr=EUR +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DocID=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DocDate=19.09.06 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ReSubmissionDate +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DocTyp=Stapelauftrag +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CustID=00000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Name1=name1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Name2=name2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Name3 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/City=city +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Street=street +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Postal=postcode +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/IATA=90 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Country=Deutschland +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ShortName=short +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ContactKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/EMail=email@example.com +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Text1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Text2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Wildcard1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Wildcard2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Dispatch=Paketdienst +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Weight=0,0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/BillingCustID=4300200000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ExtDocNr=00000000003 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AnalysisLock +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PrintFlag +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FormType=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Curr=EUR +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ExChangeRate=1,0000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/WIRRate=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/BankCode +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/BankAccount +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Language=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PriceGroup=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PrFlag=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/SalesTaxKey=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProceedKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CustDiscountGroup=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FinDisc1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc1Base=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc1Value=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FinDisc2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc2Base=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc2Value=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/FinDisc3=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc3Base=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Disc3Value=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ValueSummary=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Repr=999 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Region=99 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Commission=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Agent=000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CostUnit=0000000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CostCentre=0000000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AccountingArea=01 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/InvoiceCycleKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AnalysisKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/OrderNumber +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/OrderDate +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/OrderCode +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PosType=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ItemRef=1002 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CRef +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Desc1=Pr�sentation Niederlande per +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Desc2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ArticleGroup=102 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PosTypeVersion=E +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DelWeek +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DelDay +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DelTime +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PricePu=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PriceUnit=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PriceCalculation=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ItemVal=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/InputKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/AveragePurchasePrice=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode=00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxBra=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxBraAccess=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxSumIndex=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DiscPC=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DiscKey=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProceedKeyArticle=01 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ActionKey=00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ContactCommissionArticle=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/QuantDependantPriceKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Quant=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/QuantUnit +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Count=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Length=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Width=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Height=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DecimalPlace=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/MultiplierQuant=1,000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DifferingQuantUnit +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/DecimalPlaceConversion=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Amount=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Unit=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Wreath=0,000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Stock=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CostUnitArticle +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/SerialNbKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TextComplementKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PartsListPrintKey +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Prod=0000000000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PaymentKey=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ReminderKey=00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayTerm=1 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayDays=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays1=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays2=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayTerm=2 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/PayDays=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays1=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscDays2=000 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/CashDiscPer2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTaxFree=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax3=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax4=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax5=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax6=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax7=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TurnOverTax8=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/GrossAmount=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/ProceedAmount=145,72 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum0=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum1=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum2=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum3=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum4=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum5=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum6=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum7=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/Sum8=0,00 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode1=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode2=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode3=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode4=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode5=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode6=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode7=0 +gen_xml(prefix=/Docs/) end +gen_xml(prefix=/Docs/) +/Docs/TaxCode8=0 +gen_xml(prefix=/Docs/) end +Done diff --git a/ext/standard/tests/array/bug34227.phpt b/ext/standard/tests/array/bug34227.phpt new file mode 100644 index 0000000..29762b7 --- /dev/null +++ b/ext/standard/tests/array/bug34227.phpt @@ -0,0 +1,100 @@ +--TEST-- +Bug #34277 (array_filter() crashes with references and objects) +--FILE-- +<?php + +class C +{ + function m1() + { + $this->m2(); + } + + function m2() + { + $this->m3(); + } + + function m3() + { + $this->m4(); + } + + function m4() + { + $this->m5(); + } + + function m5() + { + $this->m6(); + } + + function m6() + { + $this->m7(); + } + + function m7() + { + $this->m8(); + } + + function m8() + { + $this->m9(); + } + + function m9() + { + $this->m10(); + } + + function m10() + { + $this->m11(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + } + + function m11($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10) + { + $arr = explode('a', 'b'); + } +} + +function f($str) +{ + $obj = new C; + $obj->m1(); + return TRUE; +} + +function p5($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $a11, $a12) +{ + $ret = array_filter(array(0), 'f'); +} + +function p4() +{ + p5(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12); +} + +function p3() +{ + p4(); +} + +function p2() +{ + p3(); +} + +function p1() +{ + p2(); +} + +p1(); +echo "ok\n"; +?> +--EXPECT-- +ok diff --git a/ext/standard/tests/array/bug34982.phpt b/ext/standard/tests/array/bug34982.phpt new file mode 100644 index 0000000..7499667 --- /dev/null +++ b/ext/standard/tests/array/bug34982.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #34982 (array_walk_recursive() modifies elements outside function scope) +--FILE-- +<?php +$ar = array( + 'element 1', + array('subelement1') + ); + +func($ar); +print_r($ar); + +function func($a) { + array_walk_recursive($a, 'apply'); + print_r($a); +} + +function apply(&$input, $key) { + $input = 'changed'; +} +?> +--EXPECT-- +Array +( + [0] => changed + [1] => Array + ( + [0] => changed + ) + +) +Array +( + [0] => element 1 + [1] => Array + ( + [0] => subelement1 + ) + +) diff --git a/ext/standard/tests/array/bug35014.phpt b/ext/standard/tests/array/bug35014.phpt new file mode 100644 index 0000000..9250c03 --- /dev/null +++ b/ext/standard/tests/array/bug35014.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #35014 (array_product() always returns 0) (32bit) +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> +--INI-- +precision=14 +--FILE-- +<?php +$tests = array( + 'foo', + array(), + array(0), + array(3), + array(3, 3), + array(0.5, 2), + array(99999999, 99999999), + array(8.993, 7443241,988, sprintf("%u", -1)+0.44), + array(2,sprintf("%u", -1)), +); + +foreach ($tests as $v) { + var_dump(array_product($v)); +} +?> +--EXPECTF-- +Warning: array_product() expects parameter 1 to be array, string given in %s on line %d +NULL +int(1) +int(0) +int(3) +int(9) +float(1) +float(9.9999998E+15) +float(2.8404260053903E+20) +float(8589934590) diff --git a/ext/standard/tests/array/bug35014_64bit.phpt b/ext/standard/tests/array/bug35014_64bit.phpt new file mode 100644 index 0000000..efd791a --- /dev/null +++ b/ext/standard/tests/array/bug35014_64bit.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #35014 (array_product() always returns 0) (64bit) +--SKIPIF-- +<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> +--INI-- +precision=14 +--FILE-- +<?php +$tests = array( + 'foo', + array(), + array(0), + array(3), + array(3, 3), + array(0.5, 2), + array(99999999, 99999999), + array(8.993, 7443241,988, sprintf("%u", -1)+0.44), + array(2,sprintf("%u", -1)), +); + +foreach ($tests as $v) { + var_dump(array_product($v)); +} +?> +--EXPECTF-- +Warning: array_product() expects parameter 1 to be array, string given in %s on line %d +NULL +int(1) +int(0) +int(3) +int(9) +float(1) +int(9999999800000001) +float(1.219953680145E+30) +float(3.6893488147419E+19) diff --git a/ext/standard/tests/array/bug35022.phpt b/ext/standard/tests/array/bug35022.phpt new file mode 100644 index 0000000..e3f5386 --- /dev/null +++ b/ext/standard/tests/array/bug35022.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #35022 (Regression in the behavior of key/current functions) +--FILE-- +<?php +$state = array("one" => 1, "two" => 2, "three" => 3); +function foo( &$state ) { + $contentDict = end( $state ); + for ( $contentDict = end( $state ); $contentDict !== false; $contentDict = prev( $state ) ) { + echo key($state) . " => " . current($state) . "\n"; + } +} +foo($state); +reset($state); +var_dump( key($state), current($state) ); +?> +--EXPECT-- +three => 3 +two => 2 +one => 1 +string(3) "one" +int(1) diff --git a/ext/standard/tests/array/bug35821.phpt b/ext/standard/tests/array/bug35821.phpt new file mode 100644 index 0000000..05140d0 --- /dev/null +++ b/ext/standard/tests/array/bug35821.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #35821 (array_map() segfaults when exception is throwed from the callback) +--FILE-- +<?php + +class Element +{ + public function ThrowException () + { + throw new Exception(); + } + + public static function CallBack(Element $elem) + { + $elem->ThrowException(); + } +} + +$arr = array(new Element(), new Element(), new Element()); +array_map(array('Element', 'CallBack'), $arr); + +echo "Done\n"; +?> +--EXPECTF-- + +Warning: array_map(): An error occurred while invoking the map callback in %s on line %d + +Fatal error: Uncaught exception 'Exception' in %s:%d +Stack trace: +#0 %s(%d): Element->ThrowException() +#1 [internal function]: Element::CallBack(Object(Element)) +#2 %s(%d): array_map(Array, Array) +#3 {main} + thrown in %s on line %d diff --git a/ext/standard/tests/array/bug36975.phpt b/ext/standard/tests/array/bug36975.phpt new file mode 100644 index 0000000..f37c933 --- /dev/null +++ b/ext/standard/tests/array/bug36975.phpt @@ -0,0 +1,62 @@ +--TEST-- +Bug #36975 (natcasesort() causes array_pop() to misbehave) +--FILE-- +<?php +$a = array('aa', 'aa', 'bb', 'bb', 'cc', 'cc'); +$test = natcasesort($a); +if ($test) { + echo "natcasesort success!\n"; +} +$val = array_pop($a); +$a[] = $val; +var_dump($a); + +$b = array(1 => 'foo', 0 => 'baz'); +array_pop($b); +$b[] = 'bar'; +array_push($b, 'bar'); +print_r($b); + +$c = array(0, 0, 0, 0, 0); +asort($c); +array_pop($c); +$c[] = 'foo'; +$c[] = 'bar'; +var_dump($c); +?> +--EXPECT-- +natcasesort success! +array(6) { + [0]=> + string(2) "aa" + [1]=> + string(2) "aa" + [3]=> + string(2) "bb" + [2]=> + string(2) "bb" + [5]=> + string(2) "cc" + [6]=> + string(2) "cc" +} +Array +( + [1] => foo + [2] => bar + [3] => bar +) +array(6) { + [4]=> + int(0) + [3]=> + int(0) + [2]=> + int(0) + [1]=> + int(0) + [5]=> + string(3) "foo" + [6]=> + string(3) "bar" +} diff --git a/ext/standard/tests/array/bug38464.phpt b/ext/standard/tests/array/bug38464.phpt new file mode 100644 index 0000000..42f7a6a --- /dev/null +++ b/ext/standard/tests/array/bug38464.phpt @@ -0,0 +1,20 @@ +--TEST-- +Bug #38464 (array_count_values() mishandles numeric strings) +--FILE-- +<?php +$array = array('-000', ' 001', 1, ' 123', '+123'); +var_dump(array_count_values($array)); +?> +--EXPECT-- +array(5) { + ["-000"]=> + int(1) + [" 001"]=> + int(1) + [1]=> + int(1) + [" 123"]=> + int(1) + ["+123"]=> + int(1) +} diff --git a/ext/standard/tests/array/bug39576.phpt b/ext/standard/tests/array/bug39576.phpt new file mode 100644 index 0000000..7c8aeef --- /dev/null +++ b/ext/standard/tests/array/bug39576.phpt @@ -0,0 +1,52 @@ +--TEST-- +Bug #39576 (array_walk() doesn't separate userdata zval) +--FILE-- +<?php + +class Test { + + public $_table = ''; + public $_columns = array (); + public $_primary = array (); + +} + +$test = new Test (); +$test->name = 'test'; +$test->_columns['name'] = new stdClass; + +function test ($value, $column, &$columns) {} + +array_walk ( + get_object_vars ($test), + 'test', + $test->_columns +); + +var_dump($test); + +array_intersect_key ( + get_object_vars ($test), + $test->_primary +); + +echo "Done\n"; +?> +--EXPECTF-- +Strict Standards: Only variables should be passed by reference in %s on line %d +object(Test)#%d (4) { + ["_table"]=> + string(0) "" + ["_columns"]=> + array(1) { + ["name"]=> + object(stdClass)#%d (0) { + } + } + ["_primary"]=> + array(0) { + } + ["name"]=> + string(4) "test" +} +Done diff --git a/ext/standard/tests/array/bug40191.phpt b/ext/standard/tests/array/bug40191.phpt new file mode 100644 index 0000000..244ce78 --- /dev/null +++ b/ext/standard/tests/array/bug40191.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #40191 (use of array_unique() with objects triggers segfault) +--SKIPIF-- +<?php if (!extension_loaded('spl')) die("skip SPL is not available"); ?> +--FILE-- +<?php + +$arrObj = new ArrayObject(); +$arrObj->append('foo'); +$arrObj->append('bar'); +$arrObj->append('foo'); + +$arr = array_unique($arrObj); +var_dump($arr); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: array_unique() expects parameter 1 to be array, object given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/bug40709.phpt b/ext/standard/tests/array/bug40709.phpt new file mode 100644 index 0000000..eb0c712 --- /dev/null +++ b/ext/standard/tests/array/bug40709.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #40709 (array_reduce() behaves strange with one item stored arrays) +--FILE-- +<?php +function CommaSeperatedList($a, $b) { + if($a == null) + return $b; + else + return $a.','.$b; +} + +$arr1 = array(1,2,3); +$arr2 = array(1); + +echo "result for arr1: ".array_reduce($arr1,'CommaSeperatedList')."\n"; +echo "result for arr2: ".array_reduce($arr2,'CommaSeperatedList')."\n"; +echo "result for arr1: ".array_reduce($arr1,'CommaSeperatedList')."\n"; +echo "result for arr2: ".array_reduce($arr2,'CommaSeperatedList')."\n"; + +echo "Done\n"; +?> +--EXPECT-- +result for arr1: 1,2,3 +result for arr2: 1 +result for arr1: 1,2,3 +result for arr2: 1 +Done diff --git a/ext/standard/tests/array/bug41121.phpt b/ext/standard/tests/array/bug41121.phpt new file mode 100644 index 0000000..a03bdaf --- /dev/null +++ b/ext/standard/tests/array/bug41121.phpt @@ -0,0 +1,128 @@ +--TEST-- +Bug #41121 (range() overflow handling for large numbers on 32bit machines) +--INI-- +precision=14 +--SKIPIF-- +<?php if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); ?> +--FILE-- +<?php + +// posotive steps +var_dump(range(2147483400, 2147483600, 100)); +var_dump( range(2147483646, 2147483648, 1 ) ); +var_dump( range(2147483646, 2147483657, 1 ) ); +var_dump( range(2147483630, 2147483646, 5 ) ); + +// negative steps +var_dump( range(-2147483645, -2147483648, 1 ) ); +var_dump( range(-2147483645, -2147483649, 1 ) ); +var_dump( range(-2147483630, -2147483646, 5 ) ); + +// low > high +var_dump(range(2147483647, 2147483645, 1 )); +var_dump(range(2147483648, 2147483645, 1 )); + +?> +--EXPECT-- +array(3) { + [0]=> + int(2147483400) + [1]=> + int(2147483500) + [2]=> + int(2147483600) +} +array(3) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) +} +array(12) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) + [3]=> + float(2147483649) + [4]=> + float(2147483650) + [5]=> + float(2147483651) + [6]=> + float(2147483652) + [7]=> + float(2147483653) + [8]=> + float(2147483654) + [9]=> + float(2147483655) + [10]=> + float(2147483656) + [11]=> + float(2147483657) +} +array(4) { + [0]=> + int(2147483630) + [1]=> + int(2147483635) + [2]=> + int(2147483640) + [3]=> + int(2147483645) +} +array(4) { + [0]=> + float(-2147483645) + [1]=> + float(-2147483646) + [2]=> + float(-2147483647) + [3]=> + float(-2147483648) +} +array(5) { + [0]=> + float(-2147483645) + [1]=> + float(-2147483646) + [2]=> + float(-2147483647) + [3]=> + float(-2147483648) + [4]=> + float(-2147483649) +} +array(4) { + [0]=> + int(-2147483630) + [1]=> + int(-2147483635) + [2]=> + int(-2147483640) + [3]=> + int(-2147483645) +} +array(3) { + [0]=> + int(2147483647) + [1]=> + int(2147483646) + [2]=> + int(2147483645) +} +array(4) { + [0]=> + float(2147483648) + [1]=> + float(2147483647) + [2]=> + float(2147483646) + [3]=> + float(2147483645) +} diff --git a/ext/standard/tests/array/bug41686.phpt b/ext/standard/tests/array/bug41686.phpt new file mode 100644 index 0000000..9f1384e --- /dev/null +++ b/ext/standard/tests/array/bug41686.phpt @@ -0,0 +1,56 @@ +--TEST-- +Bug #41686 (Omitting length param in array_slice not possible) +--FILE-- +<?php +$a = array(1,2,3); +$b = array('a'=>1,'b'=>1,'c'=>2); + +var_dump( + array_slice($a, 1), + array_slice($a, 1, 2, TRUE), + array_slice($a, 1, NULL, TRUE), + array_slice($b, 1), + array_slice($b, 1, 2, TRUE), + array_slice($b, 1, NULL, TRUE) +); + +echo "Done\n"; +?> +--EXPECT-- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + [1]=> + int(2) + [2]=> + int(3) +} +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +array(2) { + ["b"]=> + int(1) + ["c"]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/bug42177.phpt b/ext/standard/tests/array/bug42177.phpt new file mode 100644 index 0000000..5678ca3 --- /dev/null +++ b/ext/standard/tests/array/bug42177.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #42177 (Warning "array_merge_recursive(): recursion detected" comes again...) +--FILE-- +<?php + +$a1 = array( 'key1' => 1, 'key3' => 2 ); +$a2 = array(); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => 1, 'key3' => 2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$a1 = array(); +$a2 = array( 'key1' => &$a1 ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +$x = 'foo'; +$y =& $x; +$a1 = array($x, $y, $x, $y); +$a2 = array( 'key1' => $a1, $x, $y ); +$a1 = array_merge_recursive( $a1, $a2 ); +$a1 = array_merge_recursive( $a1, $a2 ); +unset( $a1, $a2 ); + +?> +--EXPECTF-- +Warning: array_merge_recursive(): recursion detected in %s on line 18 diff --git a/ext/standard/tests/array/bug42233.phpt b/ext/standard/tests/array/bug42233.phpt new file mode 100644 index 0000000..0cebc42 --- /dev/null +++ b/ext/standard/tests/array/bug42233.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #42233 (extract(): scandic characters not allowed as variable name) +--FILE-- +<?php + +$test = array( + 'a' => '1', + 'æ' => '2', + 'æøåäö' => '3', +); + +var_dump($test); +var_dump(extract($test)); +var_dump($a); +var_dump($æ); +var_dump($æøåäö); + +echo "Done.\n"; +?> +--EXPECT-- +array(3) { + ["a"]=> + string(1) "1" + ["æ"]=> + string(1) "2" + ["æøåäö"]=> + string(1) "3" +} +int(3) +string(1) "1" +string(1) "2" +string(1) "3" +Done. diff --git a/ext/standard/tests/array/bug42838.phpt b/ext/standard/tests/array/bug42838.phpt new file mode 100644 index 0000000..5a09ae9 --- /dev/null +++ b/ext/standard/tests/array/bug42838.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #42838 (Wrong results in array_diff_uassoc()) +--FILE-- +<?php + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +$array1 = array("a" => "green", "b" => "Brown", 'c' => 'blue', 0 => 'red'); +$array2 = array("a" => "green", "b" => "Brown", 'c' => 'blue', 0 => 'red'); + +$result = array_diff_uassoc($array1, $array2, "key_compare_func"); +print_r($result); + +?> +--EXPECT-- +Array +( +) diff --git a/ext/standard/tests/array/bug42850.phpt b/ext/standard/tests/array/bug42850.phpt new file mode 100644 index 0000000..3baec83 --- /dev/null +++ b/ext/standard/tests/array/bug42850.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #42850 (array_walk_recursive() leaves references) +--FILE-- +<?php + +// Bug #42850 +$data = array ('key1' => 'val1', array('key2' => 'val2')); +function apply_dumb($item, $key) {}; +var_dump($data); +array_walk_recursive($data, 'apply_dumb'); +$data2 = $data; +$data2[0] = 'altered'; +var_dump($data); +var_dump($data2); + +// Bug #34982 +function myfunc($data) { + array_walk_recursive($data, 'apply_changed'); +} +function apply_changed(&$input, $key) { + $input = 'changed'; +} +myfunc($data); +var_dump($data); + +--EXPECT-- +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + string(7) "altered" +} +array(2) { + ["key1"]=> + string(4) "val1" + [0]=> + array(1) { + ["key2"]=> + string(4) "val2" + } +} diff --git a/ext/standard/tests/array/bug43495.phpt b/ext/standard/tests/array/bug43495.phpt new file mode 100644 index 0000000..8b8f3a6 --- /dev/null +++ b/ext/standard/tests/array/bug43495.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #43495 (array_merge_recursive() crashes with recursive arrays) +--FILE-- +<?php +$a=array("key1"=>array("key2"=>array())); +$a["key1"]["key2"]["key3"]=&$a; + +$b=array("key1"=>array("key2"=>array())); +$b["key1"]["key2"]["key3"]=&$b; + +array_merge_recursive($a,$b); + +/* Break recursion */ +$a["key1"]["key2"]["key3"] = null; +$b["key1"]["key2"]["key3"] = null; + +echo "Done.\n"; +?> +--EXPECTF-- +Warning: array_merge_recursive(): recursion detected in %sbug43495.php on line %d +Done. diff --git a/ext/standard/tests/array/bug43505.phpt b/ext/standard/tests/array/bug43505.phpt new file mode 100644 index 0000000..219bbfe --- /dev/null +++ b/ext/standard/tests/array/bug43505.phpt @@ -0,0 +1,36 @@ +--TEST-- +Bug #43505 (Assign by reference bug) +--INI-- +error_reporting=0 +--SKIPIF-- +<?php if (!extension_loaded('spl')) die("skip SPL is not available"); ?> +--FILE-- +<?php +class Test implements Countable { + public function count() { + return $some; + } +} + +$obj = new Test(); + +$a = array(); +$b =& $a['test']; +var_dump($a); + +$t = count($obj); + +$a = array(); +$b =& $a['test']; +var_dump($a); +?> +--EXPECT-- +array(1) { + ["test"]=> + &NULL +} +array(1) { + ["test"]=> + &NULL +} + diff --git a/ext/standard/tests/array/bug43541.phpt b/ext/standard/tests/array/bug43541.phpt new file mode 100644 index 0000000..847f61a --- /dev/null +++ b/ext/standard/tests/array/bug43541.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #43541 (length parameter omitted or not does not work when casted to float) +--FILE-- +<?php +$arr = array(1, 2, 3, 4, 5, 6); + +var_dump(array_slice($arr, 0, (float)2)); +var_dump(array_slice($arr, 0, (int)2)); +?> +--EXPECT-- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} diff --git a/ext/standard/tests/array/bug44181.phpt b/ext/standard/tests/array/bug44181.phpt new file mode 100644 index 0000000..3da73cb --- /dev/null +++ b/ext/standard/tests/array/bug44181.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #44181 (extract EXTR_OVERWRITE|EXTR_REFS can fail to create references) +--FILE-- +<?php +$a = array('foo' => 'original.foo'); + +$foo = 'test'; +$ref = &$a; + +extract($a, EXTR_OVERWRITE|EXTR_REFS); +$foo = 'changed.foo'; + +var_dump($a['foo']); +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "changed.foo" +Done + diff --git a/ext/standard/tests/array/bug44182.phpt b/ext/standard/tests/array/bug44182.phpt new file mode 100644 index 0000000..47f3caa --- /dev/null +++ b/ext/standard/tests/array/bug44182.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #44182 (extract EXTR_REFS can fail to split copy-on-write references) +--FILE-- +<?php +$a = array('foo' => 'original.foo'); + +$nonref = $a['foo']; +$ref = &$a; + +extract($a, EXTR_REFS); +$a['foo'] = 'changed.foo'; + +var_dump($nonref); +echo "Done\n"; +?> +--EXPECTF-- +string(%d) "original.foo" +Done + diff --git a/ext/standard/tests/array/bug44929.phpt b/ext/standard/tests/array/bug44929.phpt new file mode 100644 index 0000000..9dc85ac --- /dev/null +++ b/ext/standard/tests/array/bug44929.phpt @@ -0,0 +1,35 @@ +--TEST-- +Bug #44929 (natsort doesn't handle leading zeros well) +--FILE-- +<?php +$a = array(b'001',b'008',b'005',b'00011',b'03',b'000014',b'-123',b'0.002',b'00',b'0',b'0_0',b'0-0'); +natsort($a); +var_dump($a); +?> +--EXPECT-- +array(12) { + [6]=> + string(4) "-123" + [8]=> + string(2) "00" + [9]=> + string(1) "0" + [11]=> + string(3) "0-0" + [7]=> + string(5) "0.002" + [10]=> + string(3) "0_0" + [0]=> + string(3) "001" + [4]=> + string(2) "03" + [2]=> + string(3) "005" + [1]=> + string(3) "008" + [3]=> + string(5) "00011" + [5]=> + string(6) "000014" +} diff --git a/ext/standard/tests/array/bug45312.phpt b/ext/standard/tests/array/bug45312.phpt new file mode 100644 index 0000000..017defe --- /dev/null +++ b/ext/standard/tests/array/bug45312.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #45312 (Segmentation fault on second request for array functions) +--FILE-- +<?php +class cr { + private $priv_member; + function cr($val) { + $this->priv_member = $val; + } + static function comp_func_cr($a, $b) { + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member > $b->priv_member) ? 1 : -1; + } + static function comp_func_cr2($a, $b) { + echo "."; + if ($a->priv_member === $b->priv_member) return 0; + return ($a->priv_member < $b->priv_member) ? 1 : -1; + } + function dump() { + echo $this->priv_member . "\n"; + } +} +$a = array("0.1" => new cr(9), "0.5" => new cr(12), 0 => new cr(23), 1 => new cr(4), 2 => new cr(-15),); +$b = array("0.2" => new cr(9), "0.5" => new cr(22), 0 => new cr(3), 1 => new cr(4), 2 => new cr(-15),); +$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr")); +foreach($result as $val) { + $val->dump(); +} +$result = array_udiff_assoc($a, $b, array("cr", "comp_func_cr2")); +foreach($result as $val) { + $val->dump(); +} +?> +--EXPECT-- +9 +12 +23 +....9 +12 +23 diff --git a/ext/standard/tests/array/bug46873.phpt b/ext/standard/tests/array/bug46873.phpt new file mode 100644 index 0000000..1f11c9d --- /dev/null +++ b/ext/standard/tests/array/bug46873.phpt @@ -0,0 +1,12 @@ +--TEST-- +Bug #46873 (extract($foo) crashes if $foo['foo'] exists) +--FILE-- +<?php +$foo = array('foo' => 1, 'bar' => 2, 'test' => 3); +extract($foo); +var_dump($foo, $bar, $test); +?> +--EXPECT-- +int(1) +int(2) +int(3) diff --git a/ext/standard/tests/array/bug48224.phpt b/ext/standard/tests/array/bug48224.phpt new file mode 100644 index 0000000..5b46e18 --- /dev/null +++ b/ext/standard/tests/array/bug48224.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #48224 (array_rand no longer shuffles) +--FILE-- +<?php +$a = range(0, 100); +$a1 = array_rand($a, count($a)); +$a2 = array_rand($a, count($a)); +$a3 = array_rand($a, count($a)); +$a4 = array_rand($a, count($a)); + +var_dump($a1 === $a2 && $a1 === $a3 && $a1 === $a4); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/array/bug48484.phpt b/ext/standard/tests/array/bug48484.phpt new file mode 100644 index 0000000..0b4afe2 --- /dev/null +++ b/ext/standard/tests/array/bug48484.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug 48484 (array_product() always returns 0 for an empty array) +--FILE-- +<?php +var_dump(array_product(array())); +?> +--EXPECT-- +int(1) diff --git a/ext/standard/tests/array/bug48854.phpt b/ext/standard/tests/array/bug48854.phpt new file mode 100644 index 0000000..0908637 --- /dev/null +++ b/ext/standard/tests/array/bug48854.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #48854 (array_merge_recursive modifies arrays after first one) +--FILE-- +<?php + +$array1 = array( + 'friends' => 5, + 'children' => array( + 'dogs' => 0, + ), +); + +$array2 = array( + 'friends' => 10, + 'children' => array( + 'cats' => 5, + ), +); + +$merged = array_merge_recursive($array1, $array2); + +var_dump($array1, $array2); + +?> +--EXPECTF-- +array(2) { + [%u|b%"friends"]=> + int(5) + [%u|b%"children"]=> + array(1) { + [%u|b%"dogs"]=> + int(0) + } +} +array(2) { + [%u|b%"friends"]=> + int(10) + [%u|b%"children"]=> + array(1) { + [%u|b%"cats"]=> + int(5) + } +} diff --git a/ext/standard/tests/array/bug50006.phpt b/ext/standard/tests/array/bug50006.phpt new file mode 100644 index 0000000..f03a002 --- /dev/null +++ b/ext/standard/tests/array/bug50006.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #50006 (Segfault caused by uksort()) +--FILE-- +<?php + +$data = array( + 'bar-bazbazbaz.' => 0, + 'bar-bazbazbaz-' => 0, + 'foo' => 0, +); +uksort($data, 'magic_sort_cmp'); +print_r($data); + +function magic_sort_cmp($a, $b) { + $a = substr($a, 1); + $b = substr($b, 1); + if (!$a) return $b ? -1 : 0; + if (!$b) return 1; + return magic_sort_cmp($a, $b); +} + +?> +--EXPECTF-- +Array +( + [foo] => 0 + [bar-bazbazbaz-] => 0 + [bar-bazbazbaz.] => 0 +) diff --git a/ext/standard/tests/array/bug50006_1.phpt b/ext/standard/tests/array/bug50006_1.phpt new file mode 100644 index 0000000..fbb7ddd --- /dev/null +++ b/ext/standard/tests/array/bug50006_1.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #50006 (Segfault caused by uksort()) - usort variant +--FILE-- +<?php + +$data = array( + 'bar-bazbazbaz.', + 'bar-bazbazbaz-', + 'foo' +); +usort($data, 'magic_sort_cmp'); +print_r($data); + +function magic_sort_cmp($a, $b) { + $a = substr($a, 1); + $b = substr($b, 1); + if (!$a) return $b ? -1 : 0; + if (!$b) return 1; + return magic_sort_cmp($a, $b); +} + +?> +--EXPECTF-- +Array +( + [0] => foo + [1] => bar-bazbazbaz- + [2] => bar-bazbazbaz. +) diff --git a/ext/standard/tests/array/bug50006_2.phpt b/ext/standard/tests/array/bug50006_2.phpt new file mode 100644 index 0000000..19c0d14 --- /dev/null +++ b/ext/standard/tests/array/bug50006_2.phpt @@ -0,0 +1,29 @@ +--TEST-- +Bug #50006 (Segfault caused by uksort()) - uasort variant +--FILE-- +<?php + +$data = array( + 'bar-bazbazbaz.', + 'bar-bazbazbaz-', + 'foo' +); +uasort($data, 'magic_sort_cmp'); +print_r($data); + +function magic_sort_cmp($a, $b) { + $a = substr($a, 1); + $b = substr($b, 1); + if (!$a) return $b ? -1 : 0; + if (!$b) return 1; + return magic_sort_cmp($a, $b); +} + +?> +--EXPECTF-- +Array +( + [2] => foo + [1] => bar-bazbazbaz- + [0] => bar-bazbazbaz. +) diff --git a/ext/standard/tests/array/bug51552.phpt b/ext/standard/tests/array/bug51552.phpt new file mode 100644 index 0000000..fb61f48 --- /dev/null +++ b/ext/standard/tests/array/bug51552.phpt @@ -0,0 +1,23 @@ +--TEST-- +Bug #51552 (debug_backtrace() causes segmentation fault and/or memory issues) +--FILE-- +<?php +function walk($element, $key, $p) { + $backtrace = debug_backtrace(); + echo "$element\n"; +} + +$a = array(1,2,3,4,5,6,7,8,9,10); +array_walk($a, 'walk', 'testthis'); +?> +--EXPECT-- +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/ext/standard/tests/array/bug52534.phpt b/ext/standard/tests/array/bug52534.phpt new file mode 100644 index 0000000..dfff3fd --- /dev/null +++ b/ext/standard/tests/array/bug52534.phpt @@ -0,0 +1,14 @@ +--TEST-- +Bug #52534 (var_export array with negative key) +--FILE-- +<?php + +$aArray = array ( -1 => 'Hello'); + +var_export($aArray); + +?> +--EXPECT-- +array ( + -1 => 'Hello', +) diff --git a/ext/standard/tests/array/bug52719.phpt b/ext/standard/tests/array/bug52719.phpt new file mode 100644 index 0000000..078c53d --- /dev/null +++ b/ext/standard/tests/array/bug52719.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #52719: array_walk_recursive crashes if third param of the function is by reference +--FILE-- +<?php +$array = array("hello", array("world")); +$userdata = array(); +array_walk_recursive( + $array, + function ($value, $key, &$userdata) { }, + $userdata +); +echo "Done"; +?> +--EXPECTF-- +Done diff --git a/ext/standard/tests/array/bug54459.phpt b/ext/standard/tests/array/bug54459.phpt new file mode 100644 index 0000000..e46cfcb --- /dev/null +++ b/ext/standard/tests/array/bug54459.phpt @@ -0,0 +1,215 @@ +--TEST-- +Bug #54459 (Range function accuracy) +--INI-- +precision=14 +--FILE-- +<?php +foreach (range(90, 100, .1) as $i => $v){ + echo $i, ' = ', $v, PHP_EOL; +} +foreach (range("90", "100", .1) as $i => $v){ + echo $i, ' = ', $v, PHP_EOL; +} +--EXPECT-- +0 = 90 +1 = 90.1 +2 = 90.2 +3 = 90.3 +4 = 90.4 +5 = 90.5 +6 = 90.6 +7 = 90.7 +8 = 90.8 +9 = 90.9 +10 = 91 +11 = 91.1 +12 = 91.2 +13 = 91.3 +14 = 91.4 +15 = 91.5 +16 = 91.6 +17 = 91.7 +18 = 91.8 +19 = 91.9 +20 = 92 +21 = 92.1 +22 = 92.2 +23 = 92.3 +24 = 92.4 +25 = 92.5 +26 = 92.6 +27 = 92.7 +28 = 92.8 +29 = 92.9 +30 = 93 +31 = 93.1 +32 = 93.2 +33 = 93.3 +34 = 93.4 +35 = 93.5 +36 = 93.6 +37 = 93.7 +38 = 93.8 +39 = 93.9 +40 = 94 +41 = 94.1 +42 = 94.2 +43 = 94.3 +44 = 94.4 +45 = 94.5 +46 = 94.6 +47 = 94.7 +48 = 94.8 +49 = 94.9 +50 = 95 +51 = 95.1 +52 = 95.2 +53 = 95.3 +54 = 95.4 +55 = 95.5 +56 = 95.6 +57 = 95.7 +58 = 95.8 +59 = 95.9 +60 = 96 +61 = 96.1 +62 = 96.2 +63 = 96.3 +64 = 96.4 +65 = 96.5 +66 = 96.6 +67 = 96.7 +68 = 96.8 +69 = 96.9 +70 = 97 +71 = 97.1 +72 = 97.2 +73 = 97.3 +74 = 97.4 +75 = 97.5 +76 = 97.6 +77 = 97.7 +78 = 97.8 +79 = 97.9 +80 = 98 +81 = 98.1 +82 = 98.2 +83 = 98.3 +84 = 98.4 +85 = 98.5 +86 = 98.6 +87 = 98.7 +88 = 98.8 +89 = 98.9 +90 = 99 +91 = 99.1 +92 = 99.2 +93 = 99.3 +94 = 99.4 +95 = 99.5 +96 = 99.6 +97 = 99.7 +98 = 99.8 +99 = 99.9 +100 = 100 +0 = 90 +1 = 90.1 +2 = 90.2 +3 = 90.3 +4 = 90.4 +5 = 90.5 +6 = 90.6 +7 = 90.7 +8 = 90.8 +9 = 90.9 +10 = 91 +11 = 91.1 +12 = 91.2 +13 = 91.3 +14 = 91.4 +15 = 91.5 +16 = 91.6 +17 = 91.7 +18 = 91.8 +19 = 91.9 +20 = 92 +21 = 92.1 +22 = 92.2 +23 = 92.3 +24 = 92.4 +25 = 92.5 +26 = 92.6 +27 = 92.7 +28 = 92.8 +29 = 92.9 +30 = 93 +31 = 93.1 +32 = 93.2 +33 = 93.3 +34 = 93.4 +35 = 93.5 +36 = 93.6 +37 = 93.7 +38 = 93.8 +39 = 93.9 +40 = 94 +41 = 94.1 +42 = 94.2 +43 = 94.3 +44 = 94.4 +45 = 94.5 +46 = 94.6 +47 = 94.7 +48 = 94.8 +49 = 94.9 +50 = 95 +51 = 95.1 +52 = 95.2 +53 = 95.3 +54 = 95.4 +55 = 95.5 +56 = 95.6 +57 = 95.7 +58 = 95.8 +59 = 95.9 +60 = 96 +61 = 96.1 +62 = 96.2 +63 = 96.3 +64 = 96.4 +65 = 96.5 +66 = 96.6 +67 = 96.7 +68 = 96.8 +69 = 96.9 +70 = 97 +71 = 97.1 +72 = 97.2 +73 = 97.3 +74 = 97.4 +75 = 97.5 +76 = 97.6 +77 = 97.7 +78 = 97.8 +79 = 97.9 +80 = 98 +81 = 98.1 +82 = 98.2 +83 = 98.3 +84 = 98.4 +85 = 98.5 +86 = 98.6 +87 = 98.7 +88 = 98.8 +89 = 98.9 +90 = 99 +91 = 99.1 +92 = 99.2 +93 = 99.3 +94 = 99.4 +95 = 99.5 +96 = 99.6 +97 = 99.7 +98 = 99.8 +99 = 99.9 +100 = 100 diff --git a/ext/standard/tests/array/bug61058.phpt b/ext/standard/tests/array/bug61058.phpt new file mode 100644 index 0000000..1f0f6fe --- /dev/null +++ b/ext/standard/tests/array/bug61058.phpt @@ -0,0 +1,8 @@ +--TEST-- +Bug #61058 (array_fill leaks if start index is PHP_INT_MAX) +--FILE-- +<?php +array_fill(PHP_INT_MAX, 2, '*'); +?> +--EXPECTF-- +Warning: array_fill(): Cannot add element to the array as the next element is already occupied in %sbug61058.php on line %d diff --git a/ext/standard/tests/array/bug61730.phpt b/ext/standard/tests/array/bug61730.phpt new file mode 100644 index 0000000..0fe9f22 --- /dev/null +++ b/ext/standard/tests/array/bug61730.phpt @@ -0,0 +1,37 @@ +--TEST-- +Bug #61730 (Segfault from array_walk modifying an array passed by reference) +--FILE-- +<?php +$myArray = array_fill(0, 10, 1); + +array_walk( + $myArray, + function($value, $key) use ($myArray) + { + reset($myArray); + } +); + +array_walk( + $myArray, + function($value, $key) use (&$myArray) + { + var_dump($key); + unset($myArray[$key]); + unset($myArray[$key+1]); + unset($myArray[$key+2]); + } +); + + + +print_r($myArray); +--EXPECT-- +int(0) +int(4) +int(8) +Array +( + [3] => 1 + [7] => 1 +) diff --git a/ext/standard/tests/array/compact.phpt b/ext/standard/tests/array/compact.phpt new file mode 100644 index 0000000..4b4bfbb --- /dev/null +++ b/ext/standard/tests/array/compact.phpt @@ -0,0 +1,24 @@ +--TEST-- +compact() +--INI-- +unicode.script_encoding=UTF-8 +unicode.output_encoding=UTF-8 +--FILE-- +<?php + +$çity = "San Francisco"; +$state = "CA"; +$event = "SIGGRAPH"; + +$location_vars = array("c\u0327ity", "state"); + +$result = compact("event", $location_vars); +var_dump($result); +?> +--EXPECT-- +array(2) { + ["event"]=> + string(8) "SIGGRAPH" + ["state"]=> + string(2) "CA" +} diff --git a/ext/standard/tests/array/compact_basic.phpt b/ext/standard/tests/array/compact_basic.phpt new file mode 100644 index 0000000..53a946e --- /dev/null +++ b/ext/standard/tests/array/compact_basic.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test compact() function : basic functionality +--FILE-- +<?php +/* Prototype : proto array compact(mixed var_names [, mixed ...]) + * Description: Creates a hash containing variables and their values + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* + * Test basic functionality + */ + +echo "*** Testing compact() : basic functionality ***\n"; + +$a=1; +$b=0.2; +$c=true; +$d=array("key"=>"val"); +$e=NULL; +$f="string"; + +// simple array test +var_dump (compact(array("a", "b", "c", "d", "e", "f"))); +// simple parameter test +var_dump (compact("a", "b", "c", "d", "e", "f")); +var_dump (compact(array("keyval"=>"a", "b"=>"b", "c"=>1))); + +// cases which should not yield any output. +var_dump (compact(array(10, 0.3, true, array(20), NULL))); +var_dump (compact(10, 0.3, true, array(20), NULL)); +var_dump (compact(array("g"))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing compact() : basic functionality *** +array(6) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) + ["c"]=> + bool(true) + ["d"]=> + array(1) { + ["key"]=> + string(3) "val" + } + ["e"]=> + NULL + ["f"]=> + string(6) "string" +} +array(6) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) + ["c"]=> + bool(true) + ["d"]=> + array(1) { + ["key"]=> + string(3) "val" + } + ["e"]=> + NULL + ["f"]=> + string(6) "string" +} +array(2) { + ["a"]=> + int(1) + ["b"]=> + float(0.2) +} +array(0) { +} +array(0) { +} +array(0) { +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/compact_error.phpt b/ext/standard/tests/array/compact_error.phpt new file mode 100644 index 0000000..a7ef545 --- /dev/null +++ b/ext/standard/tests/array/compact_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test compact() function : error conditions +--FILE-- +<?php +/* Prototype : proto array compact(mixed var_names [, mixed ...]) + * Description: Creates a hash containing variables and their values + * Source code: ext/standard/array.c + * Alias to functions: + */ + +/* + * Error -tests test compact with zero arguments. + */ + +echo "*** Testing compact() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing compact() function with Zero arguments --\n"; +var_dump( compact() ); + + +echo "Done"; +?> +--EXPECTF-- +*** Testing compact() : error conditions *** + +-- Testing compact() function with Zero arguments -- + +Warning: compact() expects at least 1 parameter, 0 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/compact_variation1.phpt b/ext/standard/tests/array/compact_variation1.phpt new file mode 100644 index 0000000..ea48132 --- /dev/null +++ b/ext/standard/tests/array/compact_variation1.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test compact() function : usage variations - arrays containing references. +--FILE-- +<?php +/* Prototype : proto array compact(mixed var_names [, mixed ...]) +* Description: Creates a hash containing variables and their values +* Source code: ext/standard/array.c +* Alias to functions: +*/ +/* +* compact variations - arrays with references +*/ +echo "*** Testing compact() : usage variations - arrays containg references ***\n"; +$a = 1; +$b = 2; +$c = 3; +$string = "c"; +$arr1 = array("a", &$arr1); +$arr2 = array("a", array(array(array("b")))); +$arr2[1][0][0][] = &$arr2; +$arr2[1][0][0][] = &$arr2[1]; +$arr3 = array(&$string); +var_dump(compact($arr1)); +var_dump(compact($arr2)); +var_dump(compact($arr3)); +echo "Done"; +?> +--EXPECTF-- +*** Testing compact() : usage variations - arrays containg references *** + +Warning: compact(): recursion detected in %s on line %d +array(1) { + ["a"]=> + int(1) +} + +Warning: compact(): recursion detected in %s on line %d + +Warning: compact(): recursion detected in %s on line %d + +Warning: compact(): recursion detected in %s on line %d + +Warning: compact(): recursion detected in %s on line %d +array(2) { + ["a"]=> + int(1) + ["b"]=> + int(2) +} +array(1) { + ["c"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/compact_variation2.phpt b/ext/standard/tests/array/compact_variation2.phpt new file mode 100644 index 0000000..79db8ab --- /dev/null +++ b/ext/standard/tests/array/compact_variation2.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test compact() function: ensure compact() doesn't pick up variables declared outside of current scope. +--FILE-- +<?php +/* Prototype : proto array compact(mixed var_names [, mixed ...]) +* Description: Creates a hash containing variables and their values +* Source code: ext/standard/array.c +* Alias to functions: +*/ +echo "*** Testing compact() : usage variations - variables outside of current scope ***\n"; + +$a = 'main.a'; +$b = 'main.b'; + +function f() { + $b = 'f.b'; + $c = 'f.c'; + var_dump(compact('a','b','c')); + var_dump(compact(array('a','b','c'))); +} + +f(); + +?> +==Done== +--EXPECTF-- +*** Testing compact() : usage variations - variables outside of current scope *** +array(2) { + ["b"]=> + string(3) "f.b" + ["c"]=> + string(3) "f.c" +} +array(2) { + ["b"]=> + string(3) "f.b" + ["c"]=> + string(3) "f.c" +} +==Done==
\ No newline at end of file diff --git a/ext/standard/tests/array/compare_function.inc b/ext/standard/tests/array/compare_function.inc new file mode 100644 index 0000000..e517680 --- /dev/null +++ b/ext/standard/tests/array/compare_function.inc @@ -0,0 +1,13 @@ +<?php + +function compare_function($var1, $var2) { + if ($var1 == $var2) { + return 0; + } else if ($var1 < $var2) { + return -1; + } else { + return 1; + } +} + +?>
\ No newline at end of file diff --git a/ext/standard/tests/array/count_basic.phpt b/ext/standard/tests/array/count_basic.phpt new file mode 100644 index 0000000..45f63d6 --- /dev/null +++ b/ext/standard/tests/array/count_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test count() function : basic functionality +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of count() using an array as $var argument + * and different values as $mode argument. + */ + +echo "*** Testing count() : basic functionality ***\n"; + +echo "\n-- One Dimensional Array: --\n"; +$array = array('zero', 'one', 'two'); +var_dump(count($array)); + +echo "\n-- Two Dimensional Array: --\n"; +$array_multi = array('zero', array(1, 2, 3), 'two'); +echo "\$mode = COUNT_NORMAL: "; +var_dump(count($array_multi, COUNT_NORMAL)); +echo "\$mode = 0: "; +var_dump(count($array_multi, 0)); +echo "\$mode = COUNT_RECURSIVE: "; +var_dump(count($array_multi, COUNT_RECURSIVE)); +echo "\$mode = 1: "; +var_dump(count($array_multi, 1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : basic functionality *** + +-- One Dimensional Array: -- +int(3) + +-- Two Dimensional Array: -- +$mode = COUNT_NORMAL: int(3) +$mode = 0: int(3) +$mode = COUNT_RECURSIVE: int(6) +$mode = 1: int(6) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_error.phpt b/ext/standard/tests/array/count_error.phpt new file mode 100644 index 0000000..76f7213 --- /dev/null +++ b/ext/standard/tests/array/count_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test count() function : error conditions - pass incorrect number of args +--FILE-- +<?php +/* Prototype : int count(mixed var [, int mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to count() to test behaviour + */ + +echo "*** Testing count() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing count() function with Zero arguments --\n"; +var_dump( count() ); + +//Test count with one more than the expected number of arguments +echo "\n-- Testing count() function with more than expected no. of arguments --\n"; +$var = 1; +$mode = 10; +$extra_arg = 10; +var_dump( count($var, $mode, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : error conditions *** + +-- Testing count() function with Zero arguments -- + +Warning: count() expects at least 1 parameter, 0 given in %s on line %d +NULL + +-- Testing count() function with more than expected no. of arguments -- + +Warning: count() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_recursive.phpt b/ext/standard/tests/array/count_recursive.phpt new file mode 100644 index 0000000..0f6a1d9 --- /dev/null +++ b/ext/standard/tests/array/count_recursive.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test count() function +--SKIPIF-- +<?php if (!extension_loaded("spl")) die("skip no SPL extension"); ?> +--FILE-- +<?php +/* Prototype: int count ( mixed $var [, int $mode] ); + Discription: Count elements in an array, or properties in an object +*/ + +echo "*** Testing basic functionality of count() function ***\n"; +print "-- Testing NULL --\n"; +$arr = NULL; +print "COUNT_NORMAL: should be 0, is ".count($arr, COUNT_NORMAL)."\n"; +print "COUNT_RECURSIVE: should be 0, is ".count($arr, COUNT_RECURSIVE)."\n"; + +print "-- Testing arrays --\n"; +$arr = array(1, array(3, 4, array(6, array(8)))); +print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n"; +print "COUNT_RECURSIVE: should be 8, is ".count($arr, COUNT_RECURSIVE)."\n"; + +print "-- Testing hashes --\n"; +$arr = array("a" => 1, "b" => 2, array("c" => 3, array("d" => 5))); +print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n"; +print "COUNT_RECURSIVE: should be 6, is ".count($arr, COUNT_RECURSIVE)."\n"; + +print "-- Testing strings --\n"; +print "COUNT_NORMAL: should be 1, is ".count("string", COUNT_NORMAL)."\n"; +print "COUNT_RECURSIVE: should be 1, is ".count("string", COUNT_RECURSIVE)."\n"; + +print "-- Testing various types with no second argument --\n"; +print "COUNT_NORMAL: should be 1, is ".count("string")."\n"; +print "COUNT_NORMAL: should be 2, is ".count(array("a", array("b")))."\n"; + +$arr = array('a'=>array(NULL, NULL, NULL), 1=>array(NULL=>1, 1=>NULL), + array(array(array(array(array(NULL)))))); +print "-- Testing really cool arrays --\n"; +print "COUNT_NORMAL: should be 3, is ".count($arr, COUNT_NORMAL)."\n"; +print "COUNT_RECURSIVE: should be 13, is ".count($arr, COUNT_RECURSIVE)."\n"; + +echo "\n*** Testing possible variations of count() function on arrays ***"; +$count_array = array( + array(), + array( 1 => "string"), + array( "" => "string", 0 => "a", NULL => "b", -1.00 => "c", + array(array(array(NULL)))), + array( -2.44444 => 12, array(array(1, 2, array(array("0"))))), + array( "a" => 1, "b" => -2.344, "b" => "string", "c" => NULL, "d" => -2.344), + array( 4 => 1, 3 => -2.344, "3" => "string", "2" => NULL, + 1 => -2.344, array()), + array( TRUE => TRUE, FALSE => FALSE, "" => "", " " => " ", + NULL => NULL, "\x000" => "\x000", "\000" => "\000"), + array( NULL, 1.23 => "Hi", "string" => "hello", + array("" => "World", "-2.34" => "a", "0" => "b")) +); + +$i = 0; +foreach ($count_array as $count_value) { + echo "\n-- Iteration $i --\n"; + print "COUNT_NORMAL is ".count($count_value, COUNT_NORMAL)."\n"; + print "COUNT_RECURSIVE is ".count($count_value, COUNT_RECURSIVE)."\n"; + $i++; +} + + +/* Testing count() by passing constant with no second argument */ +print "\n-- Testing count() on constants with no second argument --\n"; +print "COUNT_NORMAL: should be 1, is ".count(100)."\n"; +print "COUNT_NORMAL: should be 1, is ".count(-23.45)."\n"; + +print "\n-- Testing count() on NULL and Unset variables --\n"; +print "COUNT_NORMAL: should be 0, is ".count(NULL)."\n"; +print "COUNT_NORMAL: should be 1, is ".count("")."\n"; +print "COUNT_NORMAL: should be 0, is ".@count($a)."\n"; + + +print "\n-- Testing count() on an empty sub-array --\n"; +$arr = array(1, array(3, 4, array())); +print "COUNT_NORMAL: should be 2, is ".count($arr, COUNT_NORMAL)."\n"; +print "COUNT_RECURSIVE: should be 5, is ".count($arr, COUNT_RECURSIVE)."\n"; + +echo "\n-- Testing count() on objects with Countable interface --\n"; +class count_class implements Countable { + private $var_private; + public $var_public; + protected $var_protected; + + public function count() { + return 3; + } +} + +$obj = new count_class(); +print "COUNT_NORMAL: should be 3, is ".count($obj)."\n"; + + +echo "\n-- Testing count() on resource type --\n"; +$resource1 = fopen( __FILE__, "r" ); // Creating file(stream type) resource +$resource2 = opendir( "." ); // Creating dir resource + +/* creating an array with resources as elements */ +$arr_resource = array("a" => $resource1, "b" => $resource2); +var_dump(count($arr_resource)); + +echo "\n-- Testing count() on arrays containing references --\n"; +$arr = array(1, array("a", "b", "c")); +$arr[2] = &$arr[1]; + +$mode_arr = array( COUNT_NORMAL, COUNT_RECURSIVE, 0, 1, -1, -1.45, 2, TRUE, + FALSE, NULL); +for( $i =0; $i < count( $mode_arr ); $i++) { + echo "For mode '$mode_arr[$i]' count is => "; + var_dump(count($arr, $mode_arr[$i])); +} + + +echo "\n-- Testing error conditions --"; +var_dump( count() ); // No. of args = 0 +var_dump( count(array(), COUNT_NORMAL, 100) ); // No. of args > expected + +/* Testing Invalid type arguments */ +var_dump( count("string", ABCD) ); +var_dump( count(100, "string") ); +var_dump( count(array(), "") ); + +echo "\nDone"; + +/* closing the resource handles */ +fclose( $resource1 ); +closedir( $resource2 ); +?> +--EXPECTF-- +*** Testing basic functionality of count() function *** +-- Testing NULL -- +COUNT_NORMAL: should be 0, is 0 +COUNT_RECURSIVE: should be 0, is 0 +-- Testing arrays -- +COUNT_NORMAL: should be 2, is 2 +COUNT_RECURSIVE: should be 8, is 8 +-- Testing hashes -- +COUNT_NORMAL: should be 3, is 3 +COUNT_RECURSIVE: should be 6, is 6 +-- Testing strings -- +COUNT_NORMAL: should be 1, is 1 +COUNT_RECURSIVE: should be 1, is 1 +-- Testing various types with no second argument -- +COUNT_NORMAL: should be 1, is 1 +COUNT_NORMAL: should be 2, is 2 +-- Testing really cool arrays -- +COUNT_NORMAL: should be 3, is 3 +COUNT_RECURSIVE: should be 13, is 13 + +*** Testing possible variations of count() function on arrays *** +-- Iteration 0 -- +COUNT_NORMAL is 0 +COUNT_RECURSIVE is 0 + +-- Iteration 1 -- +COUNT_NORMAL is 1 +COUNT_RECURSIVE is 1 + +-- Iteration 2 -- +COUNT_NORMAL is 4 +COUNT_RECURSIVE is 7 + +-- Iteration 3 -- +COUNT_NORMAL is 2 +COUNT_RECURSIVE is 8 + +-- Iteration 4 -- +COUNT_NORMAL is 4 +COUNT_RECURSIVE is 4 + +-- Iteration 5 -- +COUNT_NORMAL is 5 +COUNT_RECURSIVE is 5 + +-- Iteration 6 -- +COUNT_NORMAL is 6 +COUNT_RECURSIVE is 6 + +-- Iteration 7 -- +COUNT_NORMAL is 4 +COUNT_RECURSIVE is 7 + +-- Testing count() on constants with no second argument -- +COUNT_NORMAL: should be 1, is 1 +COUNT_NORMAL: should be 1, is 1 + +-- Testing count() on NULL and Unset variables -- +COUNT_NORMAL: should be 0, is 0 +COUNT_NORMAL: should be 1, is 1 +COUNT_NORMAL: should be 0, is 0 + +-- Testing count() on an empty sub-array -- +COUNT_NORMAL: should be 2, is 2 +COUNT_RECURSIVE: should be 5, is 5 + +-- Testing count() on objects with Countable interface -- +COUNT_NORMAL: should be 3, is 3 + +-- Testing count() on resource type -- +int(2) + +-- Testing count() on arrays containing references -- +For mode '0' count is => int(3) +For mode '1' count is => int(9) +For mode '0' count is => int(3) +For mode '1' count is => int(9) +For mode '-1' count is => int(3) +For mode '-1.45' count is => int(3) +For mode '2' count is => int(3) +For mode '1' count is => int(9) +For mode '' count is => int(3) +For mode '' count is => int(3) + +-- Testing error conditions -- +Warning: count() expects at least 1 parameter, 0 given in %s on line %d +NULL + +Warning: count() expects at most 2 parameters, 3 given in %s on line %d +NULL + +Notice: Use of undefined constant ABCD - assumed 'ABCD' in %s on line %d + +Warning: count() expects parameter 2 to be long, %s given in %s on line %d +NULL + +Warning: count() expects parameter 2 to be long, %s given in %s on line %d +NULL + +Warning: count() expects parameter 2 to be long, %s given in %s on line %d +NULL + +Done diff --git a/ext/standard/tests/array/count_variation1.phpt b/ext/standard/tests/array/count_variation1.phpt new file mode 100644 index 0000000..b40a2ab --- /dev/null +++ b/ext/standard/tests/array/count_variation1.phpt @@ -0,0 +1,170 @@ +--TEST-- +Test count() function : usage variations - Pass different data types as $var arg +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * aPass different data types as $var argument to count() to test behaviour + */ + +echo "*** Testing count() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $var argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of count() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( count($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : usage variations *** + +-- Iteration 1 -- +int(1) + +-- Iteration 2 -- +int(1) + +-- Iteration 3 -- +int(1) + +-- Iteration 4 -- +int(1) + +-- Iteration 5 -- +int(1) + +-- Iteration 6 -- +int(1) + +-- Iteration 7 -- +int(1) + +-- Iteration 8 -- +int(1) + +-- Iteration 9 -- +int(1) + +-- Iteration 10 -- +int(0) + +-- Iteration 11 -- +int(0) + +-- Iteration 12 -- +int(1) + +-- Iteration 13 -- +int(1) + +-- Iteration 14 -- +int(1) + +-- Iteration 15 -- +int(1) + +-- Iteration 16 -- +int(1) + +-- Iteration 17 -- +int(1) + +-- Iteration 18 -- +int(1) + +-- Iteration 19 -- +int(1) + +-- Iteration 20 -- +int(1) + +-- Iteration 21 -- +int(1) + +-- Iteration 22 -- +int(0) + +-- Iteration 23 -- +int(0) + +-- Iteration 24 -- +int(1) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_variation2.phpt b/ext/standard/tests/array/count_variation2.phpt new file mode 100644 index 0000000..86aecc0 --- /dev/null +++ b/ext/standard/tests/array/count_variation2.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test count() function : usage variations - Pass different data types as $mode arg +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $mode argument to count() to test behaviour + */ + +echo "*** Testing count() : usage variations ***\n"; + +// Initialise function arguments not being substituted +$var = array(1, 2, array ('one', 'two')); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $mode argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of count() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( count($var, $input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : usage variations *** + +-- Iteration 1 -- +int(3) + +-- Iteration 2 -- +int(5) + +-- Iteration 3 -- +int(3) + +-- Iteration 4 -- +int(3) + +-- Iteration 5 -- +int(3) + +-- Iteration 6 -- +int(3) + +-- Iteration 7 -- +int(3) + +-- Iteration 8 -- +int(3) + +-- Iteration 9 -- +int(3) + +-- Iteration 10 -- +int(3) + +-- Iteration 11 -- +int(3) + +-- Iteration 12 -- +int(5) + +-- Iteration 13 -- +int(3) + +-- Iteration 14 -- +int(5) + +-- Iteration 15 -- +int(3) + +-- Iteration 16 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: count() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: count() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 22 -- +int(3) + +-- Iteration 23 -- +int(3) + +-- Iteration 24 -- + +Warning: count() expects parameter 2 to be long, resource given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/count_variation3.phpt b/ext/standard/tests/array/count_variation3.phpt new file mode 100644 index 0000000..e11b4c2 --- /dev/null +++ b/ext/standard/tests/array/count_variation3.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test count() function : usage variations - Infinitely recursive array +--FILE-- +<?php +/* Prototype : int count(mixed $var [, int $mode]) + * Description: Count the number of elements in a variable (usually an array) + * Source code: ext/standard/array.c + */ + +/* + * Pass count() an infinitely recursive array as $var argument + * This will stop the script before it reaches the end. + */ + +echo "*** Testing count() : usage variations ***\n"; + +$array1 = array (1, 2, 'three'); +// get an infinitely recursive array +$array1[] = &$array1; + +echo "\n-- \$mode not set: --\n"; +var_dump(count ($array1)); + +echo "\n-- \$mode = 1: --\n"; +var_dump(count ($array1, 1)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing count() : usage variations *** + +-- $mode not set: -- +int(4) + +-- $mode = 1: -- + +Warning: count(): recursion detected in %s on line %d +int(12) +Done diff --git a/ext/standard/tests/array/current_basic.phpt b/ext/standard/tests/array/current_basic.phpt new file mode 100644 index 0000000..cec6959 --- /dev/null +++ b/ext/standard/tests/array/current_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test current() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of current() + */ + +echo "*** Testing current() : basic functionality ***\n"; + +$array = array ('zero', 'one', 'two', 'three' => 3); +var_dump(current($array)); +next($array); +var_dump(current($array)); +end($array); +var_dump(current($array)); +next($array); +var_dump(current($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : basic functionality *** +string(4) "zero" +string(3) "one" +int(3) +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/current_error.phpt b/ext/standard/tests/array/current_error.phpt new file mode 100644 index 0000000..d140ba6 --- /dev/null +++ b/ext/standard/tests/array/current_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test current() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass incorrect number of arguments to current() to test behaviour + */ + +echo "*** Testing current() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing current() function with Zero arguments --\n"; +var_dump( current() ); + +//Test current with one more than the expected number of arguments +echo "\n-- Testing current() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( current($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : error conditions *** + +-- Testing current() function with Zero arguments -- + +Warning: current() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing current() function with more than expected no. of arguments -- + +Warning: current() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/current_variation1.phpt b/ext/standard/tests/array/current_variation1.phpt new file mode 100644 index 0000000..111b8de --- /dev/null +++ b/ext/standard/tests/array/current_variation1.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test current() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass different data types as $array_arg argument to current() to test behaviour + */ + +echo "*** Testing current() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $var1; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of current() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( current($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 -- + +Warning: current() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: current() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: current() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: current() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: current() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: current() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: current() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: current() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: current() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: current() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: current() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: current() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: current() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: current() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: current() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: current() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: current() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: current() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: current() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: current() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- +NULL + +-- Iteration 22 -- + +Warning: current() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: current() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: current() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/current_variation2.phpt b/ext/standard/tests/array/current_variation2.phpt new file mode 100644 index 0000000..49769ce --- /dev/null +++ b/ext/standard/tests/array/current_variation2.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test current() function : usage variations - arrays containing different data types +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass arrays of different data types as $array_arg to current() to test behaviour + */ + +echo "*** Testing current() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of current() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( current($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 : int data -- +int(0) + +-- Iteration 2 : float data -- +float(10.5) + +-- Iteration 3 : null data -- +NULL + +-- Iteration 4 : bool data -- +bool(true) + +-- Iteration 5 : empty string data -- +string(0) "" + +-- Iteration 6 : empty array data -- +bool(false) + +-- Iteration 7 : string data -- +string(6) "string" + +-- Iteration 8 : object data -- +object(classA)#%d (0) { +} + +-- Iteration 9 : undefined data -- +NULL + +-- Iteration 10 : unset data -- +NULL + +-- Iteration 11 : resource data -- +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/array/current_variation3.phpt b/ext/standard/tests/array/current_variation3.phpt new file mode 100644 index 0000000..bab5e6e --- /dev/null +++ b/ext/standard/tests/array/current_variation3.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test current() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing current() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); +next($array1); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" +===DONE=== diff --git a/ext/standard/tests/array/current_variation4.phpt b/ext/standard/tests/array/current_variation4.phpt new file mode 100644 index 0000000..741fced --- /dev/null +++ b/ext/standard/tests/array/current_variation4.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test current() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Test how current() behaves with muti-dimensional and recursive arrays + */ + +echo "*** Testing current() : usage variations ***\n"; + +echo "\n-- Two Dimensional Array --\n"; +$multi_array = array ('zero', array (1, 2, 3), 'two'); +echo "Initial Position: "; +var_dump(current($multi_array)); + +echo "Next Position: "; +next($multi_array); +var_dump(current($multi_array)); + +echo "End Position: "; +end($multi_array); +var_dump(current($multi_array)); + +echo "\n-- Access an Array Within an Array --\n"; +//accessing an array within an array +echo "Initial Position: "; +var_dump(current($multi_array[1])); + +echo "\n-- Recursive, Multidimensional Array --\n"; +//create a recursive array +$multi_array[] = &$multi_array; + +//See where internal pointer is after adding more elements +echo "Current Position: "; +var_dump(current($multi_array)); + +//see if internal pointer is in same position as referenced array +var_dump(current($multi_array[3][3][3])); +// see if internal pointer is in the same position from when accessing this inner array +var_dump(current($multi_array[3][3][3][1])); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: string(4) "zero" +Next Position: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +End Position: string(3) "two" + +-- Access an Array Within an Array -- +Initial Position: int(1) + +-- Recursive, Multidimensional Array -- +Current Position: string(3) "two" +string(3) "two" +int(1) +===DONE=== diff --git a/ext/standard/tests/array/current_variation5.phpt b/ext/standard/tests/array/current_variation5.phpt new file mode 100644 index 0000000..9e7c9e8 --- /dev/null +++ b/ext/standard/tests/array/current_variation5.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test current() function : usage variations - reference & normal parameters +--FILE-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +echo "*** Testing current() : usage variations ***\n"; + +echo "\n-- Function: reference parameter --\n"; + +function current_variation5_ref(&$a) +{ + var_dump(current($a)); + var_dump(next($a)); +} + +$a = array('yes', 'maybe', 'no'); + +var_dump(current($a)); +var_dump(next($a)); +current_variation5($a); + +echo "\n-- Function: normal parameter --\n"; + +function current_variation5($a) +{ + var_dump(current($a)); + var_dump(next($a)); +} + +$a = array('yes', 'maybe', 'no'); + +var_dump(current($a)); +var_dump(next($a)); +current_variation5($a); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Function: reference parameter -- +string(3) "yes" +string(5) "maybe" +string(5) "maybe" +string(2) "no" + +-- Function: normal parameter -- +string(3) "yes" +string(5) "maybe" +string(5) "maybe" +string(2) "no" +===DONE=== diff --git a/ext/standard/tests/array/data.inc b/ext/standard/tests/array/data.inc new file mode 100644 index 0000000..2991274 --- /dev/null +++ b/ext/standard/tests/array/data.inc @@ -0,0 +1,13 @@ +<?php +$tmp = pow(2,24); +$data = array( + 'PHP', + 17=>'PHP: Hypertext Preprocessor', + 5=>'Test', + 'test'=>27, + 1000=>'test', + "-1000"=>array('banana', 'orange'), + 'monkey', + $tmp=>-1/3 +); +?> diff --git a/ext/standard/tests/array/each.phpt b/ext/standard/tests/array/each.phpt Binary files differnew file mode 100644 index 0000000..19ee728 --- /dev/null +++ b/ext/standard/tests/array/each.phpt diff --git a/ext/standard/tests/array/each_basic.phpt b/ext/standard/tests/array/each_basic.phpt new file mode 100644 index 0000000..350b40f --- /dev/null +++ b/ext/standard/tests/array/each_basic.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test each() function : basic functionality +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test basic functionality of each() + */ + +echo "*** Testing each() : basic functionality ***\n"; + +$arr = array ('one' => 1, 'zero', 'two' => 'deux', 20 => 'twenty'); +echo "\n-- Passed array: --\n"; +var_dump($arr); + +echo "\n-- Initial position: --\n"; +var_dump(each($arr)); + +echo "\n-- End position: --\n"; +end($arr); +var_dump(each($arr)); + +echo "\n-- Passed the end of array: --\n"; +var_dump(each($arr)); + +echo "Done"; +?> +--EXPECTF-- +*** Testing each() : basic functionality *** + +-- Passed array: -- +array(4) { + ["one"]=> + int(1) + [0]=> + string(4) "zero" + ["two"]=> + string(4) "deux" + [20]=> + string(6) "twenty" +} + +-- Initial position: -- +array(4) { + [1]=> + int(1) + ["value"]=> + int(1) + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} + +-- End position: -- +array(4) { + [1]=> + string(6) "twenty" + ["value"]=> + string(6) "twenty" + [0]=> + int(20) + ["key"]=> + int(20) +} + +-- Passed the end of array: -- +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_error.phpt b/ext/standard/tests/array/each_error.phpt new file mode 100644 index 0000000..0806bee --- /dev/null +++ b/ext/standard/tests/array/each_error.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test each() function : error conditions - pass incorrect number of args +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass an incorrect number of arguments to each() to test behaviour + */ + +echo "*** Testing each() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing each() function with Zero arguments --\n"; +var_dump( each() ); + +//Test each with one more than the expected number of arguments +echo "\n-- Testing each() function with more than expected no. of arguments --\n"; +$arr = array(1, 2); +$extra_arg = 10; +var_dump( each($arr, $extra_arg) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : error conditions *** + +-- Testing each() function with Zero arguments -- + +Warning: each() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing each() function with more than expected no. of arguments -- + +Warning: each() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/each_variation1.phpt b/ext/standard/tests/array/each_variation1.phpt new file mode 100644 index 0000000..0afef31 --- /dev/null +++ b/ext/standard/tests/array/each_variation1.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test each() function : usage variations - Pass different data types as $arr arg +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass different data types as $arr arg to each() to test behaviour + */ + +echo "*** Testing each() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $arr argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( each($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: Variable passed to each() is not an array or object in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/each_variation2.phpt b/ext/standard/tests/array/each_variation2.phpt new file mode 100644 index 0000000..3f7211c --- /dev/null +++ b/ext/standard/tests/array/each_variation2.phpt @@ -0,0 +1,248 @@ +--TEST-- +Test each() function : usage variations - arrays of different data types +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass arrays of different data types as $arr argument to each() to test behaviour + */ + +echo "*** Testing each() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed as $arr +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( each($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + int(0) + ["value"]=> + int(0) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + float(10.5) + ["value"]=> + float(10.5) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 3: null data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 4: bool data -- +array(4) { + [1]=> + bool(true) + ["value"]=> + bool(true) + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 5: empty string data -- +array(4) { + [1]=> + string(0) "" + ["value"]=> + string(0) "" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 6: empty array data -- +bool(false) + +-- Iteration 7: string data -- +array(4) { + [1]=> + string(6) "string" + ["value"]=> + string(6) "string" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 8: object data -- +array(4) { + [1]=> + object(classA)#%d (0) { + } + ["value"]=> + object(classA)#%d (0) { + } + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 9: undefined data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 10: unset data -- +array(4) { + [1]=> + NULL + ["value"]=> + NULL + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 11: resource data -- +array(4) { + [1]=> + resource(%d) of type (stream) + ["value"]=> + resource(%d) of type (stream) + [0]=> + int(0) + ["key"]=> + int(0) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation3.phpt b/ext/standard/tests/array/each_variation3.phpt new file mode 100644 index 0000000..b31ddc6 --- /dev/null +++ b/ext/standard/tests/array/each_variation3.phpt @@ -0,0 +1,253 @@ +--TEST-- +Test each() function : usage variations - keys of different data types +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Pass each() arrays where the keys are different data types to test behaviour + */ + +echo "*** Testing each() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed as $arr +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of each() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator: $key data --\n"; + var_dump( each($input) ); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Iteration 1: int data -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- Iteration 2: float data -- +array(4) { + [1]=> + string(8) "positive" + ["value"]=> + string(8) "positive" + [0]=> + int(10) + ["key"]=> + int(10) +} + +-- Iteration 3: extreme floats data -- +array(4) { + [1]=> + string(5) "large" + ["value"]=> + string(5) "large" + [0]=> + int(12345678) + ["key"]=> + int(12345678) +} + +-- Iteration 4: null uppercase data -- +array(4) { + [1]=> + string(6) "null 1" + ["value"]=> + string(6) "null 1" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 5: null lowercase data -- +array(4) { + [1]=> + string(6) "null 2" + ["value"]=> + string(6) "null 2" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 6: bool lowercase data -- +array(4) { + [1]=> + string(6) "lowert" + ["value"]=> + string(6) "lowert" + [0]=> + int(1) + ["key"]=> + int(1) +} + +-- Iteration 7: bool uppercase data -- +array(4) { + [1]=> + string(6) "uppert" + ["value"]=> + string(6) "uppert" + [0]=> + int(1) + ["key"]=> + int(1) +} + +-- Iteration 8: empty double quotes data -- +array(4) { + [1]=> + string(6) "emptyd" + ["value"]=> + string(6) "emptyd" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 9: empty single quotes data -- +array(4) { + [1]=> + string(6) "emptys" + ["value"]=> + string(6) "emptys" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 10: string data -- +array(4) { + [1]=> + string(7) "stringd" + ["value"]=> + string(7) "stringd" + [0]=> + string(7) "stringd" + ["key"]=> + string(7) "stringd" +} + +-- Iteration 11: undefined data -- +array(4) { + [1]=> + string(9) "undefined" + ["value"]=> + string(9) "undefined" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} + +-- Iteration 12: unset data -- +array(4) { + [1]=> + string(5) "unset" + ["value"]=> + string(5) "unset" + [0]=> + string(0) "" + ["key"]=> + string(0) "" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation4.phpt b/ext/standard/tests/array/each_variation4.phpt new file mode 100644 index 0000000..535ae29 --- /dev/null +++ b/ext/standard/tests/array/each_variation4.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test each() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test behaviour of each() when: + * 1. Passed an array made up of referenced variables + * 2. Passed an array as $arr argument by reference + */ + +echo "*** Testing each() : usage variations ***\n"; + +echo "\n-- Array made up of referenced variables: --\n"; +$val1 = 'foo'; +$val2 = 'bar'; + +$arr1 = array('one' => &$val1, &$val2); + +echo "-- Call each until at the end of the array: --\n"; +var_dump( each($arr1) ); +var_dump( each($arr1) ); +var_dump( each($arr1) ); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Array made up of referenced variables: -- +-- Call each until at the end of the array: -- +array(4) { + [1]=> + string(3) "foo" + ["value"]=> + string(3) "foo" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} +array(4) { + [1]=> + string(3) "bar" + ["value"]=> + string(3) "bar" + [0]=> + int(0) + ["key"]=> + int(0) +} +bool(false) +Done diff --git a/ext/standard/tests/array/each_variation5.phpt b/ext/standard/tests/array/each_variation5.phpt new file mode 100644 index 0000000..941ad5e --- /dev/null +++ b/ext/standard/tests/array/each_variation5.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test each() function : usage variations - Multi-dimensional arrays +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test behaviour of each() when passed: + * 1. a two-dimensional array + * 2. a sub-array + */ + +echo "*** Testing each() : usage variations ***\n"; + +$arr = array ('zero', + array(1, 2, 3), + 'one' => 'un', + array('a', 'b', 'c') + ); + +echo "\n-- Pass each() a two-dimensional array --\n"; +for ($i = 1; $i < count($arr); $i++) { + var_dump( each($arr) ); +} + +echo "\n-- Pass each() a sub-array --\n"; +var_dump( each($arr[2])); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Pass each() a two-dimensional array -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} +array(4) { + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + ["value"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + [0]=> + int(1) + ["key"]=> + int(1) +} +array(4) { + [1]=> + string(2) "un" + ["value"]=> + string(2) "un" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} + +-- Pass each() a sub-array -- +array(4) { + [1]=> + string(1) "a" + ["value"]=> + string(1) "a" + [0]=> + int(0) + ["key"]=> + int(0) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation6.phpt b/ext/standard/tests/array/each_variation6.phpt new file mode 100644 index 0000000..445d63f --- /dev/null +++ b/ext/standard/tests/array/each_variation6.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test each() function : usage variations - Internal array pointer +--FILE-- +<?php +/* Prototype : array each(array $arr) + * Description: Return the currently pointed key..value pair in the passed array, + * and advance the pointer to the next element + * Source code: Zend/zend_builtin_functions.c + */ + +/* + * Test the position of the internal array pointer after a call to each() + */ + +echo "*** Testing each() : usage variations ***\n"; + +$arr = array('zero', 'one', 'two', 'abc', 'xyz'); + +echo "\n-- Current position: --\n"; +echo key($arr) . " => " . current($arr) . "\n"; + +echo "\n-- Call to each(): --\n"; +var_dump( each($arr) ); + +echo "\n-- New position: --\n"; +echo key($arr) . " => " . current($arr) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Current position: -- +0 => zero + +-- Call to each(): -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} + +-- New position: -- +1 => one +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/end.phpt b/ext/standard/tests/array/end.phpt new file mode 100644 index 0000000..a99f90b --- /dev/null +++ b/ext/standard/tests/array/end.phpt @@ -0,0 +1,237 @@ +--TEST-- +Test end() function +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--INI-- +precision=14 +--FILE-- +<?php +/* Prototype: mixed end ( array &$array ); + Description: Advances internal pointer of array to last element, and returns its value. +*/ + +$arrays = array ( + array( 0 ), + range(1, 100 ), + range('a', 'z', 2 ), + array("a" => "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL ), + array(1, array(1, 2 => 3 ), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, "-0.005" => "neg0.005", 2.0 => "float2", "neg.9" => -.9 ), + array(1.0005, 2.000000, -3.000000, -4.9999999 ), + array(true, false), + array("PHP", "Web2.0", "SOA"), + array(1, array() ), + array(1, 2, "" ), + array(" "), + array(2147483647, 2147483648, -2147483647, -2147483648 ), + array(0x7FFFFFFF, -0x80000000, 017777777777, -020000000000 ), + array(-.6700000E+3, -4.10003E+3, 1e-5, -1E+5, 000002.00 ) +); +/* loop through $arrays to print the last element of each sub-array */ +echo "*** Testing end() on different arrays ***\n"; +$counter = 1; +foreach ($arrays as $sub_array){ + echo "-- Iteration $counter --\n"; + var_dump( end($sub_array) ); + /* ensure that internal pointer is moved to last element */ + var_dump( current($sub_array) ); + $counter++; +} + +/* checking for end() on sub-arrays */ +echo "\n*** Testing end() with sub-arrays ***\n"; +$test_array = array(1, array(1 => "one", "two" => 2, "" => "f") ); +var_dump( end($test_array) ); +var_dump( end($test_array[1]) ); + +/* checking working of end() when array elements are deleted */ +echo "\n*** Testing end() when array elements are deleted ***\n"; +$array_test = array("a", "b", "d", 7, "u" => "U", -4, "-.008" => "neg.008"); + +// remove first element from array +echo "\n-- Remove first element from array --\n"; +unset($array_test[0]); +var_dump( end($array_test) ); + +// remove last element from array, rewind and check end() +echo "\n-- Remove last element from array --\n"; +unset($array_test['-.008']); +var_dump( end($array_test) ); +reset( $array_test ); +var_dump( end($array_test) ); + +// remove any element !first, !last, rewind and check end() +echo "\n-- Remove any element from array apart from first and last element --\n"; +unset($array_test[7]); +var_dump( end($array_test) ); +var_dump( reset($array_test) ); +var_dump( end($array_test) ); + +/* Checking on OBJECTS type */ +echo "\n*** Testing end() on objects ***\n"; +class foo +{ + function __toString() { + return "Object"; + } +} +class foo1 +{ + function __toString() { + return "Object1"; + } +} + +$object1 = new foo(); //new object created +$object2 = new foo1(); + +$array_object = array(); +$array_object[0] = &$object1; +$array_object[1] = &$object2; +var_dump( end($array_object) ); +var_dump($array_object); + +/* Checking on RESOURCE type */ +echo "\n*** Testing end() on resource type ***\n"; +//file type resource +$file_handle = fopen(__FILE__, "r"); + +//directory type resource +$dir_handle = opendir( dirname(__FILE__) ); + +//store resources in array +$resources = array($file_handle, $dir_handle); +var_dump( end($resources) ); +var_dump( current($resources) ); + +echo "\n*** Testing error conditions ***\n"; +/* checking for unexpected number of arguments */ +var_dump( end() ); +var_dump( end($array[0], $array[0]) ); + +/* checking for unexpected type of arguments */ +$var=1; +$var1="string"; +var_dump( end($var) ); +var_dump( end($var1) ); + +/* checking null array */ +$null_array = array(); +var_dump( end($null_array) ); + +echo "Done\n"; + + +/* cleaning resource handles */ +fclose( $file_handle ); //file resource handle deleted +closedir( $dir_handle ); //dir resource handle deleted + +?> +--EXPECTF-- +*** Testing end() on different arrays *** +-- Iteration 1 -- +int(0) +int(0) +-- Iteration 2 -- +int(100) +int(100) +-- Iteration 3 -- +string(1) "y" +string(1) "y" +-- Iteration 4 -- +NULL +NULL +-- Iteration 5 -- +int(5) +int(5) +-- Iteration 6 -- +float(-0.9) +float(-0.9) +-- Iteration 7 -- +float(-4.9999999) +float(-4.9999999) +-- Iteration 8 -- +bool(false) +bool(false) +-- Iteration 9 -- +string(3) "SOA" +string(3) "SOA" +-- Iteration 10 -- +array(0) { +} +array(0) { +} +-- Iteration 11 -- +string(0) "" +string(0) "" +-- Iteration 12 -- +string(1) " " +string(1) " " +-- Iteration 13 -- +float(-2147483648) +float(-2147483648) +-- Iteration 14 -- +float(-2147483648) +float(-2147483648) +-- Iteration 15 -- +float(2) +float(2) + +*** Testing end() with sub-arrays *** +array(3) { + [1]=> + string(3) "one" + ["two"]=> + int(2) + [""]=> + string(1) "f" +} +string(1) "f" + +*** Testing end() when array elements are deleted *** + +-- Remove first element from array -- +string(7) "neg.008" + +-- Remove last element from array -- +int(-4) +int(-4) + +-- Remove any element from array apart from first and last element -- +int(-4) +string(1) "b" +int(-4) + +*** Testing end() on objects *** +object(foo1)#%d (0) { +} +array(2) { + [0]=> + &object(foo)#%d (0) { + } + [1]=> + &object(foo1)#%d (0) { + } +} + +*** Testing end() on resource type *** +resource(%d) of type (stream) +resource(%d) of type (stream) + +*** Testing error conditions *** + +Warning: end() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: end() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: end() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL +bool(false) +Done diff --git a/ext/standard/tests/array/end_64bit.phpt b/ext/standard/tests/array/end_64bit.phpt new file mode 100644 index 0000000..23d410e --- /dev/null +++ b/ext/standard/tests/array/end_64bit.phpt @@ -0,0 +1,238 @@ +--TEST-- +Test end() function +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--INI-- +precision=14 +--FILE-- +<?php +/* Prototype: mixed end ( array &$array ); + Description: Advances internal pointer of array to last element, and returns its value. +*/ + +$arrays = array ( + array( 0 ), + range(1, 100 ), + range('a', 'z', 2 ), + array("a" => "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL ), + array(1, array(1, 2 => 3 ), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, "-0.005" => "neg0.005", 2.0 => "float2", "neg.9" => -.9 ), + array(1.0005, 2.000000, -3.000000, -4.9999999 ), + array(true, false), + array("PHP", "Web2.0", "SOA"), + array(1, array() ), + array(1, 2, "" ), + array(" "), + array(2147483647, 2147483648, -2147483647, -2147483648 ), + array(0x7FFFFFFF, -0x80000000, 017777777777, -020000000000 ), + array(-.6700000E+3, -4.10003E+3, 1e-5, -1E+5, 000002.00 ) +); +/* loop through $arrays to print the last element of each sub-array */ +echo "*** Testing end() on different arrays ***\n"; +$counter = 1; +foreach ($arrays as $sub_array){ + echo "-- Iteration $counter --\n"; + var_dump( end($sub_array) ); + /* ensure that internal pointer is moved to last element */ + var_dump( current($sub_array) ); + $counter++; +} + +/* checking for end() on sub-arrays */ +echo "\n*** Testing end() with sub-arrays ***\n"; +$test_array = array(1, array(1 => "one", "two" => 2, "" => "f") ); +var_dump( end($test_array) ); +var_dump( end($test_array[1]) ); + +/* checking working of end() when array elements are deleted */ +echo "\n*** Testing end() when array elements are deleted ***\n"; +$array_test = array("a", "b", "d", 7, "u" => "U", -4, "-.008" => "neg.008"); + +// remove first element from array +echo "\n-- Remove first element from array --\n"; +unset($array_test[0]); +var_dump( end($array_test) ); + +// remove last element from array, rewind and check end() +echo "\n-- Remove last element from array --\n"; +unset($array_test['-.008']); +var_dump( end($array_test) ); +reset( $array_test ); +var_dump( end($array_test) ); + +// remove any element !first, !last, rewind and check end() +echo "\n-- Remove any element from array apart from first and last element --\n"; +unset($array_test[7]); +var_dump( end($array_test) ); +var_dump( reset($array_test) ); +var_dump( end($array_test) ); + +/* Checking on OBJECTS type */ +echo "\n*** Testing end() on objects ***\n"; +class foo +{ + function __toString() { + return "Object"; + } +} +class foo1 +{ + function __toString() { + return "Object1"; + } +} + +$object1 = new foo(); //new object created +$object2 = new foo1(); + +$array_object = array(); +$array_object[0] = &$object1; +$array_object[1] = &$object2; +var_dump( end($array_object) ); +var_dump($array_object); + +/* Checking on RESOURCE type */ +echo "\n*** Testing end() on resource type ***\n"; +//file type resource +$file_handle = fopen(__FILE__, "r"); + +//directory type resource +$dir_handle = opendir( dirname(__FILE__) ); + +//store resources in array +$resources = array($file_handle, $dir_handle); +var_dump( end($resources) ); +var_dump( current($resources) ); + +echo "\n*** Testing error conditions ***\n"; +/* checking for unexpected number of arguments */ +var_dump( end() ); +var_dump( end($array[0], $array[0]) ); + +/* checking for unexpected type of arguments */ +$var=1; +$var1="string"; +var_dump( end($var) ); +var_dump( end($var1) ); + +/* checking null array */ +$null_array = array(); +var_dump( end($null_array) ); + +echo "Done\n"; + +?> + +--CLEAN-- +/* cleaning resource handles */ +fclose( $file_handle ); //file resource handle deleted +closedir( $dir_handle ); //dir resource handle deleted + +--EXPECTF-- +*** Testing end() on different arrays *** +-- Iteration 1 -- +int(0) +int(0) +-- Iteration 2 -- +int(100) +int(100) +-- Iteration 3 -- +string(1) "y" +string(1) "y" +-- Iteration 4 -- +NULL +NULL +-- Iteration 5 -- +int(5) +int(5) +-- Iteration 6 -- +float(-0.9) +float(-0.9) +-- Iteration 7 -- +float(-4.9999999) +float(-4.9999999) +-- Iteration 8 -- +bool(false) +bool(false) +-- Iteration 9 -- +string(3) "SOA" +string(3) "SOA" +-- Iteration 10 -- +array(0) { +} +array(0) { +} +-- Iteration 11 -- +string(0) "" +string(0) "" +-- Iteration 12 -- +string(1) " " +string(1) " " +-- Iteration 13 -- +int(-2147483648) +int(-2147483648) +-- Iteration 14 -- +int(-2147483648) +int(-2147483648) +-- Iteration 15 -- +float(2) +float(2) + +*** Testing end() with sub-arrays *** +array(3) { + [1]=> + string(3) "one" + ["two"]=> + int(2) + [""]=> + string(1) "f" +} +string(1) "f" + +*** Testing end() when array elements are deleted *** + +-- Remove first element from array -- +string(7) "neg.008" + +-- Remove last element from array -- +int(-4) +int(-4) + +-- Remove any element from array apart from first and last element -- +int(-4) +string(1) "b" +int(-4) + +*** Testing end() on objects *** +object(foo1)#%d (0) { +} +array(2) { + [0]=> + &object(foo)#%d (0) { + } + [1]=> + &object(foo1)#%d (0) { + } +} + +*** Testing end() on resource type *** +resource(%d) of type (stream) +resource(%d) of type (stream) + +*** Testing error conditions *** + +Warning: end() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Warning: end() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Warning: end() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL +bool(false) +Done diff --git a/ext/standard/tests/array/end_basic.phpt b/ext/standard/tests/array/end_basic.phpt new file mode 100644 index 0000000..5a6606d --- /dev/null +++ b/ext/standard/tests/array/end_basic.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test end() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of end() + */ + +echo "*** Testing end() : basic functionality ***\n"; + +$array = array('zero', 'one', 200 => 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to end() --\n"; +var_dump(end($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Add a new element to array --\n"; +$array[2] = 'foo'; +var_dump(end($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to end() -- +string(3) "two" + +-- Current Position: -- +200 => two + +-- Add a new element to array -- +string(3) "foo" +===DONE=== diff --git a/ext/standard/tests/array/end_error.phpt b/ext/standard/tests/array/end_error.phpt new file mode 100644 index 0000000..96e8429 --- /dev/null +++ b/ext/standard/tests/array/end_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test end() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to end() to test behaviour + */ + +echo "*** Testing end() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing end() function with Zero arguments --\n"; +var_dump( end() ); + +//Test end with one more than the expected number of arguments +echo "\n-- Testing end() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( end($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : error conditions *** + +-- Testing end() function with Zero arguments -- + +Warning: end() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing end() function with more than expected no. of arguments -- + +Warning: end() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/end_variation1.phpt b/ext/standard/tests/array/end_variation1.phpt new file mode 100644 index 0000000..79354ab --- /dev/null +++ b/ext/standard/tests/array/end_variation1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test end() function : usage variations - Pass different data types as $array_arg +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg to test behaviour of end() + */ + +echo "*** Testing end() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $foo = 'hello, world'; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of end() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( end($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : usage variations *** + +-- Iteration 1 -- + +Warning: end() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: end() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: end() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: end() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: end() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: end() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: end() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: end() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: end() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: end() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: end() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: end() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: end() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: end() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: end() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: end() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- +string(12) "hello, world" + +-- Iteration 23 -- + +Warning: end() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: end() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: end() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/end_variation2.phpt b/ext/standard/tests/array/end_variation2.phpt new file mode 100644 index 0000000..180f7cd --- /dev/null +++ b/ext/standard/tests/array/end_variation2.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test end() function : usage variations - Multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test end() when passed: + * 1. a two-dimensional array + * 2. a sub-array + * as $array_arg argument. + */ + +echo "*** Testing end() : usage variations ***\n"; + +$array_arg = array ('a' => 'z', array(9, 8, 7)); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(end($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(end($array_arg[0])); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} + +-- Pass a sub-array as $array_arg -- +int(7) +===DONE=== diff --git a/ext/standard/tests/array/end_variation3.phpt b/ext/standard/tests/array/end_variation3.phpt new file mode 100644 index 0000000..cd1e2d0 --- /dev/null +++ b/ext/standard/tests/array/end_variation3.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test end() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : mixed end(array $array_arg) + * Description: Advances array argument's internal pointer to the last element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing end() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); +end($array1); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; +echo "\n-- Position after calling end() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing end() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling end() -- +$array1: string(3) "two" +$array2: string(3) "two" +===DONE=== diff --git a/ext/standard/tests/array/extract_error.phpt b/ext/standard/tests/array/extract_error.phpt new file mode 100644 index 0000000..96cad9d --- /dev/null +++ b/ext/standard/tests/array/extract_error.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test extract() function (error conditions) +--FILE-- +<?php + +/* Testing Error Conditions */ +echo "*** Testing Error Conditions ***\n"; + +/* Zero Arguments */ +var_dump( extract() ); + +/* Invalid second argument ( only 0-6 is valid) */ +$arr = array(1); +var_dump( extract($arr, -1 . "wddr") ); +var_dump( extract($arr, 7 , "wddr") ); + +/* scalar argument */ +$val = 1; +var_dump( extract($val) ); + +/* string argument */ +$str = "test"; +var_dump( extract($str) ); + +/* More than valid number of arguments i.e. 3 args */ +var_dump( extract($arr, EXTR_SKIP, "aa", "ee") ); + +/* Two Arguments, second as prefix but without prefix string as third argument */ +var_dump( extract($arr,EXTR_PREFIX_IF_EXISTS) ); + +echo "Done\n"; +?> + +--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 +Done diff --git a/ext/standard/tests/array/extract_safety.phpt b/ext/standard/tests/array/extract_safety.phpt new file mode 100644 index 0000000..d5d0763 --- /dev/null +++ b/ext/standard/tests/array/extract_safety.phpt @@ -0,0 +1,24 @@ +--TEST-- +Test extract() for overwrite of GLOBALS +--FILE-- +<?php +$str = "John"; +debug_zval_dump($GLOBALS["str"]); + +/* Extracting Global Variables */ +$splat = array("foo" => "bar"); +var_dump(extract(array("GLOBALS" => $splat, EXTR_OVERWRITE))); + +unset ($splat); + +debug_zval_dump($GLOBALS["str"]); + +echo "\nDone"; +?> + +--EXPECTF-- +string(4) "John" refcount(2) +int(0) +string(4) "John" refcount(2) + +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/extract_variation1.phpt b/ext/standard/tests/array/extract_variation1.phpt new file mode 100644 index 0000000..1b2ea19 --- /dev/null +++ b/ext/standard/tests/array/extract_variation1.phpt @@ -0,0 +1,27 @@ +--TEST-- +Test extract() function (variation 1) +--FILE-- +<?php + +$val = 4; +$str = "John"; + +debug_zval_dump($val); +debug_zval_dump($str); + +/* Extracting Global Variables */ +var_dump(extract($GLOBALS, EXTR_REFS)); +debug_zval_dump($val); +debug_zval_dump($str); + +echo "\nDone"; +?> + +--EXPECTF-- +long(4) refcount(2) +string(4) "John" refcount(2) +int(%d) +long(4) refcount(2) +string(4) "John" refcount(2) + +Done diff --git a/ext/standard/tests/array/extract_variation10.phpt b/ext/standard/tests/array/extract_variation10.phpt new file mode 100644 index 0000000..d520be7 --- /dev/null +++ b/ext/standard/tests/array/extract_variation10.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test extract() function - ensure EXTR_REFS doesn't mess with isRef flag on COW references to array elements. +--FILE-- +<?php +$a = array('foo' => 'original.foo'); +$nonref = $a['foo']; +$ref = &$a; +extract($a, EXTR_REFS); +$a['foo'] = 'changed.foo'; +var_dump($nonref); +?> +--EXPECTF-- +%unicode|string%(12) "original.foo" diff --git a/ext/standard/tests/array/extract_variation11.phpt b/ext/standard/tests/array/extract_variation11.phpt new file mode 100644 index 0000000..7f6e08c --- /dev/null +++ b/ext/standard/tests/array/extract_variation11.phpt @@ -0,0 +1,13 @@ +--TEST-- +Test extract() function - ensure EXTR_REFS works when array is referenced and keys clash with variables in current scope. +--FILE-- +<?php +$a = array('foo' => 'original.foo'); +$ref = &$a; +$foo = 'test'; +extract($a, EXTR_OVERWRITE|EXTR_REFS); +$foo = 'changed.foo'; +var_dump($a['foo']); +?> +--EXPECTF-- +%unicode|string%(11) "changed.foo" diff --git a/ext/standard/tests/array/extract_variation2.phpt b/ext/standard/tests/array/extract_variation2.phpt new file mode 100644 index 0000000..570e75f --- /dev/null +++ b/ext/standard/tests/array/extract_variation2.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test extract() function (variation 2) +--FILE-- +<?php + +/* 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" ), +); + +$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")); +} + +echo "Done\n"; +?> +--EXPECTF-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) +int(0) + +-- Iteration 1 -- +int(0) +int(0) +int(0) +int(0) +int(9) +int(0) +int(9) +int(9) +int(0) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) +int(5) +int(0) +Done diff --git a/ext/standard/tests/array/extract_variation3.phpt b/ext/standard/tests/array/extract_variation3.phpt new file mode 100644 index 0000000..2dcb775 --- /dev/null +++ b/ext/standard/tests/array/extract_variation3.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test extract() function (variation 3) +--FILE-- +<?php + +/* various combinations of arrays to be used for the test */ +$mixed_array = array( + 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" ), +); + +$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")); +} + +echo "Done\n"; +?> +--EXPECTF-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(8) +int(0) +int(8) +int(8) +int(0) + +-- Iteration 1 -- +int(5) +int(5) +int(0) +int(5) +int(5) +int(5) +int(5) +int(5) +int(5) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) +int(5) +int(0) +Done diff --git a/ext/standard/tests/array/extract_variation4.phpt b/ext/standard/tests/array/extract_variation4.phpt new file mode 100644 index 0000000..11528f4 --- /dev/null +++ b/ext/standard/tests/array/extract_variation4.phpt @@ -0,0 +1,69 @@ +--TEST-- +Test extract() function (variation 4) +--FILE-- +<?php + +$mixed_array = array( + 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' ), +); + +$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")); +} + +echo "Done\n"; +?> +--EXPECTF-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(5) +int(0) +int(5) +int(5) +int(0) + +-- Iteration 1 -- +int(4) +int(4) +int(0) +int(4) +int(12) +int(4) +int(11) +int(11) +int(4) + +-- Iteration 2 -- +int(0) +int(0) +int(0) +int(0) +int(4) +int(0) +int(4) +int(4) +int(0) +Done diff --git a/ext/standard/tests/array/extract_variation5.phpt b/ext/standard/tests/array/extract_variation5.phpt new file mode 100644 index 0000000..4a3e95b --- /dev/null +++ b/ext/standard/tests/array/extract_variation5.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test extract() function (variation 5) +--FILE-- +<?php + +$mixed_array = array( + 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 ) +); + +$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")); +} + +echo "Done\n"; +?> +--EXPECTF-- +-- Iteration 0 -- +int(0) +int(0) +int(0) +int(0) +int(3) +int(0) +int(3) +int(3) +int(0) + +-- Iteration 1 -- +int(2) +int(2) +int(0) +int(2) +int(8) +int(2) +int(8) +int(8) +int(2) +Done diff --git a/ext/standard/tests/array/extract_variation6.phpt b/ext/standard/tests/array/extract_variation6.phpt new file mode 100644 index 0000000..7eac67e --- /dev/null +++ b/ext/standard/tests/array/extract_variation6.phpt @@ -0,0 +1,28 @@ +--TEST-- +Test extract() function (variation 6) +--FILE-- +<?php + +/* EXTR_REFS as second Argument */ +$a = array ('foo' => 'aaa'); +var_dump ( extract($a, EXTR_REFS)); +var_dump($foo); + +$b = $a; +$b['foo'] = 'bbb'; +var_dump ( extract($a, EXTR_REFS)); +var_dump($foo); +var_dump($a); + +echo "Done\n"; +?> +--EXPECTF-- +int(1) +string(3) "aaa" +int(1) +string(3) "bbb" +array(1) { + ["foo"]=> + &string(3) "bbb" +} +Done diff --git a/ext/standard/tests/array/extract_variation7.phpt b/ext/standard/tests/array/extract_variation7.phpt new file mode 100644 index 0000000..653941d --- /dev/null +++ b/ext/standard/tests/array/extract_variation7.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test extract() function (variation 7) +--FILE-- +<?php + +/* EXTR_PREFIX_ALL called twice with same prefix string */ +echo "\n*** Testing for EXTR_PREFIX_ALL called twice with same prefix string ***\n"; +$a = array( "1" => "one", "2" => "two", "3" => "three", "4" => "four", "5" => "five" ); +var_dump ( extract($a, EXTR_PREFIX_ALL, "same")); + +$b = 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 ); +var_dump ( extract($b, EXTR_PREFIX_ALL, "same")); +var_dump ( extract($b, EXTR_PREFIX_ALL, "diff")); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing for EXTR_PREFIX_ALL called twice with same prefix string *** +int(5) +int(11) +int(11) +Done diff --git a/ext/standard/tests/array/extract_variation8.phpt b/ext/standard/tests/array/extract_variation8.phpt new file mode 100644 index 0000000..0d15fd4 --- /dev/null +++ b/ext/standard/tests/array/extract_variation8.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test extract() function (variation 8) +--FILE-- +<?php + +/* 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)); + +echo "\nDone"; +?> + +--EXPECTF-- +*** Testing for Numerical prefixes *** +int(3) +int(1) + +Done diff --git a/ext/standard/tests/array/extract_variation9.phpt b/ext/standard/tests/array/extract_variation9.phpt new file mode 100644 index 0000000..4d42a69 --- /dev/null +++ b/ext/standard/tests/array/extract_variation9.phpt @@ -0,0 +1,20 @@ +--TEST-- +Test extract() function (variation 9) +--FILE-- +<?php +/* 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 "Done\n"; +?> +--EXPECT-- +*** Testing for object *** +int(1) +Done diff --git a/ext/standard/tests/array/in_array_errors.phpt b/ext/standard/tests/array/in_array_errors.phpt new file mode 100644 index 0000000..13a6cdb --- /dev/null +++ b/ext/standard/tests/array/in_array_errors.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test in_array() function : error conditions +--FILE-- +<?php +/* + * Prototype : bool in_array ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns TRUE + * if it is found in the array, FALSE otherwise. + * Source Code: ext/standard/array.c +*/ + +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) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** 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/in_array_variation1.phpt b/ext/standard/tests/array/in_array_variation1.phpt new file mode 100644 index 0000000..470738b --- /dev/null +++ b/ext/standard/tests/array/in_array_variation1.phpt @@ -0,0 +1,642 @@ +--TEST-- +Test in_array() function : usage variations - different needdle values +--FILE-- +<?php +/* + * Prototype : bool in_array ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns TRUE + * if it is found in the array, FALSE otherwise. + * Source Code: ext/standard/array.c +*/ + +/* Test in_array() with different possible needle values */ + +echo "*** Testing in_array() with different needle values ***\n"; +$arrays = array ( + array(0), + array("a" => "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++; + } +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing in_array() with different needle values *** +-- 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) +Done diff --git a/ext/standard/tests/array/in_array_variation2.phpt b/ext/standard/tests/array/in_array_variation2.phpt new file mode 100644 index 0000000..ee1267f --- /dev/null +++ b/ext/standard/tests/array/in_array_variation2.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test in_array() function : usage variations - different haystack values +--FILE-- +<?php +/* + * Prototype : bool in_array ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns TRUE + * if it is found in the array, FALSE otherwise. + * Source Code: ext/standard/array.c +*/ + +/* Test in_array() with different possible haystack values */ + +echo "*** Testing in_array() with different haystack values ***\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++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing in_array() with different haystack values *** +-- 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) +Done diff --git a/ext/standard/tests/array/in_array_variation3.phpt b/ext/standard/tests/array/in_array_variation3.phpt new file mode 100644 index 0000000..c8b6445 --- /dev/null +++ b/ext/standard/tests/array/in_array_variation3.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test in_array() function : usage variations - haystack as sub-array/object +--FILE-- +<?php +/* + * Prototype : bool in_array ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns TRUE + * if it is found in the array, FALSE otherwise. + * Source Code: ext/standard/array.c +*/ + +/* Test in_array() with haystack as sub-array and object */ + +/* checking for sub-arrays with in_array() */ +echo "*** 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) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** 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) +Done diff --git a/ext/standard/tests/array/in_array_variation4.phpt b/ext/standard/tests/array/in_array_variation4.phpt new file mode 100644 index 0000000..b88a5a2 --- /dev/null +++ b/ext/standard/tests/array/in_array_variation4.phpt @@ -0,0 +1,77 @@ +--TEST-- +Test in_array() function : usage variations - haystack as resource/multi dimentional array +--FILE-- +<?php +/* + * Prototype : bool in_array ( mixed $needle, array $haystack [, bool $strict] ) + * Description: Searches haystack for needle and returns TRUE + * if it is found in the array, FALSE otherwise. + * Source Code: ext/standard/array.c +*/ + +/* Test in_array() with haystack as resouce and multidimentional arrays */ + +/* checking for Resources */ +echo "*** 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 "Done\n"; +?> +--EXPECTF-- +*** 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) +Done diff --git a/ext/standard/tests/array/key_basic.phpt b/ext/standard/tests/array/key_basic.phpt new file mode 100644 index 0000000..8fdca19 --- /dev/null +++ b/ext/standard/tests/array/key_basic.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test key() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of key() + */ + +echo "*** Testing key() : basic functionality ***\n"; + +$array = array ('zero', 99 => 'one', 'two', 'three' => 3); +echo "\n-- Initial Position: --\n"; +var_dump(key($array)); + +echo "\n-- Next Position: --\n"; +next($array); +var_dump(key($array)); + +echo "\n-- End Position: --\n"; +end($array); +var_dump(key($array)); + +echo "\n-- Past end of the array --\n"; +next($array); +var_dump(key($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : basic functionality *** + +-- Initial Position: -- +int(0) + +-- Next Position: -- +int(99) + +-- End Position: -- +string(5) "three" + +-- Past end of the array -- +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_error.phpt b/ext/standard/tests/array/key_error.phpt new file mode 100644 index 0000000..1200f74 --- /dev/null +++ b/ext/standard/tests/array/key_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test key() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to key() to test behaviour + */ + +echo "*** Testing key() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing key() function with Zero arguments --\n"; +var_dump( key() ); + +//Test current with one more than the expected number of arguments +echo "\n-- Testing key() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( key($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : error conditions *** + +-- Testing key() function with Zero arguments -- + +Warning: key() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing key() function with more than expected no. of arguments -- + +Warning: key() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_exists_basic.phpt b/ext/standard/tests/array/key_exists_basic.phpt new file mode 100644 index 0000000..40d982d --- /dev/null +++ b/ext/standard/tests/array/key_exists_basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test function key_exists() by calling it with its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** test key_exists() by calling it with its expected arguments ***\n"; +$a = array('bar' => 1); +var_dump(key_exists('bar', $a)); +var_dump(key_exists('foo', $a)); +--EXPECTF-- +*** test key_exists() by calling it with its expected arguments *** +bool(true) +bool(false) diff --git a/ext/standard/tests/array/key_exists_error.phpt b/ext/standard/tests/array/key_exists_error.phpt new file mode 100644 index 0000000..1bbd41e --- /dev/null +++ b/ext/standard/tests/array/key_exists_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +Test function key_exists() by calling it more than or less than its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php + +echo "*** Test by calling method or function with incorrect numbers of arguments ***\n"; + +$a = array('bar' => 1); +var_dump(key_exists()); +var_dump(key_exists('foo', $a, 'baz')); + +?> +--EXPECTF-- +*** Test by calling method or function with incorrect numbers of arguments *** + +Warning: key_exists() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +Warning: key_exists() expects exactly 2 parameters, 3 given in %s on line %d +NULL diff --git a/ext/standard/tests/array/key_exists_variation1.phpt b/ext/standard/tests/array/key_exists_variation1.phpt new file mode 100644 index 0000000..94ea8d4 --- /dev/null +++ b/ext/standard/tests/array/key_exists_variation1.phpt @@ -0,0 +1,15 @@ +--TEST-- +Test function key_exists() by calling it with its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** test key_exists() by calling it with its expected arguments ***\n"; +$a = array('bar' => 1, 'foo' => array('bar' => 2, 'baz' => 3)); +var_dump(key_exists('baz', $a)); +var_dump(key_exists('baz', $a['foo'])); +--EXPECTF-- +*** test key_exists() by calling it with its expected arguments *** +bool(false) +bool(true) diff --git a/ext/standard/tests/array/key_exists_variation2.phpt b/ext/standard/tests/array/key_exists_variation2.phpt new file mode 100644 index 0000000..5f5ab86 --- /dev/null +++ b/ext/standard/tests/array/key_exists_variation2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test function key_exists() by calling it with its expected arguments +--CREDITS-- +Francesco Fullone ff@ideato.it +#PHPTestFest Cesena Italia on 2009-06-20 +--FILE-- +<?php +echo "*** test key_exists() by using mixed type of arrays ***\n"; + +// there is not a index = 0 element +$a = array(1 => 'bar', 'foo' => 'baz'); +var_dump(key_exists(0, $a)); + +echo "integer\n"; +// 1 has index = 0 +$b = array(1, 'foo' => 'baz'); +var_dump(key_exists(0, $b)); + +// 42 has index = 0, netherless its position is the latest +$c = array('foo' => 'baz', 42); +var_dump(key_exists(0, $c)); + +echo "string\n"; +// 'bar' has index = 0, netherless it is a string +$d = array('bar', 'foo' => 'baz'); +var_dump(key_exists(0, $d)); + +// 'baz' has index = 0, netherless its position is the latest +$e = array('foo' => 'baz', 'baz'); +var_dump(key_exists(0, $e)); + +echo "obj\n"; +class ObjectA +{ + public $foo = 'bar'; +} + +$obj = new ObjectA(); + +// object has index = 0, netherless its position is the latest +$f = array('foo' => 'baz', $obj); +var_dump(key_exists(0, $f)); + +// object has index = 0, netherless its position is the first +$g = array($obj, 'foo' => 'baz'); +var_dump(key_exists(0, $g)); + +echo "stream resource\n"; +// stream resource has index = 0, netherless its position is the first +$st = fopen('php://memory', '+r'); +$h = array($st, 'foo' => 'baz'); +var_dump(key_exists(0, $h)); + +// stream resource has index = 0, netherless its position is the latest +$i = array('foo' => 'baz', $st); +var_dump(key_exists(0, $i)); + +--EXPECTF-- +*** test key_exists() by using mixed type of arrays *** +bool(false) +integer +bool(true) +bool(true) +string +bool(true) +bool(true) +obj +bool(true) +bool(true) +stream resource +bool(true) +bool(true) diff --git a/ext/standard/tests/array/key_variation1.phpt b/ext/standard/tests/array/key_variation1.phpt new file mode 100644 index 0000000..a0c59b4 --- /dev/null +++ b/ext/standard/tests/array/key_variation1.phpt @@ -0,0 +1,220 @@ +--TEST-- +Test key() function : usage variations - Pass different data types as $array_arg arg. +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to test behaviour of key() + */ + +echo "*** Testing key() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $var1; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of key() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( key($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: key() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: key() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: key() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: key() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- +string(4) "var1" + +-- Iteration 23 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: key() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: key() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_variation2.phpt b/ext/standard/tests/array/key_variation2.phpt new file mode 100644 index 0000000..3538906 --- /dev/null +++ b/ext/standard/tests/array/key_variation2.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test key() function : usage variations +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where keys are different data types as $array_arg to key() to test behaviour + */ + +echo "*** Testing key() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// unexpected values to be passed as $array_arg +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), +); + +// loop through each element of $inputs to check the behavior of key() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + while (key($input) !== NULL) { + var_dump(key($input)); + next($input); + } + $iterator++; +}; +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Iteration 1 : int data -- +int(0) +int(1) +int(12345) +int(-2345) + +-- Iteration 2 : float data -- +int(10) +int(-10) +int(0) + +-- Iteration 3 : extreme floats data -- +int(12345678) +int(0) + +-- Iteration 4 : null uppercase data -- +string(0) "" + +-- Iteration 5 : null lowercase data -- +string(0) "" + +-- Iteration 6 : bool lowercase data -- +int(1) +int(0) + +-- Iteration 7 : bool uppercase data -- +int(1) +int(0) + +-- Iteration 8 : empty double quotes data -- +string(0) "" + +-- Iteration 9 : empty single quotes data -- +string(0) "" + +-- Iteration 10 : string data -- +string(7) "stringd" +string(7) "strings" +string(11) "hello world" + +-- Iteration 11 : undefined data -- +string(0) "" + +-- Iteration 12 : unset data -- +string(0) "" +===DONE=== diff --git a/ext/standard/tests/array/key_variation3.phpt b/ext/standard/tests/array/key_variation3.phpt new file mode 100644 index 0000000..a231917 --- /dev/null +++ b/ext/standard/tests/array/key_variation3.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test key() function : usage variations +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing key() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(key($array1)); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; + +next($array1); + +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(key($array1)); +echo "\$array2: "; +var_dump(key($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Initial position of internal pointer -- +int(0) + +-- Position after calling next() -- +$array1: int(1) +$array2: int(1) +===DONE=== diff --git a/ext/standard/tests/array/key_variation4.phpt b/ext/standard/tests/array/key_variation4.phpt new file mode 100644 index 0000000..147d55a --- /dev/null +++ b/ext/standard/tests/array/key_variation4.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test key() function : usage variations +--FILE-- +<?php +/* Prototype : mixed key(array $array_arg) + * Description: Return the key of the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test how key() behaves with muti-dimensional and recursive arrays + */ + +echo "*** Testing key() : usage variations ***\n"; + +echo "\n-- Two Dimensional Array --\n"; +$multi_array = array ('zero', array (1, 2, 3), 'two'); +echo "Initial Position: "; +var_dump(key($multi_array)); + +echo "Next Position: "; +next($multi_array); +var_dump(key($multi_array)); + +echo "End Position: "; +end($multi_array); +var_dump(key($multi_array)); + +echo "\n-- Access an Array Within an Array --\n"; +//accessing an array within an array +echo "Initial Position: "; +var_dump(key($multi_array[1])); + +echo "\n-- Recursive, Multidimensional Array --\n"; +//create a recursive array +$multi_array[] = &$multi_array; + +//See where internal pointer is after adding more elements +echo "Current Position: "; +var_dump(key($multi_array)); + +//see if internal pointer is in same position as referenced array +var_dump(key($multi_array[3][3][3])); +// see if internal pointer is in the same position from when accessing this inner array +var_dump(key($multi_array[3][3][3][1])); +?> +===DONE=== +--EXPECTF-- +*** Testing key() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: int(0) +Next Position: int(1) +End Position: int(2) + +-- Access an Array Within an Array -- +Initial Position: int(0) + +-- Recursive, Multidimensional Array -- +Current Position: int(2) +int(2) +int(0) +===DONE=== diff --git a/ext/standard/tests/array/krsort_basic.phpt b/ext/standard/tests/array/krsort_basic.phpt new file mode 100644 index 0000000..27361eb --- /dev/null +++ b/ext/standard/tests/array/krsort_basic.phpt @@ -0,0 +1,245 @@ +--TEST-- +Test krsort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing array of integer/string values to check the basic functionality + * with following flag values : + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically + * 4.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : basic functionality ***\n"; + +// an array containing unsorted string values with indices +$unsorted_strings = array( "lemon" => "l", "orange" => "o", "banana" => "b" ); +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing krsort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : basic functionality *** + +-- Testing krsort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["O3"]=> + string(7) "Orange3" + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing krsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["o2"]=> + string(7) "orange2" + ["o"]=> + string(6) "orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" + ["O3"]=> + string(7) "Orange3" + ["O1"]=> + string(7) "Orange1" + ["O"]=> + string(6) "Orange" +} + +-- Testing krsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + ["o20"]=> + string(8) "orange20" + ["O3"]=> + string(7) "Orange3" + ["o2"]=> + string(7) "orange2" + ["O1"]=> + string(7) "Orange1" + ["o"]=> + string(6) "orange" + ["O"]=> + string(6) "Orange" + ["l"]=> + string(5) "lemon" + ["b"]=> + string(6) "banana" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/krsort_error.phpt b/ext/standard/tests/array/krsort_error.phpt new file mode 100644 index 0000000..1bca5f9 --- /dev/null +++ b/ext/standard/tests/array/krsort_error.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test krsort() function : error conditions +--FILE-- +<?php +/* Prototype : bool krsort(array &array_arg [, int asort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing krsort() function with all possible error conditions +*/ + +echo "*** Testing krsort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing krsort() function with zero arguments --\n"; +var_dump( krsort() ); + +//Test krsort with more than the expected number of arguments +echo "\n-- Testing krsort() function with more than expected no. of arguments --\n"; +$array_arg = array(1 => 1, 2 => 2); +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and call krsort with all possible sort flag values +foreach($flags as $key => $flag){ + echo "\n- Sort flag = $key -\n"; + $temp_array = $array_arg; + var_dump( krsort($temp_array,$flag, $extra_arg) ); + var_dump($temp_array); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : error conditions *** + +-- Testing krsort() function with zero arguments -- + +Warning: krsort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing krsort() function with more than expected no. of arguments -- + +- Sort flag = SORT_REGULAR - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_STRING - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_NUMERIC - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/krsort_object.phpt b/ext/standard/tests/array/krsort_object.phpt new file mode 100644 index 0000000..36d8589 --- /dev/null +++ b/ext/standard/tests/array/krsort_object.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test krsort() function : object functionality - sort objects +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ +/* + * testing krsort() by providing array of integer/string objects with following flag values: + * 1.Defualt flag value + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing krsort() : object functionality ***\n"; + +// class declaration for integer objects +class Integer +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } +} + +// class declaration for string objects +class String +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects with different key values +$unsorted_int_obj = array ( + 10 => new Integer(11), 20 => new Integer(66), + 3 => new Integer(23), 4 => new Integer(-5), + 50 => new Integer(0.001), 6 => new Integer(0) +); + +// array of string objects with different key values +$unsorted_str_obj = array ( + "axx" => new String("axx"), "t" => new String("t"), + "w" => new String("w"), "py" => new String("py"), + "apple" => new String("apple"), "Orange" => new String("Orange"), + "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") +); + + +echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing krsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +// testing krsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing krsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing krsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : object functionality *** + +-- Testing krsort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [50]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [50]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done diff --git a/ext/standard/tests/array/krsort_variation1.phpt b/ext/standard/tests/array/krsort_variation1.phpt new file mode 100644 index 0000000..e4cbaf8 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation1.phpt @@ -0,0 +1,397 @@ +--TEST-- +Test krsort() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : bool krsort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing different unexpected values for array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically + * 4.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +$unexpected_values = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e3, + 10.6E-2, + 0.5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*11*/ true, + false, + TRUE, + FALSE, + + // empty data +/*15*/ "", + '', + + // string data +/*17*/ "string", + 'string', + + // object data +/*19*/ new stdclass(), + + // undefined data +/*20*/ @undefined_var, + + // unset data +/*21*/ @unset_var, + + // resource variable +/*22*/ $fp +); + +// loop though each element of the array and check the working of krsort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing krsort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( krsort($value) ); // expecting : bool(false) + var_dump( krsort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( krsort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( krsort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/krsort_variation10.phpt b/ext/standard/tests/array/krsort_variation10.phpt new file mode 100644 index 0000000..f56d287 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation10.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test krsort() function : usage variations - sort heredoc strings +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of heredoc strings for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// Different heredoc strings to be sorted +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + +$array = array ( + $simple_heredoc1 => "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt --\n"; +$temp_array = $array; +var_dump(krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} +Done diff --git a/ext/standard/tests/array/krsort_variation11.phpt b/ext/standard/tests/array/krsort_variation11.phpt new file mode 100644 index 0000000..0cfa482 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation11.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test krsort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of boolean values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// bool value array +$bool_values = array (true => true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying boolean value array, 'flag' value is defualt -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/krsort_variation2.phpt b/ext/standard/tests/array/krsort_variation2.phpt new file mode 100644 index 0000000..1376202 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation2.phpt @@ -0,0 +1,307 @@ +--TEST-- +Test krsort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : bool krsort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// an array for checking unexpected behavior +$unsorted_values = array(10 => 10, 2 => 2, 45 => 45); + +//array of unexpected values to iterate over +$unexpected_values = array ( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of krsort() +// when 'sort_flags' arugment is supplied with different values +echo "\n-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( krsort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 2 -- +bool(true) +array(3) { + [45]=> + int(45) + [2]=> + int(2) + [10]=> + int(10) +} +-- Iteration 3 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 4 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 5 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 6 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 7 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 8 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 9 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 10 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 11 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 12 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 13 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 14 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 15 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 16 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 17 -- + +Warning: krsort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 18 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 19 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 20 -- + +Warning: krsort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/krsort_variation3.phpt b/ext/standard/tests/array/krsort_variation3.phpt new file mode 100644 index 0000000..8f411a9 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation3.phpt @@ -0,0 +1,262 @@ +--TEST-- +Test krsort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing array of integer/float/mixed values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// diff. associative arrays to sort +$various_arrays = array( + // negative/posative integer key value array + array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41), + + // float key values + array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1), + + // mixed value array with different types of keys + array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, 9 => 10.6E-2, + -10 => -10.6E-2, 11 => 33) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing krsort() by supplying various integer/float arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +Done diff --git a/ext/standard/tests/array/krsort_variation4.phpt b/ext/standard/tests/array/krsort_variation4.phpt new file mode 100644 index 0000000..3df924a --- /dev/null +++ b/ext/standard/tests/array/krsort_variation4.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test krsort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of octal values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} +Done diff --git a/ext/standard/tests/array/krsort_variation5.phpt b/ext/standard/tests/array/krsort_variation5.phpt new file mode 100644 index 0000000..0fa1e9c --- /dev/null +++ b/ext/standard/tests/array/krsort_variation5.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test krsort() function : usage variations - sort strings +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of string values for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +$various_arrays = array ( + // diff. escape sequence chars with key values + array ( null => null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test", + 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing krsort() by supplying various string arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +Done diff --git a/ext/standard/tests/array/krsort_variation6.phpt b/ext/standard/tests/array/krsort_variation6.phpt new file mode 100644 index 0000000..167d0ee --- /dev/null +++ b/ext/standard/tests/array/krsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test krsort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing array of hexa-decimal values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// an array containing unsorted hexadecimal values with keys +$unsorted_hex_array = array ( + 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa +); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done diff --git a/ext/standard/tests/array/krsort_variation7.phpt b/ext/standard/tests/array/krsort_variation7.phpt new file mode 100644 index 0000000..9ba3fc5 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation7.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test krsort() function : usage variations - sort array with diff. sub arrays +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing krsort() by providing arrays contains sub arrays for $array argument + * with flowing flag values + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing krsort() : usage variations ***\n"; + +// array with diff sub arrays to be sorted +$various_arrays = array ( + // null array + 1 => array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +Done diff --git a/ext/standard/tests/array/krsort_variation8.phpt b/ext/standard/tests/array/krsort_variation8.phpt Binary files differnew file mode 100644 index 0000000..20276ad --- /dev/null +++ b/ext/standard/tests/array/krsort_variation8.phpt diff --git a/ext/standard/tests/array/krsort_variation9.phpt b/ext/standard/tests/array/krsort_variation9.phpt new file mode 100644 index 0000000..d7d8343 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation9.phpt @@ -0,0 +1,257 @@ +--TEST-- +Test krsort() function : usage variations - sort array with/without key values +--FILE-- +<?php +/* Prototype : bool krsort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key in reverse order, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * Testing krsort() by providing arrays with/without key values for $array argument + * with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing krsort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays with/without key values --\n"; + +// loop through to test krsort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With defualt sort flag - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With defualt sort flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With defualt sort flag - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/ksort_basic.phpt b/ext/standard/tests/array/ksort_basic.phpt new file mode 100644 index 0000000..dd9f7a2 --- /dev/null +++ b/ext/standard/tests/array/ksort_basic.phpt @@ -0,0 +1,243 @@ +--TEST-- +Test ksort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing array of integer/string values to check the basic functionality with following flag values : + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically + * 4.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : basic functionality ***\n"; + +// an array containing unsorted string values with indices +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing ksort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( ksort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : basic functionality *** + +-- Testing ksort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} + +-- Testing ksort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} + +-- Testing ksort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + ["O"]=> + string(6) "Orange" + ["O1"]=> + string(7) "Orange1" + ["O3"]=> + string(7) "Orange3" + ["b"]=> + string(6) "banana" + ["l"]=> + string(5) "lemon" + ["o"]=> + string(6) "orange" + ["o2"]=> + string(7) "orange2" + ["o20"]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(6) "banana" + [1]=> + string(5) "lemon" + [2]=> + string(6) "orange" + [3]=> + string(6) "Orange" + [4]=> + string(7) "Orange1" + [5]=> + string(7) "orange2" + [6]=> + string(8) "orange20" + [7]=> + string(7) "Orange3" +} + +-- Testing ksort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(6) "banana" + [1]=> + string(5) "lemon" + [2]=> + string(6) "orange" + [3]=> + string(6) "Orange" + [4]=> + string(7) "Orange1" + [5]=> + string(7) "orange2" + [6]=> + string(7) "Orange3" + [7]=> + string(8) "orange20" +} + +-- Testing ksort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [22]=> + int(1) + [33]=> + int(3) + [100]=> + int(4) + [555]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/ksort_error.phpt b/ext/standard/tests/array/ksort_error.phpt new file mode 100644 index 0000000..f2b102a --- /dev/null +++ b/ext/standard/tests/array/ksort_error.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test ksort() function : error conditions +--FILE-- +<?php +/* Prototype : bool ksort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* +* Testing ksort() function with all possible error conditions +*/ + +echo "*** Testing ksort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing ksort() function with Zero arguments --\n"; +var_dump( ksort() ); + +//Test ksort with more than the expected number of arguments +echo "\n-- Testing ksort() function with more than expected no. of arguments --\n"; +$array_arg = array(1 => 1, 2 => 2); +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and call krsort with all possible sort flag values +foreach($flag_value as $key => $flag){ + echo "\n- Sort flag = $key -\n"; + $temp_array = $array_arg; + var_dump( ksort($temp_array,$flag, $extra_arg) ); + var_dump( $temp_array); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ksort() : error conditions *** + +-- Testing ksort() function with Zero arguments -- + +Warning: ksort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing ksort() function with more than expected no. of arguments -- + +- Sort flag = SORT_REGULAR - + +Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_STRING - + +Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_NUMERIC - + +Warning: ksort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/ksort_object.phpt b/ext/standard/tests/array/ksort_object.phpt new file mode 100644 index 0000000..20e8ba2 --- /dev/null +++ b/ext/standard/tests/array/ksort_object.phpt @@ -0,0 +1,241 @@ +--TEST-- +Test ksort() function : object functionality - sort objects +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ +/* + * testing ksort() by providing array ofinteger/string objects with following flag values: + * 1.SORT_NUMERIC - compare items numerically + * 2.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : object functionality ***\n"; + +// class declaration for integer objects +class Integer +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class String +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array ( + 11 => new Integer(11), 66 => new Integer(66), + 23 => new Integer(23), -5 => new Integer(-5), + 1 => new Integer(0.001), 0 => new Integer(0) +); + +// array of string objects +$unsorted_str_obj = array ( + "axx" => new String("axx"), "t" => new String("t"), + "w" => new String("w"), "py" => new String("py"), + "apple" => new String("apple"), "Orange" => new String("Orange"), + "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") +); +echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing ksort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +// testing ksort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing ksort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing ksort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : object functionality *** + +-- Testing ksort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [-5]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [0]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [1]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [11]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [23]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } + [66]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing ksort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [-5]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [0]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [1]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [11]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [23]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } + [66]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/ext/standard/tests/array/ksort_variation1.phpt b/ext/standard/tests/array/ksort_variation1.phpt new file mode 100644 index 0000000..d8c037f --- /dev/null +++ b/ext/standard/tests/array/ksort_variation1.phpt @@ -0,0 +1,397 @@ +--TEST-- +Test ksort() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : bool ksort(array &array [, int sort_flags]) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing different unexpected values for array argument with following flag values: + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +$unexpected_values = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e3, + 10.6E-2, + 0.5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*11*/ true, + false, + TRUE, + FALSE, + + // empty data +/*15*/ "", + '', + + // string data +/*17*/ "string", + 'string', + + // object data +/*19*/ new stdclass(), + + // undefined data +/*20*/ @undefined_var, + + // unset data +/*21*/ @unset_var, + + // resource variable +/*22*/ $fp + +); + +// loop though each element of the array and check the working of ksort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing ksort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( ksort($value) ); // expecting : bool(false) + var_dump( ksort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( ksort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( ksort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: ksort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/ksort_variation10.phpt b/ext/standard/tests/array/ksort_variation10.phpt new file mode 100644 index 0000000..051bc30 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation10.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test ksort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of octal values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array ( + 01235 => 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( ksort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} + +-- Testing ksort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} + +-- Testing ksort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-229]=> + int(-2) + [-54]=> + int(-1) + [0]=> + int(0) + [54]=> + int(4) + [63]=> + int(6) + [209]=> + int(2) + [229]=> + int(3) + [506]=> + int(5) + [669]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/ksort_variation11.phpt b/ext/standard/tests/array/ksort_variation11.phpt new file mode 100644 index 0000000..347df65 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation11.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test ksort() function : usage variations - sort heredoc strings +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of heredoc strings for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// Different heredoc strings to be sorted +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + +$array = array ( + $simple_heredoc1 => "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' value is defualt --\n"; +$temp_array = $array; +var_dump(ksort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(ksort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(ksort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying heredoc string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} + +-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} + +-- Testing ksort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["HEREDOC"]=> + string(7) "HEREDOC" + ["Heredoc"]=> + string(7) "Heredoc" + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/ext/standard/tests/array/ksort_variation2.phpt b/ext/standard/tests/array/ksort_variation2.phpt new file mode 100644 index 0000000..4969844 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation2.phpt @@ -0,0 +1,307 @@ +--TEST-- +Test ksort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : bool ksort(array &array_arg [, int sort_flags]) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// an array for checking unexpected behavior +$unsorted_values = array(10 => 10, 2 => 2, 45 => 45); + +//array of unexpected values to iterate over +$unexpected_values = array ( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of ksort() +// when 'sort_flags' arugment is supplied with different values +echo "\n-- Testing ksort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( ksort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 2 -- +bool(true) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 3 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 4 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 5 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 6 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 7 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 8 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 9 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 10 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 11 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 12 -- +bool(true) +array(3) { + [2]=> + int(2) + [10]=> + int(10) + [45]=> + int(45) +} +-- Iteration 13 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 14 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 15 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 16 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 17 -- + +Warning: ksort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 18 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 19 -- + +Warning: ksort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 20 -- + +Warning: ksort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/ksort_variation3.phpt b/ext/standard/tests/array/ksort_variation3.phpt new file mode 100644 index 0000000..4029b9b --- /dev/null +++ b/ext/standard/tests/array/ksort_variation3.phpt @@ -0,0 +1,262 @@ +--TEST-- +Test ksort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing array of integer/float/mixed values for $array argument + * with following flag values: + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// diff. associative arrays to sort +$various_arrays = array( + // negative/posative integer key value array + array(1 => 11, -2 => -11, 3 => 21, -4 => -21, 5 => 31, -6 => -31, 7 => 0, 8 => 41, -10 =>-41), + + // float key values + array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1), + + // mixed value array with different types of keys + array(1 => .0001, 2 => .0021, -3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, -8 => -.9, + 9 => 10.6E-2, -10 => -10.6E-2, 11 => 33) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing ksort() by supplying various integer/float arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(ksort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call ksort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(ksort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [-10]=> + int(-41) + [-6]=> + int(-31) + [-4]=> + int(-21) + [-2]=> + int(-11) + [1]=> + int(11) + [3]=> + int(21) + [5]=> + int(31) + [7]=> + int(0) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(6) { + [-7]=> + float(-0.1) + [0]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) + [4]=> + float(0.106) + [6]=> + float(0.0001) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [-7]=> + float(-0.1) + [0]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) + [4]=> + float(0.106) + [6]=> + float(0.0001) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(6) { + [-7]=> + float(-0.1) + [0]=> + float(0.5) + [1]=> + float(10.5) + [3]=> + float(1050) + [4]=> + float(0.106) + [6]=> + float(0.0001) +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [-10]=> + float(-0.106) + [-8]=> + float(-0.9) + [-3]=> + float(-0.01) + [1]=> + float(0.0001) + [2]=> + float(0.0021) + [4]=> + int(-1) + [5]=> + int(0) + [6]=> + float(0.09) + [7]=> + int(2) + [9]=> + float(0.106) + [11]=> + int(33) +} +Done diff --git a/ext/standard/tests/array/ksort_variation4.phpt b/ext/standard/tests/array/ksort_variation4.phpt new file mode 100644 index 0000000..d6b3f48 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation4.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test ksort() function : usage variations - sort bool values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of boolean values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// bool value array +$bool_values = array (true => true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(ksort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying boolean value array, 'flag' value is defualt -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} + +-- Testing ksort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +Done diff --git a/ext/standard/tests/array/ksort_variation5.phpt b/ext/standard/tests/array/ksort_variation5.phpt new file mode 100644 index 0000000..6e6a38b --- /dev/null +++ b/ext/standard/tests/array/ksort_variation5.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test ksort() function : usage variations - sort strings +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of string values for $array argument with + * following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_STRING - compare items as strings +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +$various_arrays = array ( + // diff. escape sequence chars with key values + array ( null => null, NULL => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "apple", 'te' => "Test", + 't' => "TTTT", 'T' => "ttt", 'W' => "ww", 'X' => "x", 'x' => "X", 'O' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing ksort() by supplying various string arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(ksort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call ksort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(ksort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various string arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\xhh"]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["Apple"]=> + string(5) "apple" + ["B"]=> + string(6) "BANANA" + ["Lemon"]=> + string(5) "lemoN" + ["O"]=> + string(6) "oraNGe" + ["T"]=> + string(3) "ttt" + ["W"]=> + string(2) "ww" + ["X"]=> + string(1) "x" + ["o"]=> + string(6) "Orange" + ["t"]=> + string(4) "TTTT" + ["te"]=> + string(4) "Test" + ["x"]=> + string(1) "X" +} +Done diff --git a/ext/standard/tests/array/ksort_variation6.phpt b/ext/standard/tests/array/ksort_variation6.phpt new file mode 100644 index 0000000..1243ab1 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test ksort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing array of hexa-decimal values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// an array containng unsorted hexadecimal values with keys +// There are multiple keys which are duplicate and the later should be picked +$unsorted_hex_array = array ( + 0x1AB => 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa +); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(ksort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} + +-- Testing ksort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [-682]=> + int(-682) + [-255]=> + int(-255) + [0]=> + int(0) + [15]=> + int(15) + [187]=> + int(187) + [255]=> + int(255) + [427]=> + int(427) + [682]=> + int(682) + [4095]=> + int(4095) +} +Done diff --git a/ext/standard/tests/array/ksort_variation7.phpt b/ext/standard/tests/array/ksort_variation7.phpt new file mode 100644 index 0000000..a0f454b --- /dev/null +++ b/ext/standard/tests/array/ksort_variation7.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test ksort() function : usage variations - sort array with diff. sub arrays +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation + * Source code: ext/standard/array.c +*/ + +/* + * testing ksort() by providing arrays containing sub arrays for $array argument + * with flowing flag values: + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally +*/ + +echo "*** Testing ksort() : usage variations ***\n"; + +// array with diff sub arrays to be sorted +$various_arrays = array ( + // null array + 1 => array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing ksort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test ksort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( ksort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( ksort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(3) { + [1]=> + int(11) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [4]=> + int(44) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [1]=> + int(11) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [4]=> + int(44) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/ext/standard/tests/array/ksort_variation8.phpt b/ext/standard/tests/array/ksort_variation8.phpt Binary files differnew file mode 100644 index 0000000..787e71d --- /dev/null +++ b/ext/standard/tests/array/ksort_variation8.phpt diff --git a/ext/standard/tests/array/ksort_variation9.phpt b/ext/standard/tests/array/ksort_variation9.phpt new file mode 100644 index 0000000..ed406e2 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation9.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test ksort() function : usage variations - sorting arrays with/without keys +--FILE-- +<?php +/* Prototype : bool ksort ( array &$array [, int $sort_flags] ) + * Description: Sort an array by key, maintaining key to data correlation. + * Source code: ext/standard/array.c +*/ + +/* + * Testing ksort() by providing arrays with/without key values for $array argument with following flag values: + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + */ + +echo "*** Testing ksort() : usage variations ***\n"; + +// list of arrays with/without key values +$various_arrays = array ( + array(5 => 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing ksort() by supplying various arrays with/without key values --\n"; + +// loop through to test ksort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( ksort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( ksort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing ksort() : usage variations *** + +-- Testing ksort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(5) { + [5]=> + int(55) + [6]=> + int(66) + [7]=> + int(22) + [8]=> + int(33) + [9]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [5]=> + int(55) + [6]=> + int(66) + [7]=> + int(22) + [8]=> + int(33) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(3) { + [0]=> + string(5) "first" + [1]=> + string(5) "third" + [5]=> + string(6) "second" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + string(5) "first" + [1]=> + string(5) "third" + [5]=> + string(6) "second" +} + +-- Iteration 5 -- +- With defualt sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [9]=> + int(19) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [9]=> + int(19) +} + +-- Iteration 6 -- +- With defualt sort flag - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + ["bar"]=> + string(3) "baz" + ["foo"]=> + int(1) +} + +-- Iteration 7 -- +- With defualt sort flag - +bool(true) +array(4) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["a"]=> + int(1) + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) +} +Done diff --git a/ext/standard/tests/array/locale_sort.phpt b/ext/standard/tests/array/locale_sort.phpt new file mode 100644 index 0000000..1db9604 --- /dev/null +++ b/ext/standard/tests/array/locale_sort.phpt @@ -0,0 +1,62 @@ +--TEST-- +Sort with SORT_LOCALE_STRING +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Unix locale name only, not available on windows (and crashes with VC6)\n"); +} +if (false == setlocale(LC_CTYPE, "fr_FR.ISO8859-1", "fr_FR")) { + die("skip setlocale() failed\n"); +} +?> +--INI-- +unicode.script_encoding=ISO8859-1 +unicode.output_encoding=ISO8859-1 +--FILE-- +<?php +setlocale(LC_ALL, 'fr_FR.ISO8859-1', 'fr_FR'); +$table = array("AB" => "Alberta", +"BC" => "Colombie-Britannique", +"MB" => "Manitoba", +"NB" => "Nouveau-Brunswick", +"NL" => "Terre-Neuve-et-Labrador", +"NS" => "Nouvelle-Écosse", +"ON" => "Ontario", +"PE" => "Île-du-Prince-Édouard", +"QC" => "Québec", +"SK" => "Saskatchewan", +"NT" => "Territoires du Nord-Ouest", +"NU" => "Nunavut", +"YT" => "Territoire du Yukon"); +asort($table, SORT_LOCALE_STRING); +var_dump($table); +?> +--EXPECT-- +array(13) { + ["AB"]=> + string(7) "Alberta" + ["BC"]=> + string(20) "Colombie-Britannique" + ["PE"]=> + string(21) "Île-du-Prince-Édouard" + ["MB"]=> + string(8) "Manitoba" + ["NB"]=> + string(17) "Nouveau-Brunswick" + ["NS"]=> + string(15) "Nouvelle-Écosse" + ["NU"]=> + string(7) "Nunavut" + ["ON"]=> + string(7) "Ontario" + ["QC"]=> + string(6) "Québec" + ["SK"]=> + string(12) "Saskatchewan" + ["NL"]=> + string(23) "Terre-Neuve-et-Labrador" + ["YT"]=> + string(19) "Territoire du Yukon" + ["NT"]=> + string(25) "Territoires du Nord-Ouest" +} diff --git a/ext/standard/tests/array/max.phpt b/ext/standard/tests/array/max.phpt new file mode 100644 index 0000000..555d2d0 --- /dev/null +++ b/ext/standard/tests/array/max.phpt @@ -0,0 +1,41 @@ +--TEST-- +max() tests +--INI-- +precision=14 +--FILE-- +<?php + +var_dump(max()); +var_dump(max(1)); +var_dump(max(array())); +var_dump(max(new stdclass)); +var_dump(max(2,1,2)); +var_dump(max(2.1,2.11,2.09)); +var_dump(max("", "t", "b")); +var_dump(max(false, true, false)); +var_dump(max(true, false, true)); +var_dump(max(1, true, false, true)); +var_dump(max(0, true, false, true)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: max() expects at least 1 parameter, 0 given in %s on line 3 +NULL + +Warning: max(): When only one parameter is given, it must be an array in %s on line 4 +NULL + +Warning: max(): Array must contain at least one element in %s on line 5 +bool(false) + +Warning: max(): When only one parameter is given, it must be an array in %s on line 6 +NULL +int(2) +float(2.11) +string(1) "t" +bool(true) +bool(true) +int(1) +bool(true) +Done diff --git a/ext/standard/tests/array/max_basic.phpt b/ext/standard/tests/array/max_basic.phpt new file mode 100644 index 0000000..f304212 --- /dev/null +++ b/ext/standard/tests/array/max_basic.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test return type and value for expected input max() +--FILE-- +<?php +/* + * proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing sequences of numbers ***\n"; + +var_dump(max(2,1,2)); +var_dump(max(-2,1,2)); +var_dump(max(2.1,2.11,2.09)); +var_dump(max("", "t", "b")); +var_dump(max(false, true, false)); +var_dump(max(true, false, true)); +var_dump(max(1, true, false, true)); +var_dump(max(0, true, false, true)); +var_dump(max(0, 1, array(2,3))); + +echo "\nDone\n"; +?> +--EXPECT-- + +*** Testing sequences of numbers *** +int(2) +int(2) +float(2.11) +string(1) "t" +bool(true) +bool(true) +int(1) +bool(true) +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} + +Done diff --git a/ext/standard/tests/array/max_basiclong_64bit.phpt b/ext/standard/tests/array/max_basiclong_64bit.phpt new file mode 100644 index 0000000..1eb7e31 --- /dev/null +++ b/ext/standard/tests/array/max_basiclong_64bit.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test max function : 64bit long tests +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php + +define("MAX_64Bit", 9223372036854775807); +define("MAX_32Bit", 2147483647); +define("MIN_64Bit", -MAX_64Bit - 1); +define("MIN_32Bit", -MAX_32Bit - 1); + +$arrayVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MIN_64Bit + 1 +); + +$longVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1 +); + + var_dump(max($arrayVals)); + var_dump(max($longVals)); + +?> +===DONE=== +--EXPECT-- +int(9223372036854775807) +int(9223372036854775807) +===DONE=== diff --git a/ext/standard/tests/array/max_error.phpt b/ext/standard/tests/array/max_error.phpt new file mode 100644 index 0000000..b20a3c0 --- /dev/null +++ b/ext/standard/tests/array/max_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test wrong number of arguments for min() +--FILE-- +<?php +/* + * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + + +echo "\n*** Testing Error Conditions ***\n"; + +var_dump(max()); +var_dump(max(1)); +var_dump(max(array())); +var_dump(max(new stdclass)); + +?> +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: max() expects at least 1 parameter, 0 given in %s on line 10 +NULL + +Warning: max(): When only one parameter is given, it must be an array in %s on line 11 +NULL + +Warning: max(): Array must contain at least one element in %s on line 12 +bool(false) + +Warning: max(): When only one parameter is given, it must be an array in %s on line 13 +NULL diff --git a/ext/standard/tests/array/max_variation1.phpt b/ext/standard/tests/array/max_variation1.phpt new file mode 100644 index 0000000..a32ceb8 --- /dev/null +++ b/ext/standard/tests/array/max_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test variations in usage of max() +--FILE-- +<?php +/* + * proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing boundary conditions ***\n"; +var_dump(max(2147483645, 2147483646) ); +var_dump(max(2147483647, 2147483648) ); +var_dump(max(2147483646, 2147483648) ); +var_dump(max(-2147483647, -2147483646) ); +var_dump(max(-2147483648, -2147483647) ); +var_dump(max(-2147483649, -2147483647) ); + +echo "\n*** Testing large number of arguments ***\n"; + +var_dump(max(0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,21)); + +echo "\nDone\n"; +?> +--EXPECTF-- + +*** Testing boundary conditions *** +int(2147483646) +%s(2147483648) +%s(2147483648) +int(-2147483646) +int(-2147483647) +int(-2147483647) + +*** Testing large number of arguments *** +int(21) + +Done diff --git a/ext/standard/tests/array/max_variation2.phpt b/ext/standard/tests/array/max_variation2.phpt new file mode 100644 index 0000000..9abcda5 --- /dev/null +++ b/ext/standard/tests/array/max_variation2.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test variations in usage of max() +--FILE-- +<?php +/* + * proto mixed max(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing arrays ***\n"; + +var_dump(max(array(2,1,2))); +var_dump(max(array(-2,1,2))); +var_dump(max(array(2.1,2.11,2.09))); +var_dump(max(array("", "t", "b"))); +var_dump(max(array(false, true, false))); +var_dump(max(array(true, false, true))); +var_dump(max(array(1, true, false, true))); +var_dump(max(array(0, true, false, true))); +var_dump(max(array(0, 1, array(2,3)))); +var_dump(max(array(2147483645, 2147483646))); +var_dump(max(array(2147483647, 2147483648))); +var_dump(max(array(2147483646, 2147483648))); +var_dump(max(array(-2147483647, -2147483646))); +var_dump(max(array(-2147483648, -2147483647))); +var_dump(max(array(-2147483649, -2147483647))); + +echo "\nDone\n"; + +?> +--EXPECTF-- + +*** Testing arrays *** +int(2) +int(2) +float(2.11) +string(1) "t" +bool(true) +bool(true) +int(1) +bool(true) +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +int(2147483646) +%s(2147483648) +%s(2147483648) +int(-2147483646) +int(-2147483647) +int(-2147483647) + +Done diff --git a/ext/standard/tests/array/min.phpt b/ext/standard/tests/array/min.phpt new file mode 100644 index 0000000..3a77ee8 --- /dev/null +++ b/ext/standard/tests/array/min.phpt @@ -0,0 +1,41 @@ +--TEST-- +min() tests +--INI-- +precision=14 +--FILE-- +<?php + +var_dump(min()); +var_dump(min(1)); +var_dump(min(array())); +var_dump(min(new stdclass)); +var_dump(min(2,1,2)); +var_dump(min(2.1,2.11,2.09)); +var_dump(min("", "t", "b")); +var_dump(min(false, true, false)); +var_dump(min(true, false, true)); +var_dump(min(1, true, false, true)); +var_dump(min(0, true, false, true)); + +echo "Done\n"; +?> +--EXPECTF-- +Warning: min() expects at least 1 parameter, 0 given in %s on line 3 +NULL + +Warning: min(): When only one parameter is given, it must be an array in %s on line 4 +NULL + +Warning: min(): Array must contain at least one element in %s on line 5 +bool(false) + +Warning: min(): When only one parameter is given, it must be an array in %s on line 6 +NULL +int(1) +float(2.09) +string(0) "" +bool(false) +bool(false) +bool(false) +int(0) +Done diff --git a/ext/standard/tests/array/min_basic.phpt b/ext/standard/tests/array/min_basic.phpt new file mode 100644 index 0000000..34f853f --- /dev/null +++ b/ext/standard/tests/array/min_basic.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test return type and value for expected input min() +--FILE-- +<?php +/* + * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing sequences of numbers ***\n"; + +var_dump(min(2,1,2)); +var_dump(min(-2,1,2)); +var_dump(min(2.1,2.11,2.09)); +var_dump(min("", "t", "b")); +var_dump(min(false, true, false)); +var_dump(min(true, false, true)); +var_dump(min(1, true, false, true)); +var_dump(min(0, true, false, true)); +var_dump(min(0, 1, array(2,3))); + +echo "\nDone\n"; +?> +--EXPECT-- + +*** Testing sequences of numbers *** +int(1) +int(-2) +float(2.09) +string(0) "" +bool(false) +bool(false) +bool(false) +int(0) +int(0) + +Done diff --git a/ext/standard/tests/array/min_basiclong_64bit.phpt b/ext/standard/tests/array/min_basiclong_64bit.phpt new file mode 100644 index 0000000..52f63f3 --- /dev/null +++ b/ext/standard/tests/array/min_basiclong_64bit.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test min function : 64bit long tests +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php + +define("MAX_64Bit", 9223372036854775807); +define("MAX_32Bit", 2147483647); +define("MIN_64Bit", -MAX_64Bit - 1); +define("MIN_32Bit", -MAX_32Bit - 1); + +$arrayVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MIN_64Bit + 1 +); + +$longVals = array( + MAX_64Bit, MIN_64Bit, MAX_32Bit, MIN_32Bit, MAX_64Bit - MAX_32Bit, MIN_64Bit - MIN_32Bit, + MAX_32Bit + 1, MIN_32Bit - 1, MAX_32Bit * 2, (MAX_32Bit * 2) + 1, (MAX_32Bit * 2) - 1, + MAX_64Bit -1, MAX_64Bit + 1, MIN_64Bit + 1, MIN_64Bit - 1 +); + + var_dump(min($arrayVals)); + var_dump(min($longVals)); + +?> +===DONE=== +--EXPECT-- +int(-9223372036854775808) +int(-9223372036854775808) +===DONE=== diff --git a/ext/standard/tests/array/min_error.phpt b/ext/standard/tests/array/min_error.phpt new file mode 100644 index 0000000..dc472bc --- /dev/null +++ b/ext/standard/tests/array/min_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test wrong number of arguments for min() +--FILE-- +<?php +/* + * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + + +echo "\n*** Testing Error Conditions ***\n"; + +var_dump(min()); +var_dump(min(1)); +var_dump(min(array())); +var_dump(min(new stdclass)); + +?> +--EXPECTF-- +*** Testing Error Conditions *** + +Warning: min() expects at least 1 parameter, 0 given in %s on line 10 +NULL + +Warning: min(): When only one parameter is given, it must be an array in %s on line 11 +NULL + +Warning: min(): Array must contain at least one element in %s on line 12 +bool(false) + +Warning: min(): When only one parameter is given, it must be an array in %s on line 13 +NULL diff --git a/ext/standard/tests/array/min_variation1.phpt b/ext/standard/tests/array/min_variation1.phpt new file mode 100644 index 0000000..9e24bd6 --- /dev/null +++ b/ext/standard/tests/array/min_variation1.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test variations in usage of min() +--FILE-- +<?php +/* + * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing boundary conditions ***\n"; +var_dump(min(2147483645, 2147483646) ); +var_dump(min(2147483647, 2147483648) ); +var_dump(min(2147483646, 2147483648) ); +var_dump(min(-2147483647, -2147483646) ); +var_dump(min(-2147483648, -2147483647) ); +var_dump(min(-2147483649, -2147483647) ); + +echo "\n*** Testing large number of arguments ***\n"; + +var_dump(min(0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,0, 1 , 2, 3, 4, 5, 6, 7, 8, 9, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,21)); + +echo "\nDone\n"; +?> +--EXPECTF-- + +*** Testing boundary conditions *** +int(2147483645) +int(2147483647) +int(2147483646) +int(-2147483647) +%s(-2147483648) +%s(-2147483649) + +*** Testing large number of arguments *** +int(0) + +Done diff --git a/ext/standard/tests/array/min_variation2.phpt b/ext/standard/tests/array/min_variation2.phpt new file mode 100644 index 0000000..a8b2152 --- /dev/null +++ b/ext/standard/tests/array/min_variation2.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test variations in usage of min() +--FILE-- +<?php +/* + * proto mixed min(mixed arg1 [, mixed arg2 [, mixed ...]]) + * Function is implemented in ext/standard/array.c +*/ + +echo "\n*** Testing arrays ***\n"; + +var_dump(min(array(2,1,2))); +var_dump(min(array(-2,1,2))); +var_dump(min(array(2.1,2.11,2.09))); +var_dump(min(array("", "t", "b"))); +var_dump(min(array(false, true, false))); +var_dump(min(array(true, false, true))); +var_dump(min(array(1, true, false, true))); +var_dump(min(array(0, true, false, true))); +var_dump(min(array(0, 1, array(2,3)))); +var_dump(min(array(2147483645, 2147483646))); +var_dump(min(array(2147483647, 2147483648))); +var_dump(min(array(2147483646, 2147483648))); +var_dump(min(array(-2147483647, -2147483646))); +var_dump(min(array(-2147483648, -2147483647))); +var_dump(min(array(-2147483649, -2147483647))); + +echo "\nDone\n"; + +?> +--EXPECTF-- + +*** Testing arrays *** +int(1) +int(-2) +float(2.09) +string(0) "" +bool(false) +bool(false) +bool(false) +int(0) +int(0) +int(2147483645) +int(2147483647) +int(2147483646) +int(-2147483647) +%s(-2147483648) +%s(-2147483649) + +Done diff --git a/ext/standard/tests/array/natcasesort_basic.phpt b/ext/standard/tests/array/natcasesort_basic.phpt new file mode 100644 index 0000000..cf6cc57 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_basic.phpt @@ -0,0 +1,57 @@ +--TEST-- +Test natcasesort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of natcasesort() + */ + +echo "*** Testing natcasesort() : basic functionality ***\n"; + +$array = array ('A01', 'a1', 'b10', 'a01', 'b01'); +echo "\n-- Before sorting: --\n"; +var_dump($array); + +echo "\n-- After Sorting: --\n"; +var_dump(natcasesort($array)); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : basic functionality *** + +-- Before sorting: -- +array(5) { + [0]=> + string(3) "A01" + [1]=> + string(2) "a1" + [2]=> + string(3) "b10" + [3]=> + string(3) "a01" + [4]=> + string(3) "b01" +} + +-- After Sorting: -- +bool(true) +array(5) { + [3]=> + string(3) "a01" + [0]=> + string(3) "A01" + [1]=> + string(2) "a1" + [4]=> + string(3) "b01" + [2]=> + string(3) "b10" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_error.phpt b/ext/standard/tests/array/natcasesort_error.phpt new file mode 100644 index 0000000..9ae8691 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test natcasesort() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to natcasesort() to test behaviour + */ + +echo "*** Testing natcasesort() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing natcasesort() function with Zero arguments --\n"; +var_dump( natcasesort() ); + +// Test natcasesort with one more than the expected number of arguments +echo "\n-- Testing natcasesort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( natcasesort($array_arg, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : error conditions *** + +-- Testing natcasesort() function with Zero arguments -- + +Warning: natcasesort() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing natcasesort() function with more than expected no. of arguments -- + +Warning: natcasesort() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_object1.phpt b/ext/standard/tests/array/natcasesort_object1.phpt new file mode 100644 index 0000000..aab98a4 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_object1.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test natcasesort() function : object functionality - array of objects +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass natcasesort() an array of objects to test how it re-orders them + */ + +echo "*** Testing natcasesort() : object functionality ***\n"; + +// class declaration for string objects +class for_string_natcasesort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->class_value; + } + +} + + + +// array of string objects +$unsorted_str_obj = array ( + new for_string_natcasesort("axx"), new for_string_natcasesort("t"), + new for_string_natcasesort("w"), new for_string_natcasesort("py"), + new for_string_natcasesort("apple"), new for_string_natcasesort("Orange"), + new for_string_natcasesort("Lemon"), new for_string_natcasesort("aPPle") +); + + +echo "\n-- Testing natcasesort() by supplying various object arrays --\n"; + +// testing natcasesort() function by supplying string object array +var_dump(natcasesort($unsorted_str_obj) ); +var_dump($unsorted_str_obj); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : object functionality *** + +-- Testing natcasesort() by supplying various object arrays -- +bool(true) +array(8) { + [4]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [7]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [0]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [6]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [5]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [3]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [1]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_natcasesort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_object2.phpt b/ext/standard/tests/array/natcasesort_object2.phpt new file mode 100644 index 0000000..38efefc --- /dev/null +++ b/ext/standard/tests/array/natcasesort_object2.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test natcasesort() function : object functionality - mixed visibility within objects +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass natcasesort() an array of objects which have properties of different + * visibilities to test how it re-orders the array. + */ + +echo "*** Testing natcasesort() : object functionality ***\n"; + +// class declaration for string objects +class for_string_natcasesort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->public_class_value; + } + +} + +// array of string objects +$unsorted_str_obj = array ( +new for_string_natcasesort("axx","AXX","ass"), +new for_string_natcasesort("t","eee","abb"), +new for_string_natcasesort("w","W", "c"), +new for_string_natcasesort("py","PY", "pt"), +); + + +echo "\n-- Testing natcasesort() by supplying object arrays --\n"; + +// testing natcasesort() function by supplying string object array +$temp_array = $unsorted_str_obj; +var_dump(natcasesort($temp_array) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : object functionality *** + +-- Testing natcasesort() by supplying object arrays -- +bool(true) +array(4) { + [0]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_natcasesort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } + [3]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_natcasesort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [1]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_natcasesort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [2]=> + object(for_string_natcasesort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_natcasesort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation1.phpt b/ext/standard/tests/array/natcasesort_variation1.phpt new file mode 100644 index 0000000..59eaded --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation1.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test natcasesort() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to natcasesort() to test behaviour + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- + +Warning: natcasesort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: natcasesort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: natcasesort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: natcasesort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: natcasesort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: natcasesort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: natcasesort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: natcasesort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: natcasesort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: natcasesort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: natcasesort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: natcasesort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: natcasesort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: natcasesort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: natcasesort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: natcasesort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: natcasesort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(true) + +-- Iteration 19 -- + +Warning: natcasesort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: natcasesort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: natcasesort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: natcasesort() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: natcasesort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: natcasesort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: natcasesort() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done + diff --git a/ext/standard/tests/array/natcasesort_variation10.phpt b/ext/standard/tests/array/natcasesort_variation10.phpt new file mode 100644 index 0000000..cffa007 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation10.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test natcasesort() function : usage variations - position of internal array pointer +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Check position of internal array pointer after calling natcasesort() + */ + +echo "*** Testing natcasesort() : usage variations ***\n"; + +$array_arg = array ('img13', 'img20', 'img2', 'img1'); + +echo "\n-- Initial Position of Internal Pointer: --\n"; +echo key($array_arg) . " => " . current ($array_arg) . "\n"; + +echo "\n-- Call natcasesort() --\n"; +var_dump(natcasesort($array_arg)); +var_dump($array_arg); + +echo "\n-- Position of Internal Pointer in Passed Array: --\n"; +echo key($array_arg) . " => " . current ($array_arg) . "\n"; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variations *** + +-- Initial Position of Internal Pointer: -- +0 => img13 + +-- Call natcasesort() -- +bool(true) +array(4) { + [3]=> + string(4) "img1" + [2]=> + string(4) "img2" + [0]=> + string(5) "img13" + [1]=> + string(5) "img20" +} + +-- Position of Internal Pointer in Passed Array: -- +3 => img1 +Done diff --git a/ext/standard/tests/array/natcasesort_variation11.phpt b/ext/standard/tests/array/natcasesort_variation11.phpt new file mode 100644 index 0000000..98158f1 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation11.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test natcasesort() function : usage variations - Different array keys +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays where the keys are different data types to test behaviour of natcasesort() + */ + +echo "*** Testing natcasesort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// arrays with keys as different data types to be passed as $array_arg +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0 => 'zero', + 1 => 'one', + 12345 => 'positive', + -2345 => 'negative', + ), + + // float data +/*2*/ 'float' => array( + 10.5 => 'positive', + -10.5 => 'negative', + .5 => 'half', + ), + +/*3*/ 'extreme floats' => array( + 12.3456789000e6 => 'large', + 12.3456789000E-10 => 'small', + ), + + // null data +/*4*/ 'null uppercase' => array( + NULL => 'null 1', + ), + +/*5*/ 'null lowercase' => array( + null => 'null 2', + ), + + // boolean data +/*6*/ 'bool lowercase' => array( + true => 'lowert', + false => 'lowerf', + ), + +/*7*/ 'bool uppercase' => array( + TRUE => 'uppert', + FALSE => 'upperf', + ), + + // empty data +/*8*/ 'empty double quotes' => array( + "" => 'emptyd', + ), + +/*9*/ 'empty single quotes' => array( + '' => 'emptys', + ), + + // string data +/*10*/ 'string' => array( + "stringd" => 'stringd', + 'strings' => 'strings', + $heredoc => 'stringh', + ), + + // undefined data +/*11*/ 'undefined' => array( + @$undefined_var => 'undefined', + ), + + // unset data +/*12*/ 'unset' => array( + @$unset_var => 'unset', + ), + + // duplicate values +/*13*/ 'duplicate' => array( + 'foo' => 'bar', + 'baz' => 'bar', + 'hello' => 'world' + ), + +); + +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + var_dump($input); + $iterator++; +}; + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variations *** + +-- Iteration 1 -- +bool(true) +array(4) { + [-2345]=> + string(8) "negative" + [1]=> + string(3) "one" + [12345]=> + string(8) "positive" + [0]=> + string(4) "zero" +} + +-- Iteration 2 -- +bool(true) +array(3) { + [0]=> + string(4) "half" + [-10]=> + string(8) "negative" + [10]=> + string(8) "positive" +} + +-- Iteration 3 -- +bool(true) +array(2) { + [12345678]=> + string(5) "large" + [0]=> + string(5) "small" +} + +-- Iteration 4 -- +bool(true) +array(1) { + [""]=> + string(6) "null 1" +} + +-- Iteration 5 -- +bool(true) +array(1) { + [""]=> + string(6) "null 2" +} + +-- Iteration 6 -- +bool(true) +array(2) { + [0]=> + string(6) "lowerf" + [1]=> + string(6) "lowert" +} + +-- Iteration 7 -- +bool(true) +array(2) { + [0]=> + string(6) "upperf" + [1]=> + string(6) "uppert" +} + +-- Iteration 8 -- +bool(true) +array(1) { + [""]=> + string(6) "emptyd" +} + +-- Iteration 9 -- +bool(true) +array(1) { + [""]=> + string(6) "emptys" +} + +-- Iteration 10 -- +bool(true) +array(3) { + ["stringd"]=> + string(7) "stringd" + ["hello world"]=> + string(7) "stringh" + ["strings"]=> + string(7) "strings" +} + +-- Iteration 11 -- +bool(true) +array(1) { + [""]=> + string(9) "undefined" +} + +-- Iteration 12 -- +bool(true) +array(1) { + [""]=> + string(5) "unset" +} + +-- Iteration 13 -- +bool(true) +array(3) { + ["foo"]=> + string(3) "bar" + ["baz"]=> + string(3) "bar" + ["hello"]=> + string(5) "world" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation2.phpt b/ext/standard/tests/array/natcasesort_variation2.phpt new file mode 100644 index 0000000..00edf94 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation2.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test natcasesort() function : usage variations - Pass arrays of different data types +--FILE-- +<?php + +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of different data types to natcasesort() to test how they are sorted + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 'int' => array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); +// loop through each element of $inputs to check the behavior of natcasesort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( natcasesort($input) ); + var_dump($input); + $iterator++; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- +bool(true) +array(4) { + [3]=> + int(-2345) + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(12345) +} + +-- Iteration 2 -- +bool(true) +array(5) { + [1]=> + float(-10.5) + [4]=> + float(0.5) + [3]=> + float(1.23456789E-9) + [0]=> + float(10.5) + [2]=> + float(123456789000) +} + +-- Iteration 3 -- +bool(true) +array(2) { + [1]=> + NULL + [0]=> + NULL +} + +-- Iteration 4 -- +bool(true) +array(4) { + [3]=> + bool(false) + [1]=> + bool(false) + [0]=> + bool(true) + [2]=> + bool(true) +} + +-- Iteration 5 -- +bool(true) +array(2) { + [1]=> + string(0) "" + [0]=> + string(0) "" +} + +-- Iteration 6 -- +bool(true) +array(0) { +} + +-- Iteration 7 -- +bool(true) +array(3) { + [2]=> + string(11) "hello world" + [1]=> + string(6) "string" + [0]=> + string(6) "string" +} + +-- Iteration 8 -- +bool(true) +array(1) { + [0]=> + object(classA)#%d (0) { + } +} + +-- Iteration 9 -- +bool(true) +array(1) { + [0]=> + NULL +} + +-- Iteration 10 -- +bool(true) +array(1) { + [0]=> + NULL +} + +-- Iteration 11 -- +bool(true) +array(1) { + [0]=> + resource(%d) of type (stream) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation3.phpt b/ext/standard/tests/array/natcasesort_variation3.phpt new file mode 100644 index 0000000..77f83e1 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation3.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test natcasesort() function : usage variations - different numeric types +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of numeric data to test how natcasesort re-orders the array + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$inputs = array ( + + // negative/positive integers array + array(11, -11, 21, -21, 31, -31, 0, 41, -41), + + // float value array + array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1), + + // mixed value array + array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33), + + // array values contains minimum and maximum ranges + array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649) +); + +$iterator = 1; +foreach ($inputs as $array_arg) { + echo "\n-- Iteration $iterator --\n"; + var_dump(natcasesort($array_arg)); + var_dump($array_arg); +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Iteration 1 -- +bool(true) +array(9) { + [1]=> + int(-11) + [3]=> + int(-21) + [5]=> + int(-31) + [8]=> + int(-41) + [6]=> + int(0) + [0]=> + int(11) + [2]=> + int(21) + [4]=> + int(31) + [7]=> + int(41) +} + +-- Iteration 1 -- +bool(true) +array(7) { + [6]=> + float(-0.1) + [1]=> + float(-10.5) + [5]=> + float(0.01) + [4]=> + float(0.5) + [3]=> + float(0.106) + [0]=> + float(10.5) + [2]=> + float(1050) +} + +-- Iteration 1 -- +bool(true) +array(11) { + [2]=> + float(-0.01) + [7]=> + float(-0.9) + [9]=> + float(-0.106) + [3]=> + int(-1) + [4]=> + int(0) + [0]=> + float(0.0001) + [1]=> + float(0.0021) + [5]=> + float(0.09) + [8]=> + float(0.106) + [6]=> + int(2) + [10]=> + int(33) +} + +-- Iteration 1 -- +bool(true) +array(7) { + [2]=> + int(-2147483647) + [3]=> + float(-2147483648) + [6]=> + float(-2147483649) + [5]=> + int(0) + [4]=> + int(0) + [0]=> + int(2147483647) + [1]=> + float(2147483648) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation4.phpt b/ext/standard/tests/array/natcasesort_variation4.phpt new file mode 100644 index 0000000..c7f99e1 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation4.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test natcasesort() function : usage variations - different string types +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of string data to see how natcasesort() re-orders the array + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$inputs = array ( + // group of escape sequences + array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"), + + // array contains combination of capital/small letters + array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA") +); + +foreach ($inputs as $array_arg) { + var_dump( natcasesort($array_arg) ); + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(11) { + [0]=> + NULL + [1]=> + NULL + [6]=> + string(1) " +" + [10]=> + string(1) "" + [7]=> + string(1) " " + [5]=> + string(1) "" + [4]=> + string(1) "" + [2]=> + string(2) "\a" + [3]=> + string(3) "\cx" + [9]=> + string(4) "\ddd" + [8]=> + string(4) "\xhh" +} +bool(true) +array(12) { + [3]=> + string(5) "apple" + [11]=> + string(6) "BANANA" + [2]=> + string(6) "banana" + [0]=> + string(5) "lemoN" + [10]=> + string(6) "oraNGe" + [1]=> + string(6) "Orange" + [4]=> + string(4) "Test" + [6]=> + string(3) "ttt" + [5]=> + string(4) "TTTT" + [7]=> + string(2) "ww" + [8]=> + string(1) "x" + [9]=> + string(1) "X" +} +Done diff --git a/ext/standard/tests/array/natcasesort_variation5.phpt b/ext/standard/tests/array/natcasesort_variation5.phpt new file mode 100644 index 0000000..867d0b8 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation5.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test natcasesort() function : usage variations - different hex values +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of different hex values to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa); +var_dump( natcasesort($unsorted_hex_array) ); +var_dump($unsorted_hex_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(11) { + [8]=> + int(-255) + [10]=> + int(-682) + [9]=> + int(0) + [2]=> + int(15) + [5]=> + int(187) + [3]=> + int(255) + [7]=> + int(255) + [0]=> + int(427) + [6]=> + int(427) + [4]=> + int(682) + [1]=> + int(4095) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation6.phpt b/ext/standard/tests/array/natcasesort_variation6.phpt new file mode 100644 index 0000000..1d151d8 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation6.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test natcasesort() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of referenced varaibles to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +echo "\n-- Initial test --\n"; +$array = array( &$value1 , &$value2, &$value3); +var_dump( natcasesort($array) ); +var_dump($array); + +echo "\n-- Change \$value1 --\n"; +$value1 = -29; +var_dump( natcasesort($array) ); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** + +-- Initial test -- +bool(true) +array(3) { + [1]=> + &int(33) + [0]=> + &int(100) + [2]=> + &int(555) +} + +-- Change $value1 -- +bool(true) +array(3) { + [0]=> + &int(-29) + [1]=> + &int(33) + [2]=> + &int(555) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation7.phpt b/ext/standard/tests/array/natcasesort_variation7.phpt new file mode 100644 index 0000000..91be7e2 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation7.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test natcasesort() function : usage variations - recursive arrays +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass natcasesort() an infinitely recursive array to test how it is re-ordered + */ + +echo "*** Testing natcasesort() : usage variations ***\n"; + +$array = array (1, 3.00, 'zero', '2'); +$array[] = &$array; +var_dump($array); + +var_dump(@natcasesort($array)); +var_dump($array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variations *** +array(5) { + [0]=> + int(1) + [1]=> + float(3) + [2]=> + string(4) "zero" + [3]=> + string(1) "2" + [4]=> + &array(5) { + [0]=> + int(1) + [1]=> + float(3) + [2]=> + string(4) "zero" + [3]=> + string(1) "2" + [4]=> + *RECURSION* + } +} +bool(true) +array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + &array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + *RECURSION* + [2]=> + string(4) "zero" + } + [2]=> + string(4) "zero" +} +Done diff --git a/ext/standard/tests/array/natcasesort_variation8.phpt b/ext/standard/tests/array/natcasesort_variation8.phpt new file mode 100644 index 0000000..fbced4a --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation8.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test natcasesort() function : usage variations - octal values +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of octal values to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$unsorted_oct_array = array(01235, 0321, 0345, 066, 0772, 077, -066, -0345, 0); + +var_dump( natcasesort($unsorted_oct_array) ); +var_dump($unsorted_oct_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(9) { + [6]=> + int(-54) + [7]=> + int(-229) + [8]=> + int(0) + [3]=> + int(54) + [5]=> + int(63) + [1]=> + int(209) + [2]=> + int(229) + [4]=> + int(506) + [0]=> + int(669) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation9.phpt b/ext/standard/tests/array/natcasesort_variation9.phpt new file mode 100644 index 0000000..98eec05 --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation9.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test natcasesort() function : usage variations - mixed array +--FILE-- +<?php +/* Prototype : bool natcasesort(array &$array_arg) + * Description: Sort an array using case-insensitive natural sort + * Source code: ext/standard/array.c + */ + +/* + * Pass an array containing sub-arrays, ints, floats, strings, boolean, null + * and escape characters to test how natcasesort() re-orders it + */ + +echo "*** Testing natcasesort() : usage variation ***\n"; + +$mixed_values = array ( + array(), + array( array(33, -5, 6), + array(11), + array(22, -55), + array() + ), + -4, "4", 4.00, "b", "5", -2, -2.0, -2.98989, "-.9", "True", "", + NULL, "ab", "abcd", 0.0, -0, "abcd\x00abcd\x00abcd", '', true, false +); +// suppress errors as is generating a lot of "array to string" notices +var_dump( @natcasesort($mixed_values) ); + +var_dump($mixed_values); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing natcasesort() : usage variation *** +bool(true) +array(22) { + [13]=> + NULL + [19]=> + string(0) "" + [21]=> + bool(false) + [12]=> + string(0) "" + [10]=> + string(3) "-.9" + [7]=> + int(-2) + [8]=> + float(-2) + [9]=> + float(-2.98989) + [2]=> + int(-4) + [16]=> + float(0) + [17]=> + int(0) + [20]=> + bool(true) + [3]=> + string(1) "4" + [4]=> + float(4) + [6]=> + string(1) "5" + [14]=> + string(2) "ab" + [15]=> + string(4) "abcd" + [18]=> + string(14) "%s" + [0]=> + array(0) { + } + [1]=> + array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(0) { + } + } + [5]=> + string(1) "b" + [11]=> + string(4) "True" +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natsort_basic.phpt b/ext/standard/tests/array/natsort_basic.phpt new file mode 100644 index 0000000..e38359f --- /dev/null +++ b/ext/standard/tests/array/natsort_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test natsort(): basic functionality +--FILE-- +<?php +/* +* proto bool natsort ( array &$array ) +* Function is implemented in ext/standard/array.c +*/ +$array1 = $array2 = array("img12.png", "img10.png", "img2.png", "img1.png"); +sort($array1); +echo "Standard sorting\n"; +print_r($array1); +natsort($array2); +echo "\nNatural order sorting\n"; +print_r($array2); +?> +--EXPECT-- +Standard sorting +Array +( + [0] => img1.png + [1] => img10.png + [2] => img12.png + [3] => img2.png +) + +Natural order sorting +Array +( + [3] => img1.png + [2] => img2.png + [1] => img10.png + [0] => img12.png +) + diff --git a/ext/standard/tests/array/next_basic.phpt b/ext/standard/tests/array/next_basic.phpt new file mode 100644 index 0000000..fe8b70c --- /dev/null +++ b/ext/standard/tests/array/next_basic.phpt @@ -0,0 +1,35 @@ +--TEST-- +Test next() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of next() + */ + +echo "*** Testing next() : basic functionality ***\n"; + +$array = array('zero', 'one', 'two'); +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(next($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : basic functionality *** +0 => zero +string(3) "one" +1 => one +string(3) "two" +2 => two +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/next_error.phpt b/ext/standard/tests/array/next_error.phpt new file mode 100644 index 0000000..f7b7835 --- /dev/null +++ b/ext/standard/tests/array/next_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test next() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to next() to test behaviour + */ + +echo "*** Testing next() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing next() function with Zero arguments --\n"; +var_dump( next() ); + +//Test next with one more than the expected number of arguments +echo "\n-- Testing next() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( next($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : error conditions *** + +-- Testing next() function with Zero arguments -- + +Warning: next() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing next() function with more than expected no. of arguments -- + +Warning: next() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/next_variation1.phpt b/ext/standard/tests/array/next_variation1.phpt new file mode 100644 index 0000000..5f477b4 --- /dev/null +++ b/ext/standard/tests/array/next_variation1.phpt @@ -0,0 +1,219 @@ +--TEST-- +Test next() function : usage variation - Pass different data types as $array_arg +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to next() to test behaviour + */ + +echo "*** Testing next() : variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of next() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( next($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : variation *** + +-- Iteration 1 -- + +Warning: next() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: next() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: next() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: next() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: next() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: next() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: next() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: next() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: next() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: next() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: next() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: next() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: next() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: next() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: next() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: next() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: next() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: next() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: next() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: next() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: next() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: next() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: next() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/next_variation2.phpt b/ext/standard/tests/array/next_variation2.phpt new file mode 100644 index 0000000..e750509 --- /dev/null +++ b/ext/standard/tests/array/next_variation2.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test next() function : usage variation - Mulit-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed next(array $array_arg) + * Description: Move array argument's internal pointer to the next element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test next() when passed: + * 1. a two-dimensional array + * 2. a sub-array + * as $array_arg argument. + */ + +echo "*** Testing next() : usage variations ***\n"; + +$array_arg = array ('a' => 'z', array(9, 8, 7)); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(next($array_arg)); +var_dump(next($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(next($array_arg[0])); +?> +===DONE=== +--EXPECTF-- +*** Testing next() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} +bool(false) + +-- Pass a sub-array as $array_arg -- +int(8) +===DONE=== diff --git a/ext/standard/tests/array/prev_basic.phpt b/ext/standard/tests/array/prev_basic.phpt new file mode 100644 index 0000000..8c1450d --- /dev/null +++ b/ext/standard/tests/array/prev_basic.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test prev() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of prev() + */ + +echo "*** Testing prev() : basic functionality ***\n"; + +$array = array('zero', 'one', 'two'); +end($array); +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo key($array) . " => " . current($array) . "\n"; +var_dump(prev($array)); + +echo "\n*** Testing an array with differing values/keys ***\n"; +$array2 = array('one', 2 => "help", 3, false, 'stringkey2' => 'val2', 'stringkey1' => 'val1'); +end($array2); +$length = count($array2); +for ($i = $length; $i > 0; $i--) { + var_dump(prev($array2)); +} + +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : basic functionality *** +2 => two +string(3) "one" +1 => one +string(4) "zero" +0 => zero +bool(false) + +*** Testing an array with differing values/keys *** +string(4) "val2" +bool(false) +int(3) +string(4) "help" +string(3) "one" +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/prev_error1.phpt b/ext/standard/tests/array/prev_error1.phpt new file mode 100644 index 0000000..bea2451 --- /dev/null +++ b/ext/standard/tests/array/prev_error1.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test prev() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to prev() to test behaviour + */ + +echo "*** Testing prev() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing prev() function with Zero arguments --\n"; +var_dump( prev() ); + +//Test prev with one more than the expected number of arguments +echo "\n-- Testing prev() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( prev($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : error conditions *** + +-- Testing prev() function with Zero arguments -- + +Warning: prev() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing prev() function with more than expected no. of arguments -- + +Warning: prev() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/prev_error2.phpt b/ext/standard/tests/array/prev_error2.phpt new file mode 100644 index 0000000..f26bdd0 --- /dev/null +++ b/ext/standard/tests/array/prev_error2.phpt @@ -0,0 +1,28 @@ +--TEST-- +prev - ensure warning is received when passing an indirect temporary. +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass temporary variables to prev() to test behaviour + */ + +function f() { + $array = array(1,2); + end($array); + return $array; +} + +echo "\n-- Passing an indirect temporary variable --\n"; +var_dump(prev(f())); + +?> +--EXPECTF-- +-- Passing an indirect temporary variable -- + +Strict Standards: Only variables should be passed by reference in %s on line %d +int(1) diff --git a/ext/standard/tests/array/prev_error3.phpt b/ext/standard/tests/array/prev_error3.phpt new file mode 100644 index 0000000..dfac24e --- /dev/null +++ b/ext/standard/tests/array/prev_error3.phpt @@ -0,0 +1,19 @@ +--TEST-- +prev - ensure we cannot pass a temporary +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass temporary variables to prev() to test behaviour + */ + + +var_dump(prev(array(1, 2))); +?> +--EXPECTF-- + +Fatal error: Only variables can be passed by reference in %s on line %d
\ No newline at end of file diff --git a/ext/standard/tests/array/prev_variation1.phpt b/ext/standard/tests/array/prev_variation1.phpt new file mode 100644 index 0000000..5a62536 --- /dev/null +++ b/ext/standard/tests/array/prev_variation1.phpt @@ -0,0 +1,219 @@ +--TEST-- +Test prev() function : usage variation - Pass different data types as $array_arg +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to prev() to test behaviour + */ + +echo "*** Testing prev() : variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of prev() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( prev($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : variation *** + +-- Iteration 1 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: prev() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: prev() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: prev() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: prev() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: prev() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: prev() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/prev_variation2.phpt b/ext/standard/tests/array/prev_variation2.phpt new file mode 100644 index 0000000..0ce0877 --- /dev/null +++ b/ext/standard/tests/array/prev_variation2.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test prev() function : usage variation - Multi-dimensional arrays +--FILE-- +<?php +/* Prototype : mixed prev(array $array_arg) + * Description: Move array argument's internal pointer to the previous element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test prev() when passed: + * 1. a two-dimensional array + * 2. a sub-array + * as $array_arg argument. + */ + +echo "*** Testing prev() : usage variations ***\n"; + +$subarray = array(9,8,7); +end($subarray); + +$array_arg = array ($subarray, 'a' => 'z'); +end($array_arg); + +echo "\n-- Pass a two-dimensional array as \$array_arg --\n"; +var_dump(prev($array_arg)); +var_dump(prev($array_arg)); + +echo "\n-- Pass a sub-array as \$array_arg --\n"; +var_dump(prev($array_arg[0])); +?> +===DONE=== +--EXPECTF-- +*** Testing prev() : usage variations *** + +-- Pass a two-dimensional array as $array_arg -- +array(3) { + [0]=> + int(9) + [1]=> + int(8) + [2]=> + int(7) +} +bool(false) + +-- Pass a sub-array as $array_arg -- +int(8) +===DONE=== diff --git a/ext/standard/tests/array/range.phpt b/ext/standard/tests/array/range.phpt new file mode 100644 index 0000000..9fd0f5e --- /dev/null +++ b/ext/standard/tests/array/range.phpt @@ -0,0 +1,448 @@ +--TEST-- +Test range() function +--INI-- +precision=14 +--FILE-- +<?php + +echo "*** Testing range() function on basic operations ***\n"; + +echo "\n-- Integers as Low and High --\n"; +echo "-- An array of elements from low to high --\n"; +var_dump( range(1, 10) ); +echo "\n-- An array of elements from high to low --\n"; +var_dump( range(10, 1) ); + +echo "\n-- Numeric Strings as Low and High --\n"; +echo "-- An array of elements from low to high --\n"; +var_dump( range("1", "10") ); +echo "\n-- An array of elements from high to low --\n"; +var_dump( range("10", "1") ); + +echo "\n-- Chars as Low and High --\n"; +echo "-- An array of elements from low to high --\n"; +var_dump( range("a", "z") ); +echo "\n-- An array of elements from high to low --\n"; +var_dump( range("z", "a") ); + +echo "\n-- Low and High are equal --\n"; +var_dump( range(5, 5) ); +var_dump( range("q", "q") ); + +echo "\n-- floats as Low and High --\n"; +var_dump( range(5.1, 10.1) ); +var_dump( range(10.1, 5.1) ); + +var_dump( range("5.1", "10.1") ); +var_dump( range("10.1", "5.1") ); + +echo "\n-- Passing step with Low and High --\n"; +var_dump( range(1, 2, 0.1) ); +var_dump( range(2, 1, 0.1) ); + +var_dump( range(1, 2, "0.1") ); +var_dump( range("1", "2", 0.1) ); + +echo "\n-- Testing basic string with step --\n"; +var_dump( range("abcd", "mnop", 2) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing range() function on basic operations *** + +-- Integers as Low and High -- +-- An array of elements from low to high -- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} + +-- An array of elements from high to low -- +array(10) { + [0]=> + int(10) + [1]=> + int(9) + [2]=> + int(8) + [3]=> + int(7) + [4]=> + int(6) + [5]=> + int(5) + [6]=> + int(4) + [7]=> + int(3) + [8]=> + int(2) + [9]=> + int(1) +} + +-- Numeric Strings as Low and High -- +-- An array of elements from low to high -- +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + [6]=> + int(7) + [7]=> + int(8) + [8]=> + int(9) + [9]=> + int(10) +} + +-- An array of elements from high to low -- +array(10) { + [0]=> + int(10) + [1]=> + int(9) + [2]=> + int(8) + [3]=> + int(7) + [4]=> + int(6) + [5]=> + int(5) + [6]=> + int(4) + [7]=> + int(3) + [8]=> + int(2) + [9]=> + int(1) +} + +-- Chars as Low and High -- +-- An array of elements from low to high -- +array(26) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + [2]=> + string(1) "c" + [3]=> + string(1) "d" + [4]=> + string(1) "e" + [5]=> + string(1) "f" + [6]=> + string(1) "g" + [7]=> + string(1) "h" + [8]=> + string(1) "i" + [9]=> + string(1) "j" + [10]=> + string(1) "k" + [11]=> + string(1) "l" + [12]=> + string(1) "m" + [13]=> + string(1) "n" + [14]=> + string(1) "o" + [15]=> + string(1) "p" + [16]=> + string(1) "q" + [17]=> + string(1) "r" + [18]=> + string(1) "s" + [19]=> + string(1) "t" + [20]=> + string(1) "u" + [21]=> + string(1) "v" + [22]=> + string(1) "w" + [23]=> + string(1) "x" + [24]=> + string(1) "y" + [25]=> + string(1) "z" +} + +-- An array of elements from high to low -- +array(26) { + [0]=> + string(1) "z" + [1]=> + string(1) "y" + [2]=> + string(1) "x" + [3]=> + string(1) "w" + [4]=> + string(1) "v" + [5]=> + string(1) "u" + [6]=> + string(1) "t" + [7]=> + string(1) "s" + [8]=> + string(1) "r" + [9]=> + string(1) "q" + [10]=> + string(1) "p" + [11]=> + string(1) "o" + [12]=> + string(1) "n" + [13]=> + string(1) "m" + [14]=> + string(1) "l" + [15]=> + string(1) "k" + [16]=> + string(1) "j" + [17]=> + string(1) "i" + [18]=> + string(1) "h" + [19]=> + string(1) "g" + [20]=> + string(1) "f" + [21]=> + string(1) "e" + [22]=> + string(1) "d" + [23]=> + string(1) "c" + [24]=> + string(1) "b" + [25]=> + string(1) "a" +} + +-- Low and High are equal -- +array(1) { + [0]=> + int(5) +} +array(1) { + [0]=> + string(1) "q" +} + +-- floats as Low and High -- +array(6) { + [0]=> + float(5.1) + [1]=> + float(6.1) + [2]=> + float(7.1) + [3]=> + float(8.1) + [4]=> + float(9.1) + [5]=> + float(10.1) +} +array(6) { + [0]=> + float(10.1) + [1]=> + float(9.1) + [2]=> + float(8.1) + [3]=> + float(7.1) + [4]=> + float(6.1) + [5]=> + float(5.1) +} +array(6) { + [0]=> + float(5.1) + [1]=> + float(6.1) + [2]=> + float(7.1) + [3]=> + float(8.1) + [4]=> + float(9.1) + [5]=> + float(10.1) +} +array(6) { + [0]=> + float(10.1) + [1]=> + float(9.1) + [2]=> + float(8.1) + [3]=> + float(7.1) + [4]=> + float(6.1) + [5]=> + float(5.1) +} + +-- Passing step with Low and High -- +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} +array(11) { + [0]=> + float(2) + [1]=> + float(1.9) + [2]=> + float(1.8) + [3]=> + float(1.7) + [4]=> + float(1.6) + [5]=> + float(1.5) + [6]=> + float(1.4) + [7]=> + float(1.3) + [8]=> + float(1.2) + [9]=> + float(1.1) + [10]=> + float(1) +} +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} +array(11) { + [0]=> + float(1) + [1]=> + float(1.1) + [2]=> + float(1.2) + [3]=> + float(1.3) + [4]=> + float(1.4) + [5]=> + float(1.5) + [6]=> + float(1.6) + [7]=> + float(1.7) + [8]=> + float(1.8) + [9]=> + float(1.9) + [10]=> + float(2) +} + +-- Testing basic string with step -- +array(7) { + [0]=> + string(1) "a" + [1]=> + string(1) "c" + [2]=> + string(1) "e" + [3]=> + string(1) "g" + [4]=> + string(1) "i" + [5]=> + string(1) "k" + [6]=> + string(1) "m" +} +Done diff --git a/ext/standard/tests/array/range_errors.phpt b/ext/standard/tests/array/range_errors.phpt new file mode 100644 index 0000000..9652e28 --- /dev/null +++ b/ext/standard/tests/array/range_errors.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test range() function (errors) +--INI-- +precision=14 +--FILE-- +<?php + +echo "\n*** Testing error conditions ***\n"; + +echo "\n-- Testing ( (low < high) && (step = 0) ) --"; +var_dump( range(1, 2, 0) ); +var_dump( range("a", "b", 0) ); + +echo "\n\n-- Testing ( (low > high) && (step = 0) ) --"; +var_dump( range(2, 1, 0) ); +var_dump( range("b", "a", 0) ); + +echo "\n\n-- Testing ( (low < high) && (high-low < step) ) --"; +var_dump( range(1.0, 7.0, 6.5) ); + +echo "\n\n-- Testing ( (low > high) && (low-high < step) ) --"; +var_dump( range(7.0, 1.0, 6.5) ); + +echo "\n-- Testing Invalid number of arguments --"; +var_dump( range() ); // No.of args = 0 +var_dump( range(1) ); // No.of args < expected +var_dump( range(1,2,3,4) ); // No.of args > expected +var_dump( range(-1, -2, 2) ); +var_dump( range("a", "j", "z") ); + +echo "\n-- Testing Invalid steps --"; +$step_arr = array( "string", NULL, FALSE, "", "\0" ); + +foreach( $step_arr as $step ) { + var_dump( range( 1, 5, $step ) ); +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing error conditions *** + +-- Testing ( (low < high) && (step = 0) ) -- +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + + +-- Testing ( (low > high) && (step = 0) ) -- +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + + +-- Testing ( (low < high) && (high-low < step) ) -- +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + + +-- Testing ( (low > high) && (low-high < step) ) -- +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +-- Testing Invalid number of arguments -- +Warning: range() expects at least 2 parameters, 0 given in %s on line %d +bool(false) + +Warning: range() expects at least 2 parameters, 1 given in %s on line %d +bool(false) + +Warning: range() expects at most 3 parameters, 4 given in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +-- Testing Invalid steps -- +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) + +Warning: range(): step exceeds the specified range in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/range_variation.phpt b/ext/standard/tests/array/range_variation.phpt new file mode 100644 index 0000000..e97d918 --- /dev/null +++ b/ext/standard/tests/array/range_variation.phpt @@ -0,0 +1,626 @@ +--TEST-- +Test range() function (variation-1) +--INI-- +precision=14 +--FILE-- +<?php + +echo "\n*** Testing range() with various low and high values ***"; +$low_arr = array( "ABCD", -10.5555, TRUE, NULL, FALSE, "", array(1,2)); +$high_arr = array( "ABCD", -10.5555, TRUE, NULL, FALSE, "", array(1,2)); + +for( $i = 0; $i < count($low_arr); $i++) { + for( $j = 0; $j < count($high_arr); $j++) { + echo @"\n-- creating an array with low = '$low_arr[$i]' and high = '$high_arr[$j]' --\n"; + var_dump( range( $low_arr[$i], $high_arr[$j] ) ); + } +} + +echo "\n*** Possible variatins with steps ***\n"; +var_dump( range( 1, 5, TRUE ) ); +var_dump( range( 1, 5, array(1, 2) ) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing range() with various low and high values *** +-- creating an array with low = 'ABCD' and high = 'ABCD' -- +array(1) { + [0]=> + string(1) "A" +} + +-- creating an array with low = 'ABCD' and high = '-10.5555' -- +array(11) { + [0]=> + float(0) + [1]=> + float(-1) + [2]=> + float(-2) + [3]=> + float(-3) + [4]=> + float(-4) + [5]=> + float(-5) + [6]=> + float(-6) + [7]=> + float(-7) + [8]=> + float(-8) + [9]=> + float(-9) + [10]=> + float(-10) +} + +-- creating an array with low = 'ABCD' and high = '1' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = 'ABCD' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = 'ABCD' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = 'ABCD' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = 'ABCD' and high = 'Array' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = '-10.5555' and high = 'ABCD' -- +array(11) { + [0]=> + float(-10.5555) + [1]=> + float(-9.5555) + [2]=> + float(-8.5555) + [3]=> + float(-7.5555) + [4]=> + float(-6.5555) + [5]=> + float(-5.5555) + [6]=> + float(-4.5555) + [7]=> + float(-3.5555) + [8]=> + float(-2.5555) + [9]=> + float(-1.5555) + [10]=> + float(-0.5555) +} + +-- creating an array with low = '-10.5555' and high = '-10.5555' -- +array(1) { + [0]=> + float(-10.5555) +} + +-- creating an array with low = '-10.5555' and high = '1' -- +array(12) { + [0]=> + float(-10.5555) + [1]=> + float(-9.5555) + [2]=> + float(-8.5555) + [3]=> + float(-7.5555) + [4]=> + float(-6.5555) + [5]=> + float(-5.5555) + [6]=> + float(-4.5555) + [7]=> + float(-3.5555) + [8]=> + float(-2.5555) + [9]=> + float(-1.5555) + [10]=> + float(-0.5555) + [11]=> + float(0.4445) +} + +-- creating an array with low = '-10.5555' and high = '' -- +array(11) { + [0]=> + float(-10.5555) + [1]=> + float(-9.5555) + [2]=> + float(-8.5555) + [3]=> + float(-7.5555) + [4]=> + float(-6.5555) + [5]=> + float(-5.5555) + [6]=> + float(-4.5555) + [7]=> + float(-3.5555) + [8]=> + float(-2.5555) + [9]=> + float(-1.5555) + [10]=> + float(-0.5555) +} + +-- creating an array with low = '-10.5555' and high = '' -- +array(11) { + [0]=> + float(-10.5555) + [1]=> + float(-9.5555) + [2]=> + float(-8.5555) + [3]=> + float(-7.5555) + [4]=> + float(-6.5555) + [5]=> + float(-5.5555) + [6]=> + float(-4.5555) + [7]=> + float(-3.5555) + [8]=> + float(-2.5555) + [9]=> + float(-1.5555) + [10]=> + float(-0.5555) +} + +-- creating an array with low = '-10.5555' and high = '' -- +array(11) { + [0]=> + float(-10.5555) + [1]=> + float(-9.5555) + [2]=> + float(-8.5555) + [3]=> + float(-7.5555) + [4]=> + float(-6.5555) + [5]=> + float(-5.5555) + [6]=> + float(-4.5555) + [7]=> + float(-3.5555) + [8]=> + float(-2.5555) + [9]=> + float(-1.5555) + [10]=> + float(-0.5555) +} + +-- creating an array with low = '-10.5555' and high = 'Array' -- +array(12) { + [0]=> + float(-10.5555) + [1]=> + float(-9.5555) + [2]=> + float(-8.5555) + [3]=> + float(-7.5555) + [4]=> + float(-6.5555) + [5]=> + float(-5.5555) + [6]=> + float(-4.5555) + [7]=> + float(-3.5555) + [8]=> + float(-2.5555) + [9]=> + float(-1.5555) + [10]=> + float(-0.5555) + [11]=> + float(0.4445) +} + +-- creating an array with low = '1' and high = 'ABCD' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = '1' and high = '-10.5555' -- +array(12) { + [0]=> + float(1) + [1]=> + float(0) + [2]=> + float(-1) + [3]=> + float(-2) + [4]=> + float(-3) + [5]=> + float(-4) + [6]=> + float(-5) + [7]=> + float(-6) + [8]=> + float(-7) + [9]=> + float(-8) + [10]=> + float(-9) + [11]=> + float(-10) +} + +-- creating an array with low = '1' and high = '1' -- +array(1) { + [0]=> + int(1) +} + +-- creating an array with low = '1' and high = '' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = '1' and high = '' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = '1' and high = '' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = '1' and high = 'Array' -- +array(1) { + [0]=> + int(1) +} + +-- creating an array with low = '' and high = 'ABCD' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '-10.5555' -- +array(11) { + [0]=> + float(0) + [1]=> + float(-1) + [2]=> + float(-2) + [3]=> + float(-3) + [4]=> + float(-4) + [5]=> + float(-5) + [6]=> + float(-6) + [7]=> + float(-7) + [8]=> + float(-8) + [9]=> + float(-9) + [10]=> + float(-10) +} + +-- creating an array with low = '' and high = '1' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = 'Array' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = '' and high = 'ABCD' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '-10.5555' -- +array(11) { + [0]=> + float(0) + [1]=> + float(-1) + [2]=> + float(-2) + [3]=> + float(-3) + [4]=> + float(-4) + [5]=> + float(-5) + [6]=> + float(-6) + [7]=> + float(-7) + [8]=> + float(-8) + [9]=> + float(-9) + [10]=> + float(-10) +} + +-- creating an array with low = '' and high = '1' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = 'Array' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = '' and high = 'ABCD' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '-10.5555' -- +array(11) { + [0]=> + float(0) + [1]=> + float(-1) + [2]=> + float(-2) + [3]=> + float(-3) + [4]=> + float(-4) + [5]=> + float(-5) + [6]=> + float(-6) + [7]=> + float(-7) + [8]=> + float(-8) + [9]=> + float(-9) + [10]=> + float(-10) +} + +-- creating an array with low = '' and high = '1' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = '' -- +array(1) { + [0]=> + int(0) +} + +-- creating an array with low = '' and high = 'Array' -- +array(2) { + [0]=> + int(0) + [1]=> + int(1) +} + +-- creating an array with low = 'Array' and high = 'ABCD' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = 'Array' and high = '-10.5555' -- +array(12) { + [0]=> + float(1) + [1]=> + float(0) + [2]=> + float(-1) + [3]=> + float(-2) + [4]=> + float(-3) + [5]=> + float(-4) + [6]=> + float(-5) + [7]=> + float(-6) + [8]=> + float(-7) + [9]=> + float(-8) + [10]=> + float(-9) + [11]=> + float(-10) +} + +-- creating an array with low = 'Array' and high = '1' -- +array(1) { + [0]=> + int(1) +} + +-- creating an array with low = 'Array' and high = '' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = 'Array' and high = '' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = 'Array' and high = '' -- +array(2) { + [0]=> + int(1) + [1]=> + int(0) +} + +-- creating an array with low = 'Array' and high = 'Array' -- +array(1) { + [0]=> + int(1) +} + +*** Possible variatins with steps *** +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) +} +Done diff --git a/ext/standard/tests/array/range_variation1.phpt b/ext/standard/tests/array/range_variation1.phpt new file mode 100644 index 0000000..6e57f73 --- /dev/null +++ b/ext/standard/tests/array/range_variation1.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test range() function (variation-2) +--INI-- +precision=14 +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php + +echo "\n*** Testing max/outof range values ***\n"; +/*var_dump( range("a", "z", 255) ); +var_dump( range("z", "a", 255) ); */ +var_dump( range(2147483645, 2147483646) ); +var_dump( range(2147483646, 2147483648) ); +var_dump( range(-2147483647, -2147483646) ); +var_dump( range(-2147483648, -2147483647) ); +var_dump( range(-2147483649, -2147483647) ); + +echo "\nDone"; +?> +--EXPECTF-- +*** Testing max/outof range values *** +array(2) { + [0]=> + int(2147483645) + [1]=> + int(2147483646) +} +array(3) { + [0]=> + float(2147483646) + [1]=> + float(2147483647) + [2]=> + float(2147483648) +} +array(2) { + [0]=> + int(-2147483647) + [1]=> + int(-2147483646) +} +array(2) { + [0]=> + float(-2147483648) + [1]=> + float(-2147483647) +} +array(3) { + [0]=> + float(-2147483649) + [1]=> + float(-2147483648) + [2]=> + float(-2147483647) +} + +Done diff --git a/ext/standard/tests/array/range_variation1_64bit.phpt b/ext/standard/tests/array/range_variation1_64bit.phpt new file mode 100644 index 0000000..a14dae9 --- /dev/null +++ b/ext/standard/tests/array/range_variation1_64bit.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test range() function (variation-2) +--INI-- +precision=14 +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); +?> +--FILE-- +<?php + +echo "\n*** Testing max/outof range values ***\n"; +/*var_dump( range("a", "z", 255) ); +var_dump( range("z", "a", 255) ); */ +var_dump( range(2147483645, 2147483646) ); +var_dump( range(2147483646, 2147483648) ); +var_dump( range(-2147483647, -2147483646) ); +var_dump( range(-2147483648, -2147483647) ); +var_dump( range(-2147483649, -2147483647) ); + +echo "\nDone"; +?> +--EXPECTF-- +*** Testing max/outof range values *** +array(2) { + [0]=> + int(2147483645) + [1]=> + int(2147483646) +} +array(3) { + [0]=> + int(2147483646) + [1]=> + int(2147483647) + [2]=> + int(2147483648) +} +array(2) { + [0]=> + int(-2147483647) + [1]=> + int(-2147483646) +} +array(2) { + [0]=> + int(-2147483648) + [1]=> + int(-2147483647) +} +array(3) { + [0]=> + int(-2147483649) + [1]=> + int(-2147483648) + [2]=> + int(-2147483647) +} + +Done diff --git a/ext/standard/tests/array/reset_basic.phpt b/ext/standard/tests/array/reset_basic.phpt new file mode 100644 index 0000000..d376e68 --- /dev/null +++ b/ext/standard/tests/array/reset_basic.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test reset() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of reset() + */ + +echo "*** Testing reset() : basic functionality ***\n"; + +$array = array('zero', 'one', 200 => 'two'); + +echo "\n-- Initial Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to next() --\n"; +var_dump(next($array)); + +echo "\n-- Current Position: --\n"; +echo key($array) . " => " . current($array) . "\n"; + +echo "\n-- Call to reset() --\n"; +var_dump(reset($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : basic functionality *** + +-- Initial Position: -- +0 => zero + +-- Call to next() -- +string(3) "one" + +-- Current Position: -- +1 => one + +-- Call to reset() -- +string(4) "zero" +===DONE=== diff --git a/ext/standard/tests/array/reset_error.phpt b/ext/standard/tests/array/reset_error.phpt new file mode 100644 index 0000000..c716081 --- /dev/null +++ b/ext/standard/tests/array/reset_error.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test reset() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to reset() to test behaviour + */ + +echo "*** Testing reset() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing reset() function with Zero arguments --\n"; +var_dump( reset() ); + +//Test reset with one more than the expected number of arguments +echo "\n-- Testing reset() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( reset($array_arg, $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : error conditions *** + +-- Testing reset() function with Zero arguments -- + +Warning: reset() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing reset() function with more than expected no. of arguments -- + +Warning: reset() expects exactly 1 parameter, 2 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/reset_variation1.phpt b/ext/standard/tests/array/reset_variation1.phpt new file mode 100644 index 0000000..b6cddf0 --- /dev/null +++ b/ext/standard/tests/array/reset_variation1.phpt @@ -0,0 +1,219 @@ +--TEST-- +Test reset() function : usage variations - Pass different data types as $array_arg arg. +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to reset() to test behaviour + */ + +echo "*** Testing reset() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of reset() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( reset($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Iteration 1 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: reset() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: reset() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: reset() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: reset() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: reset() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: reset() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/reset_variation2.phpt b/ext/standard/tests/array/reset_variation2.phpt new file mode 100644 index 0000000..1384aff --- /dev/null +++ b/ext/standard/tests/array/reset_variation2.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test reset() function : usage variations - unset first element +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Unset first element of an array and test behaviour of reset() + */ + +echo "*** Testing reset() : usage variations ***\n"; + +$array = array('a', 'b', 'c'); + +echo "\n-- Initial Position: --\n"; +echo current($array) . " => " . key($array) . "\n"; + +echo "\n-- Unset First element in array and check reset() --\n"; +unset($array[0]); +var_dump(reset($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial Position: -- +a => 0 + +-- Unset First element in array and check reset() -- +string(1) "b" +===DONE=== diff --git a/ext/standard/tests/array/reset_variation3.phpt b/ext/standard/tests/array/reset_variation3.phpt new file mode 100644 index 0000000..29f965a --- /dev/null +++ b/ext/standard/tests/array/reset_variation3.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test reset() function : usage variations - Referenced variables +--FILE-- +<?php +/* Prototype : mixed reset(array $array_arg) + * Description: Set array argument's internal pointer to the first element and return it + * Source code: ext/standard/array.c + */ + +/* + * Reference two arrays to each other then call reset() to test position of + * internal pointer in both arrays + */ + +echo "*** Testing reset() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; + +next($array1); + +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); + +echo "\n-- Position after calling reset() --\n"; +var_dump(reset($array1)); +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===DONE=== +--EXPECTF-- +*** Testing reset() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" + +-- Position after calling reset() -- +string(4) "zero" +$array1: string(4) "zero" +$array2: string(4) "zero" +===DONE=== diff --git a/ext/standard/tests/array/rsort_basic.phpt b/ext/standard/tests/array/rsort_basic.phpt new file mode 100644 index 0000000..34fcbb7 --- /dev/null +++ b/ext/standard/tests/array/rsort_basic.phpt @@ -0,0 +1,241 @@ +--TEST-- +Test rsort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of rsort() + */ + +echo "*** Testing rsort() : basic functionality ***\n"; + +// associative array containing unsorted string values +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); + +// array with default keys containing unsorted numeric values +$unsorted_numerics = array( 100, 33, 555, 22 ); + +echo "\n-- Testing rsort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_STRING) ); +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( rsort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array, SORT_NUMERIC) ); +var_dump( $temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : basic functionality *** + +-- Testing rsort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} + +-- Testing rsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} + +-- Testing rsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(7) "Orange3" + [1]=> + string(8) "orange20" + [2]=> + string(7) "orange2" + [3]=> + string(7) "Orange1" + [4]=> + string(6) "orange" + [5]=> + string(6) "Orange" + [6]=> + string(5) "lemon" + [7]=> + string(6) "banana" +} + +-- Testing rsort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "orange2" + [2]=> + string(6) "orange" + [3]=> + string(5) "lemon" + [4]=> + string(6) "banana" + [5]=> + string(7) "Orange3" + [6]=> + string(7) "Orange1" + [7]=> + string(6) "Orange" +} + +-- Testing rsort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(8) "orange20" + [1]=> + string(7) "Orange3" + [2]=> + string(7) "orange2" + [3]=> + string(7) "Orange1" + [4]=> + string(6) "orange" + [5]=> + string(6) "Orange" + [6]=> + string(5) "lemon" + [7]=> + string(6) "banana" +} + +-- Testing rsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + int(555) + [1]=> + int(100) + [2]=> + int(33) + [3]=> + int(22) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_error.phpt b/ext/standard/tests/array/rsort_error.phpt new file mode 100644 index 0000000..6f6f2f9 --- /dev/null +++ b/ext/standard/tests/array/rsort_error.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test rsort() function : error conditions - Pass incorrect number of args +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to rsort() to test behaviour + */ + +echo "*** Testing rsort() : error conditions ***\n"; + +// zero arguments +echo "\n-- Testing rsort() function with Zero arguments --\n"; +var_dump( rsort() ); + +//Test rsort() with more than the expected number of arguments +echo "\n-- Testing rsort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$sort_flags = SORT_REGULAR; +$extra_arg = 10; +var_dump( rsort($array_arg, $sort_flags, $extra_arg) ); + +// dump the input array to ensure that it wasn't changed +var_dump($array_arg); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : error conditions *** + +-- Testing rsort() function with Zero arguments -- + +Warning: rsort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing rsort() function with more than expected no. of arguments -- + +Warning: rsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_object1.phpt b/ext/standard/tests/array/rsort_object1.phpt new file mode 100644 index 0000000..98f7cfe --- /dev/null +++ b/ext/standard/tests/array/rsort_object1.phpt @@ -0,0 +1,243 @@ +--TEST-- +Test rsort() function : object functionality +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of rsort() with objects + */ + +echo "*** Testing rsort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_rsort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class for_string_rsort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array( + new for_integer_rsort(11), new for_integer_rsort(66), + new for_integer_rsort(23), new for_integer_rsort(-5), + new for_integer_rsort(0.001), new for_integer_rsort(0) +); + +// array of string objects +$unsorted_str_obj = array ( + new for_string_rsort("axx"), new for_string_rsort("t"), + new for_string_rsort("w"), new for_string_rsort("py"), + new for_string_rsort("apple"), new for_string_rsort("Orange"), + new for_string_rsort("Lemon"), new for_string_rsort("aPPle") +); + + +echo "\n-- Sort flag = default --\n"; + +// testing rsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_REGULAR --\n"; +// testing rsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : object functionality *** + +-- Sort flag = default -- +bool(true) +array(6) { + [0]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(66) + } + [1]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [4]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "w" + } + [1]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [3]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [4]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [5]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [6]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [7]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(66) + } + [1]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(23) + } + [2]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(11) + } + [3]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [4]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(0) + } + [5]=> + object(for_integer_rsort)#%d (1) { + ["class_value"]=> + int(-5) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "w" + } + [1]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [2]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [3]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [4]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [5]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [6]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [7]=> + object(for_string_rsort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_object2.phpt b/ext/standard/tests/array/rsort_object2.phpt new file mode 100644 index 0000000..57acdc6 --- /dev/null +++ b/ext/standard/tests/array/rsort_object2.phpt @@ -0,0 +1,258 @@ +--TEST-- +Test rsort() function : object functionality - different visibilities +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test functionality of rsort() with objects where properties have different visibilities + */ + +echo "*** Testing rsort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_rsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + +} + +// class declaration for string objects +class for_string_rsort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects + +$unsorted_int_obj = array( + new for_integer_rsort(11,33,30), + new for_integer_rsort(66,44,4), + new for_integer_rsort(-88,-5,5), + new for_integer_rsort(0.001,99.5,0.1) +); + +// array of string objects +$unsorted_str_obj = array ( + new for_string_rsort("axx","AXX","ass"), + new for_string_rsort("t","eee","abb"), + new for_string_rsort("w","W", "c"), + new for_string_rsort("py","PY", "pt"), +); + + +echo "\n-- Sort flag = default --\n"; + +// testing rsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_REGULAR --\n"; +// testing rsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing rsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : object functionality *** + +-- Sort flag = default -- +bool(true) +array(4) { + [0]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_rsort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_rsort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [2]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_rsort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [3]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_rsort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_rsort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } + [1]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_rsort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [2]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_rsort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [3]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_rsort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_rsort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_rsort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [2]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_rsort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [3]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_rsort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_rsort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } + [1]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_rsort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [2]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_rsort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [3]=> + object(for_string_rsort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_rsort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation1.phpt b/ext/standard/tests/array/rsort_variation1.phpt new file mode 100644 index 0000000..96dac90 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation1.phpt @@ -0,0 +1,514 @@ +--TEST-- +Test rsort() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to rsort() to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of rsort() +$iterator = 1; +foreach ($inputs as $input) { + echo "-- Iteration $iterator --\n"; + echo "Flag = default:\n"; + var_dump( rsort($input) ); + echo "Flag = SORT_REGULAR:\n"; + var_dump( rsort($input, SORT_REGULAR) ); + echo "Flag = SORT_NUMERIC:\n"; + var_dump( rsort($input, SORT_NUMERIC) ); + echo "Flag = SORT_STRING:\n"; + var_dump( rsort($input, SORT_STRING) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** +-- Iteration 1 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 21 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 22 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 23 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 24 -- +Flag = default: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Flag = SORT_REGULAR: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Flag = SORT_NUMERIC: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Flag = SORT_STRING: + +Warning: rsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation10.phpt b/ext/standard/tests/array/rsort_variation10.phpt new file mode 100644 index 0000000..ccf886b --- /dev/null +++ b/ext/standard/tests/array/rsort_variation10.phpt @@ -0,0 +1,108 @@ +--TEST-- +Test rsort() function : usage variations - Octal values +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() an array containing octal values to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array(01235, 0321, 0345, 066, 0772, 077, -066, -0345, 0); + +echo "\n-- Sort flag = default --\n"; +$temp_array = $unsorted_oct_array; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Sort flag = SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump(rsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Sort flag = default -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} + +-- Sort flag = SORT_REGULAR -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} + +-- Sort flag = SORT_NUMERIC -- +bool(true) +array(9) { + [0]=> + int(669) + [1]=> + int(506) + [2]=> + int(229) + [3]=> + int(209) + [4]=> + int(63) + [5]=> + int(54) + [6]=> + int(0) + [7]=> + int(-54) + [8]=> + int(-229) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation11.phpt b/ext/standard/tests/array/rsort_variation11.phpt Binary files differnew file mode 100644 index 0000000..83bbf84 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation11.phpt diff --git a/ext/standard/tests/array/rsort_variation2.phpt b/ext/standard/tests/array/rsort_variation2.phpt new file mode 100644 index 0000000..2196a64 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation2.phpt @@ -0,0 +1,484 @@ +--TEST-- +Test rsort() function : usage variations - Pass different data types as $sort_flags arg +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $sort_flags argument to rsort() to test behaviour + * Where possible, 'SORT_NUMERIC' has been entered as a string value + */ + +echo "*** Testing rsort() : variation ***\n"; + +// Initialise function arguments not being substituted +$array_arg = array (1, 5, 2, 3, 1); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "SORT_NUMERIC"; + } +} + +// heredoc string +$heredoc = <<<EOT +SORT_NUMERIC +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $sort_flags argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "SORT_NUMERIC", + 'SORT_NUMERIC', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of rsort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + + //create temporary array in case rsort() works + $temp = $array_arg; + + var_dump( rsort($temp, $input) ); + var_dump($temp); + $iterator++; + + $temp = null; +}; + +fclose($fp); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 2 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 3 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 4 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 5 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 6 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 7 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 8 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 9 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 10 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 11 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 12 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 13 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 14 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 15 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 16 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 17 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 18 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 19 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 20 -- + +Warning: rsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 21 -- + +Warning: rsort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} + +-- Iteration 22 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 23 -- +bool(true) +array(5) { + [0]=> + int(5) + [1]=> + int(3) + [2]=> + int(2) + [3]=> + int(1) + [4]=> + int(1) +} + +-- Iteration 24 -- + +Warning: rsort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(5) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(2) + [3]=> + int(3) + [4]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation3.phpt b/ext/standard/tests/array/rsort_variation3.phpt new file mode 100644 index 0000000..f8c002a --- /dev/null +++ b/ext/standard/tests/array/rsort_variation3.phpt @@ -0,0 +1,325 @@ +--TEST-- +Test rsort() function : usage variations - numeric values +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays containing different numeric data to rsort() to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// group of various arrays + +$various_arrays = array ( +// negative/positive integers array +array(11, -11, 21, -21, 31, -31, 0, 41, -41), + +// float value array +array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1), + +// mixed value array +array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33), + +// array values contains minimum and maximum ranges +array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; + +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Defualt sort flag -\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(rsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +- With Defualt sort flag - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [0]=> + int(41) + [1]=> + int(31) + [2]=> + int(21) + [3]=> + int(11) + [4]=> + int(0) + [5]=> + int(-11) + [6]=> + int(-21) + [7]=> + int(-31) + [8]=> + int(-41) +} + +-- Iteration 2 -- +- With Defualt sort flag - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(1050) + [1]=> + float(10.5) + [2]=> + float(0.5) + [3]=> + float(0.106) + [4]=> + float(0.01) + [5]=> + float(-0.1) + [6]=> + float(-10.5) +} + +-- Iteration 3 -- +- With Defualt sort flag - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [0]=> + int(33) + [1]=> + int(2) + [2]=> + float(0.106) + [3]=> + float(0.09) + [4]=> + float(0.0021) + [5]=> + float(0.0001) + [6]=> + int(0) + [7]=> + float(-0.01) + [8]=> + float(-0.106) + [9]=> + float(-0.9) + [10]=> + int(-1) +} + +-- Iteration 4 -- +- With Defualt sort flag - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(2147483648) + [1]=> + int(2147483647) + [2]=> + int(0) + [3]=> + int(0) + [4]=> + int(-2147483647) + [5]=> + float(-2147483648) + [6]=> + float(-2147483649) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation4.phpt b/ext/standard/tests/array/rsort_variation4.phpt new file mode 100644 index 0000000..226284d --- /dev/null +++ b/ext/standard/tests/array/rsort_variation4.phpt @@ -0,0 +1,62 @@ +--TEST-- +Test rsort() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Test behaviour of rsort() when: + * 1. passed an array of referenced variables + * 2. $array_arg is a reference to another array + * 3. $array_arg is passed by reference + */ + +echo "*** Testing rsort() : variation ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +// an array containing integer references +$unsorted_numerics = array( &$value1 , &$value2, &$value3); + +echo "\n-- 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort($temp_array) ); +var_dump( $temp_array); + +echo "\n-- 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( rsort($temp_array, SORT_REGULAR) ); +var_dump( $temp_array); + +echo "Done"; +?> +--EXPECTF-- +*** Testing rsort() : variation *** + +-- 'flag' value is defualt -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done diff --git a/ext/standard/tests/array/rsort_variation5.phpt b/ext/standard/tests/array/rsort_variation5.phpt new file mode 100644 index 0000000..c0184e8 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation5.phpt @@ -0,0 +1,226 @@ +--TEST-- +Test rsort() function : usage variations - String values +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays containing different string data to rsort() to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +$various_arrays = array ( +// group of escape sequences +array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\t", "\xhh", "\ddd", "\v"), + +// array contains combination of capital/small letters +array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA") +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + + $temp_array = $array; + var_dump(rsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(4) "\ddd" + [2]=> + string(3) "\cx" + [3]=> + string(2) "\a" + [4]=> + string(1) "" + [5]=> + string(1) "" + [6]=> + string(1) "" + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(4) "\ddd" + [2]=> + string(3) "\cx" + [3]=> + string(2) "\a" + [4]=> + string(1) "" + [5]=> + string(1) "" + [6]=> + string(1) "" + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [0]=> + string(4) "\xhh" + [1]=> + string(4) "\ddd" + [2]=> + string(3) "\cx" + [3]=> + string(2) "\a" + [4]=> + string(1) "" + [5]=> + string(1) "" + [6]=> + string(1) "" + [7]=> + string(1) " +" + [8]=> + string(1) " " + [9]=> + NULL + [10]=> + NULL +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + string(1) "x" + [1]=> + string(2) "ww" + [2]=> + string(3) "ttt" + [3]=> + string(6) "oraNGe" + [4]=> + string(5) "lemoN" + [5]=> + string(6) "banana" + [6]=> + string(5) "apple" + [7]=> + string(1) "X" + [8]=> + string(4) "Test" + [9]=> + string(4) "TTTT" + [10]=> + string(6) "Orange" + [11]=> + string(6) "BANANA" +} +Done diff --git a/ext/standard/tests/array/rsort_variation6.phpt b/ext/standard/tests/array/rsort_variation6.phpt new file mode 100644 index 0000000..559a1eb --- /dev/null +++ b/ext/standard/tests/array/rsort_variation6.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test rsort() function : usage variations - Hexadecimal vales +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() an array of hexadecimal values to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// an array contains unsorted hexadecimal values +$unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa); + +echo "\n-- 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(rsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- 'flag' value is defualt -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} + +-- 'flag' value is SORT_NUMERIC -- +bool(true) +array(11) { + [0]=> + int(4095) + [1]=> + int(682) + [2]=> + int(427) + [3]=> + int(427) + [4]=> + int(255) + [5]=> + int(255) + [6]=> + int(187) + [7]=> + int(15) + [8]=> + int(0) + [9]=> + int(-255) + [10]=> + int(-682) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation7.phpt b/ext/standard/tests/array/rsort_variation7.phpt new file mode 100644 index 0000000..a996bf6 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation7.phpt @@ -0,0 +1,96 @@ +--TEST-- +Test rsort() function : usage variations - boolean values +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() arrays of boolean values to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// bool value array +$bool_values = array (true, false, TRUE, FALSE); + +echo "\n-- 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(rsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} + +-- 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(false) + [3]=> + bool(false) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation8.phpt b/ext/standard/tests/array/rsort_variation8.phpt new file mode 100644 index 0000000..a4f94b5 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation8.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test rsort() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() multi-dimensional arrays to test behaviour + */ + +echo "*** Testing rsort() : variation ***\n"; + +// array of arrays +$various_arrays = array ( + // null array + array(), + + // array contains null sub array + array( array() ), + + // array of arrays along with some values + array(44, 11, array(64, 61) ), + + // array containing sub arrays + array(array(33, -5, 6), array(11), array(22, -55), array() ) +); + + +$count = 1; + +// loop through to test rsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + + echo "\n-- 'flag' value is default --\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + echo "\n-- 'flag' value is SORT_REGULAR --\n"; + $temp_array = $array; + var_dump(rsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done"; +?> + +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- + +-- 'flag' value is default -- +bool(true) +array(0) { +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(0) { +} + +-- Iteration 2 -- + +-- 'flag' value is default -- +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- Iteration 3 -- + +-- 'flag' value is default -- +bool(true) +array(3) { + [0]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(44) + [2]=> + int(11) +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(44) + [2]=> + int(11) +} + +-- Iteration 4 -- + +-- 'flag' value is default -- +bool(true) +array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [2]=> + array(1) { + [0]=> + int(11) + } + [3]=> + array(0) { + } +} + +-- 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [1]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [2]=> + array(1) { + [0]=> + int(11) + } + [3]=> + array(0) { + } +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation9.phpt b/ext/standard/tests/array/rsort_variation9.phpt new file mode 100644 index 0000000..c08791d --- /dev/null +++ b/ext/standard/tests/array/rsort_variation9.phpt @@ -0,0 +1,259 @@ +--TEST-- +Test rsort() function : usage variations - mixed associative arrays +--FILE-- +<?php +/* Prototype : bool rsort(array &$array_arg [, int $sort_flags]) + * Description: Sort an array in reverse order + * Source code: ext/standard/array.c + */ + +/* + * Pass rsort() associative arrays to test key re-assignment + */ + +echo "*** Testing rsort() : variation ***\n"; + +// Associative arrays +$various_arrays = array( + // numeric assoc. only array + array(5 => 55, 6 => 66, 2 => 22, 3 => 33, 1 => 11), + + // two-dimensional assoc. and default key array + array("fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), + "numbers" => array(1, 2, 3, 4, 5, 6), + "holes" => array("first", 5 => "second", "third")), + + // numeric assoc. and default key array + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + + // mixed assoc. array + array('bar' => 'baz', "foo" => 1), + + // assoc. only multi-dimensional array + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; + +// loop through to test rsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "-- Sort flag = default --\n"; + $temp_array = $array; + var_dump(rsort($temp_array) ); + var_dump($temp_array); + + echo "-- Sort flag = SORT_REGULAR --\n"; + $temp_array = $array; + var_dump(rsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing rsort() : variation *** + +-- Iteration 1 -- +-- Sort flag = default -- +bool(true) +array(5) { + [0]=> + int(66) + [1]=> + int(55) + [2]=> + int(33) + [3]=> + int(22) + [4]=> + int(11) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(5) { + [0]=> + int(66) + [1]=> + int(55) + [2]=> + int(33) + [3]=> + int(22) + [4]=> + int(11) +} + +-- Iteration 2 -- +-- Sort flag = default -- +bool(true) +array(3) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [2]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } + [1]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [2]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } +} + +-- Iteration 3 -- +-- Sort flag = default -- +bool(true) +array(6) { + [0]=> + int(19) + [1]=> + int(13) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + int(19) + [1]=> + int(13) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(1) + [5]=> + int(1) +} + +-- Iteration 4 -- +-- Sort flag = default -- +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "baz" +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(2) { + [0]=> + int(1) + [1]=> + string(3) "baz" +} + +-- Iteration 5 -- +-- Sort flag = default -- +bool(true) +array(4) { + [0]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + [1]=> + array(1) { + ["g"]=> + int(4) + } + [2]=> + int(5) + [3]=> + int(1) +} +-- Sort flag = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + [1]=> + array(1) { + ["g"]=> + int(4) + } + [2]=> + int(5) + [3]=> + int(1) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/shuffle_basic1.phpt b/ext/standard/tests/array/shuffle_basic1.phpt new file mode 100644 index 0000000..d601f54 --- /dev/null +++ b/ext/standard/tests/array/shuffle_basic1.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test shuffle() function : basic functionality - array with default keys +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle when an array with default keys +* is passed to the 'array_arg' argument and check for the +* changes in the input array by printing the input array +* before and after shuffle() function is applied on it +*/ + +echo "*** Testing shuffle() : with arrays having default keys ***\n"; + +// Initialise the array with integers +$array_arg_int = array(0, 10, 20, 30, 40, 50, 60, 70, 80); + +// Initialise the array with strings +$array_arg_strings = array("one", 'two', 'three', "four", "five", " ", 'six', ' ', "seven"); + +/* Testing shuffle() function with array of integers */ + +// printing the input array with integers before the shuffle operation +echo "\n-- input array of integers before shuffle() function is applied --\n"; +var_dump( $array_arg_int ); + +// applying shuffle() function on the input array of integers +echo "\n-- return value from shuffle() function --\n"; +var_dump( shuffle($array_arg_int) ); // prints the return value from shuffle() function + +echo "\n-- resultant array after shuffle() function is applied --\n"; +var_dump( $array_arg_int ); + +/* Testing shuffle() function with array of strings */ + +// printing the input array with strings before the shuffle operation +echo "\n-- input array of strings before shuffle() function is applied --\n"; +var_dump( $array_arg_strings ); + +// applying shuffle() function on the input array of strings +echo "\n-- return value from shuffle() function --\n"; +var_dump( shuffle($array_arg_strings) ); // prints the return value from shuffle() function + +echo "\n-- resultant array after shuffle() function is applied --\n"; +var_dump( $array_arg_strings ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : with arrays having default keys *** + +-- input array of integers before shuffle() function is applied -- +array(9) { + [0]=> + int(0) + [1]=> + int(10) + [2]=> + int(20) + [3]=> + int(30) + [4]=> + int(40) + [5]=> + int(50) + [6]=> + int(60) + [7]=> + int(70) + [8]=> + int(80) +} + +-- return value from shuffle() function -- +bool(true) + +-- resultant array after shuffle() function is applied -- +array(9) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) +} + +-- input array of strings before shuffle() function is applied -- +array(9) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + [2]=> + string(5) "three" + [3]=> + string(4) "four" + [4]=> + string(4) "five" + [5]=> + string(1) " " + [6]=> + string(3) "six" + [7]=> + string(1) " " + [8]=> + string(5) "seven" +} + +-- return value from shuffle() function -- +bool(true) + +-- resultant array after shuffle() function is applied -- +array(9) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" + [4]=> + string(%d) "%s" + [5]=> + string(%d) "%s" + [6]=> + string(%d) "%s" + [7]=> + string(%d) "%s" + [8]=> + string(%d) "%s" +} +Done + diff --git a/ext/standard/tests/array/shuffle_basic2.phpt b/ext/standard/tests/array/shuffle_basic2.phpt new file mode 100644 index 0000000..cb127d2 --- /dev/null +++ b/ext/standard/tests/array/shuffle_basic2.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test shuffle() function : basic functionality - with associative array +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle when an associative array is +* passed to the 'array_arg' argument and check for the +* changes in the input array by printing the input array +* before and after shuffle() function is applied on it +*/ + +echo "*** Testing shuffle() : with associative array ***\n"; + +// Initialise the associative array +$array_arg = array( + 'one' => 1, 2 => 02, 'three' => 3, + 4 => 4, '#5' => 5, 'SIX' => 6, + "seven" => 0x7, "#8" => 012, "nine" => 9 +); + +// printing the input array before the shuffle operation +echo "\n-- input array before shuffle() function is applied --\n"; +var_dump( $array_arg ); + +// applying shuffle() function on the input array +echo "\n-- return value from shuffle() function --\n"; +var_dump( shuffle($array_arg) ); // prints the return value from shuffle() function + +echo "\n-- resultant array after shuffle() function is applied --\n"; +var_dump( $array_arg ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : with associative array *** + +-- input array before shuffle() function is applied -- +array(9) { + ["one"]=> + int(1) + [2]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) + ["#5"]=> + int(5) + ["SIX"]=> + int(6) + ["seven"]=> + int(7) + ["#8"]=> + int(10) + ["nine"]=> + int(9) +} + +-- return value from shuffle() function -- +bool(true) + +-- resultant array after shuffle() function is applied -- +array(9) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) + [6]=> + int(%d) + [7]=> + int(%d) + [8]=> + int(%d) +} +Done + diff --git a/ext/standard/tests/array/shuffle_error.phpt b/ext/standard/tests/array/shuffle_error.phpt new file mode 100644 index 0000000..833b390 --- /dev/null +++ b/ext/standard/tests/array/shuffle_error.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test shuffle() function : error conditions +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* Test shuffle() to see that warning messages are emitted + * when invalid number of arguments are passed to the function +*/ + +echo "*** Testing shuffle() : error conditions ***\n"; + +// zero arguments +echo "\n-- Testing shuffle() function with Zero arguments --\n"; +var_dump( shuffle() ); + +// more than the expected number of arguments +echo "\n-- Testing shuffle() function with more than expected no. of arguments --\n"; +$array_arg = array(1, "two" => 2); +$extra_arg = 10; +var_dump( shuffle($array_arg, $extra_arg) ); + +// printing the input array to check that it is not affected +// by above shuffle() function calls +echo "\n-- original input array --\n"; +var_dump( $array_arg ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : error conditions *** + +-- Testing shuffle() function with Zero arguments -- + +Warning: shuffle() expects exactly 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing shuffle() function with more than expected no. of arguments -- + +Warning: shuffle() expects exactly 1 parameter, 2 given in %s on line %d +bool(false) + +-- original input array -- +array(2) { + [0]=> + int(1) + ["two"]=> + int(2) +} +Done + diff --git a/ext/standard/tests/array/shuffle_variation1.phpt b/ext/standard/tests/array/shuffle_variation1.phpt new file mode 100644 index 0000000..dff2182 --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation1.phpt @@ -0,0 +1,214 @@ +--TEST-- +Test shuffle() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle() when unexpected values are passed for 'array_arg' +* argument and verify that function outputs required warning messages wherever applicable +*/ + +echo "*** Testing shuffle() : with unexpected values for 'array_arg' argument ***\n"; + + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//get a resource variable +$fp = fopen(__FILE__, "r"); + +//define a class +class test +{ + var $t = 10; + function __toString() + { + return "object"; + } +} + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new test(), + + // undefined data +/*21*/ @$undefined_var, + + // unset data +/*22*/ @$unset_var, + +/*23*/ // resource data + $fp +); + +// loop through the array to test shuffle() function +// with each element of the array +$count = 1; +foreach($values as $value) { + echo "\n-- Iteration $count --\n"; + var_dump( shuffle($value) ); + $count++; +}; + +// closing the resource +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : with unexpected values for 'array_arg' argument *** + +-- Iteration 1 -- + +Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: shuffle() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: shuffle() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: shuffle() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: shuffle() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: shuffle() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: shuffle() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: shuffle() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: shuffle() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: shuffle() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done + diff --git a/ext/standard/tests/array/shuffle_variation2.phpt b/ext/standard/tests/array/shuffle_variation2.phpt new file mode 100644 index 0000000..a0cb6b6 --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation2.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test shuffle() function : usage variation - with MultiDimensional array +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle() function when multi-dimensional array is +* passed to 'array_arg' argument +*/ + +echo "*** Testing shuffle() : with multi-dimensional array ***\n"; + +// initialise the multi-dimensional array +$array_arg = array( + array(1, 2, 3), + array(4, 5, 6), + array(7, 8, 9), + array(10000, 20000000, 30000000), + array(0, 0, 0), + array(012, 023, 034), + array(0x1, 0x0, 0xa) + +); + +// calling shuffle() function with multi-dimensional array +var_dump( shuffle($array_arg) ); +echo "\nThe output array is:\n"; +var_dump( $array_arg ); + + +// looping to test shuffle() with each sub-array in the multi-dimensional array +echo "\n*** Testing shuffle() with arrays having different types of values ***\n"; +$counter = 1; +for($i=0; $i<=6; $i++) { + echo "\n-- Iteration $counter --\n"; + var_dump( shuffle($array_arg[$i]) ); + echo "\nThe output array is:\n"; + var_dump( $array_arg[$i] ); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : with multi-dimensional array *** +bool(true) + +The output array is: +array(7) { + [0]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [1]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [2]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [3]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [4]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [5]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } + [6]=> + array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + } +} + +*** Testing shuffle() with arrays having different types of values *** + +-- Iteration 1 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 2 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 3 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 4 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 5 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 6 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} + +-- Iteration 7 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) +} +Done + diff --git a/ext/standard/tests/array/shuffle_variation3.phpt b/ext/standard/tests/array/shuffle_variation3.phpt new file mode 100644 index 0000000..ad8e668 --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation3.phpt @@ -0,0 +1,233 @@ +--TEST-- +Test shuffle() function : usage variation - arrays with diff types of values +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle() function when arrays having different +* types of values, are passed to 'array_arg' argument +*/ + +echo "*** Testing shuffle() : arrays with diff types of values ***\n"; + +// initialise different arrays +$array_arg = array( + // array with positive int values +/*1*/ array(0, 1, 2, 2147483647 ), + + // array with negative int values + array(-1, -2, -2147483647 ), + + // array with positive float values +/*3*/ array(0.23, 1.34, 0e2, 200e-2, 30e2, 10e0, 2147473648.90), + + // array with negative float values + array(-0.23, -1.34, -200e-2, -30e2, -10e0, -2147473649.80), + + // array with single quoted and double quoted strings +/*5*/ array('one', "123numbers", 'hello\tworld', "hello world\0", '12.34floatnum'), + + // array with bool values + array(true, TRUE, FALSE, false), + + // array with positive hexa values +/*7*/ array(0x123, 0xabc, 0xABC, 0xac, 0xAb1, 0x9fa), + + // array with negative hexa values + array(-0x123, -0xabc, -0xABC, -0xAb1, -0x9fa), + + // array with positive octal values +/*9*/ array(0123, 02348, 034, 00), + + // array with negative octal values +/*10*/ array(-0123, -02348, -034), + +); + +// looping to test shuffle() with each sub-array in the $array_arg array +echo "\n*** Testing shuffle() with arrays having different types of values ***\n"; +$counter = 1; +foreach($array_arg as $arr) { + echo "\n-- Iteration $counter --\n"; + var_dump( shuffle($arr) ); + echo "\nThe output array is:\n"; + var_dump( $arr ); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : arrays with diff types of values *** + +*** Testing shuffle() with arrays having different types of values *** + +-- Iteration 1 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 2 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} + +-- Iteration 3 -- +bool(true) + +The output array is: +array(7) { + [0]=> + float(%f) + [1]=> + float(%f) + [2]=> + float(%f) + [3]=> + float(%f) + [4]=> + float(%f) + [5]=> + float(%f) + [6]=> + float(%f) +} + +-- Iteration 4 -- +bool(true) + +The output array is: +array(6) { + [0]=> + float(-%f) + [1]=> + float(-%f) + [2]=> + float(-%f) + [3]=> + float(-%f) + [4]=> + float(-%f) + [5]=> + float(-%f) +} + +-- Iteration 5 -- +bool(true) + +The output array is: +array(5) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" + [4]=> + string(%d) "%s" +} + +-- Iteration 6 -- +bool(true) + +The output array is: +array(4) { + [0]=> + bool(%s) + [1]=> + bool(%s) + [2]=> + bool(%s) + [3]=> + bool(%s) +} + +-- Iteration 7 -- +bool(true) + +The output array is: +array(6) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) + [4]=> + int(%d) + [5]=> + int(%d) +} + +-- Iteration 8 -- +bool(true) + +The output array is: +array(5) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) + [3]=> + int(-%d) + [4]=> + int(-%d) +} + +-- Iteration 9 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 10 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} +Done + diff --git a/ext/standard/tests/array/shuffle_variation4.phpt b/ext/standard/tests/array/shuffle_variation4.phpt new file mode 100644 index 0000000..516e7c9 --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation4.phpt @@ -0,0 +1,231 @@ +--TEST-- +Test shuffle() function : usage variation - associative arrays with diff types of values +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle() function when associative arrays +* having different types of values, are passed to 'array_arg' argument +*/ + +echo "*** Testing shuffle() : associative arrays with diff types of values ***\n"; + +// initialise different arrays +$array_arg = array( + // array with positive int values +/*1*/ array("zero" => 0, 1 => 1, "two" => 2, "max_int" => 2147483647 ), + + // array with negative int values + array("minus_one" => -1, 'minus_two' => -2, "min_int" => -2147483647 ), + + // array with positive float values +/*3*/ array("float1" => 0.23, 'float2' => 1.34, "exp1" => 0e2, 'exp2' => 200e-2, "exp3" => 10e0), + + // array with negative float values + array(-0.23 => -0.23, -1.34 => -1.34, -200e-2 => -200e-2, -30 => -30e0, -2147473649.80), + + // array with single and double quoted strings +/*5*/ array('1' => 'one', "str1" => "123numbers", '' => 'hello\tworld', "" => "hello world\0", "12.34floatnum"), + + // array with bool values + array('1' => TRUE, "1" => TRUE, "0" => FALSE, '0' => FALSE), + + // array with positive hexa values +/*7*/ array("hex1" => 0x123, 'hex2' => 0xabc, "hex\t3" => 0xABC, "hex\04" => 0xAb1), + + // array with negative hexa values + array(NULL => -0x123, "NULL" => -0xabc, "-ABC" => -0xABC, -0xAB1 => -0xAb1), + + // array with positive octal values +/*9*/ array(0123 => 0123, "02348" => 02348, '034' => 034, 00 => 00), + + // array with negative octal values + array(-0123 => -0123, "-02348" => -02348, '-034' => -034), + + // array with null values +/*11*/ array(NULL => NULL, "null" => NULL, "NULL" => NULL) + +); + +// looping to test shuffle() with each sub-array in the $array_arg array +echo "\n*** Testing shuffle() with arrays having different types of values ***\n"; +$counter = 1; +foreach($array_arg as $arr) { + echo "\n-- Iteration $counter --\n"; + var_dump( shuffle($arr) ); + echo "\nThe output array is:\n"; + var_dump( $arr ); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing shuffle() : associative arrays with diff types of values *** + +*** Testing shuffle() with arrays having different types of values *** + +-- Iteration 1 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 2 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} + +-- Iteration 3 -- +bool(true) + +The output array is: +array(5) { + [0]=> + float(%f) + [1]=> + float(%f) + [2]=> + float(%f) + [3]=> + float(%f) + [4]=> + float(%f) +} + +-- Iteration 4 -- +bool(true) + +The output array is: +array(5) { + [0]=> + float(-%f) + [1]=> + float(-%f) + [2]=> + float(-%f) + [3]=> + float(-%f) + [4]=> + float(-%f) +} + +-- Iteration 5 -- +bool(true) + +The output array is: +array(4) { + [0]=> + string(%d) "%s" + [1]=> + string(%d) "%s" + [2]=> + string(%d) "%s" + [3]=> + string(%d) "%s" +} + +-- Iteration 6 -- +bool(true) + +The output array is: +array(2) { + [0]=> + bool(%s) + [1]=> + bool(%s) +} + +-- Iteration 7 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 8 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) + [3]=> + int(-%d) +} + +-- Iteration 9 -- +bool(true) + +The output array is: +array(4) { + [0]=> + int(%d) + [1]=> + int(%d) + [2]=> + int(%d) + [3]=> + int(%d) +} + +-- Iteration 10 -- +bool(true) + +The output array is: +array(3) { + [0]=> + int(-%d) + [1]=> + int(-%d) + [2]=> + int(-%d) +} + +-- Iteration 11 -- +bool(true) + +The output array is: +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +Done + diff --git a/ext/standard/tests/array/shuffle_variation5.phpt b/ext/standard/tests/array/shuffle_variation5.phpt new file mode 100644 index 0000000..ca2c1ac --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation5.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test shuffle() function : usage variation - arrays with diff heredoc strings +--FILE-- +<?php +/* Prototype : bool shuffle(array $array_arg) + * Description: Randomly shuffle the contents of an array + * Source code: ext/standard/array.c +*/ + +/* +* Test behaviour of shuffle() when an array of heredoc strings is passed to +* 'array_arg' argument of the function +*/ + +echo "*** Testing shuffle() : with array containing heredoc strings ***\n"; + +// defining different heredoc strings +$empty_heredoc = <<<EOT +EOT; + +$heredoc_with_newline = <<<EOT +\n +EOT; + +$heredoc_with_characters = <<<EOT +first line of heredoc string +second line of heredoc string +third line of heredocstring +EOT; + +$heredoc_with_newline_and_tabs = <<<EOT +hello\tworld\nhello\nworld\n +EOT; + +$heredoc_with_alphanumerics = <<<EOT +hello123world456 +1234hello\t1234 +EOT; + +$heredoc_with_embedded_nulls = <<<EOT +hello\0world\0hello +\0hello\0 +EOT; + +// defining array with values as heredoc strings +$heredoc_array = array( + $empty_heredoc, + $heredoc_with_newline, + $heredoc_with_characters, + $heredoc_with_newline_and_tabs, + $heredoc_with_alphanumerics, + $heredoc_with_embedded_nulls +); + +// defining array with keys as heredoc strings +$heredoc_asso_array = array( + $empty_heredoc => "heredoc1", + $heredoc_with_newline => "heredoc2", + $heredoc_with_characters => "heredoc3", + $heredoc_with_newline_and_tabs => "heredoc3", + $heredoc_with_alphanumerics => "heredoc4", + $heredoc_with_embedded_nulls => "heredoc5" +); + +// test shuffle() with array containing heredoc strings as values +echo "\n-- with array of heredoc strings --\n"; +var_dump( shuffle($heredoc_array) ); +echo "\nThe output array is:\n"; +var_dump( $heredoc_array ); + +// test shuffle() with array containing heredoc strings as its keys +echo "\n-- with array having heredoc strings as keys --\n"; +var_dump( shuffle($heredoc_asso_array) ); +echo "\nThe output array is:\n"; +var_dump( $heredoc_asso_array ); + +echo "Done"; +?> +--EXPECTREGEX-- +\*\*\* Testing shuffle\(\) : with array containing heredoc strings \*\*\* + +-- with array of heredoc strings -- +bool\(true\) + +The output array is: +array\(6\) { + \[0\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[1\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[2\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[3\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[4\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" + \[5\]=> + string\([0-9]*\) "[0-9 a-z \n \0 \t]*" +} + +-- with array having heredoc strings as keys -- +bool\(true\) + +The output array is: +array\(6\) { + \[0\]=> + string\(8\) "[heredoc 1-5]*" + \[1\]=> + string\(8\) "[heredoc 1-5]*" + \[2\]=> + string\(8\) "[heredoc 1-5]*" + \[3\]=> + string\(8\) "[heredoc 1-5]*" + \[4\]=> + string\(8\) "[heredoc 1-5]*" + \[5\]=> + string\(8\) "[heredoc 1-5]*" +} +Done + diff --git a/ext/standard/tests/array/sizeof_basic1.phpt b/ext/standard/tests/array/sizeof_basic1.phpt new file mode 100644 index 0000000..dea4a68 --- /dev/null +++ b/ext/standard/tests/array/sizeof_basic1.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test sizeof() function : basic functionality - for scalar types +--FILE-- +<?php +/* Prototype : int sizeof(mixed $var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP library is + * installed, it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +/* Testing the sizeof() for some of the scalar types(integer, float) values + * in default, COUNT_NORMAL and COUNT_RECURSIVE modes. + */ + +echo "*** Testing sizeof() : basic functionality ***\n"; + +$intval = 10; +$floatval = 10.5; +$stringval = "String"; + +echo "-- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($intval) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($intval, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($intval, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($floatval) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($floatval, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($floatval, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : basic functionality *** +-- Testing sizeof() for integer type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- +default mode: int(1) + +COUNT_NORMAL mode: int(1) + +COUNT_RECURSIVE mode: int(1) + +-- Testing sizeof() for float type in default, COUNT_NORMAL and COUNT_RECURSIVE modes -- +default mode: int(1) + +COUNT_NORMAL mode: int(1) + +COUNT_RECURSIVE mode: int(1) +Done diff --git a/ext/standard/tests/array/sizeof_basic2.phpt b/ext/standard/tests/array/sizeof_basic2.phpt new file mode 100644 index 0000000..a2ab2ee --- /dev/null +++ b/ext/standard/tests/array/sizeof_basic2.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test sizeof() function : basic functionality - for non-scalar type(array) +--FILE-- +<?php +/* Prototype : int sizeof(mixed $var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP library is + * installed, it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +/* Testing the sizeof() for non-scalar type(array) value + * in default, COUNT_NORMAL and COUNT_RECURSIVE modes. + * Sizeof() has been tested for simple integer, string, + * indexed and mixed arrays. + */ + +echo "*** Testing sizeof() : basic functionality ***\n"; + +$int_array = array(1, 2, 3, 4); +$string_array = array("Saffron", "White", "Green"); +$indexed_array = array("Agression" => "Saffron", "Peace" => "White", "Growth" => "Green"); +$mixed_array = array(1, 2, "Aggression" => "Saffron", 10 => "Ten", "Ten" => 10); + +echo "-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($int_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($int_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($int_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($string_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($string_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($string_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($indexed_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($indexed_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($indexed_array, COUNT_RECURSIVE) ); +echo "\n"; + +echo "-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes --\n"; +echo "default mode: "; +var_dump( sizeof($mixed_array) ); +echo "\n"; +echo "COUNT_NORMAL mode: "; +var_dump( sizeof($mixed_array, COUNT_NORMAL) ); +echo "\n"; +echo "COUNT_RECURSIVE mode: "; +var_dump( sizeof($mixed_array, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : basic functionality *** +-- Testing sizeof() with integer array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(4) + +COUNT_NORMAL mode: int(4) + +COUNT_RECURSIVE mode: int(4) + +-- Testing sizeof() with string array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(3) + +COUNT_NORMAL mode: int(3) + +COUNT_RECURSIVE mode: int(3) + +-- Testing sizeof() with indexed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(3) + +COUNT_NORMAL mode: int(3) + +COUNT_RECURSIVE mode: int(3) + +-- Testing sizeof() with mixed array in default, COUNT_NORMAL, COUNT_RECURSIVE modes -- +default mode: int(5) + +COUNT_NORMAL mode: int(5) + +COUNT_RECURSIVE mode: int(5) +Done diff --git a/ext/standard/tests/array/sizeof_error.phpt b/ext/standard/tests/array/sizeof_error.phpt new file mode 100644 index 0000000..79a75f3 --- /dev/null +++ b/ext/standard/tests/array/sizeof_error.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test sizeof() function : error conditions +--FILE-- +<?php +/* Prototype : int sizeof(mixed $var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP Library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +// Calling sizeof() with zero and more than expected arguments . + +echo "*** Testing sizeof() : error conditions ***\n"; + +echo "-- Testing sizeof() with zero arguments --\n"; +var_dump( sizeof() ); +echo "-- Testing sizeof() function with more than two arguments under COUNT_NORMAL mode --\n"; +$var = 100; +$extra_arg = 10;; +var_dump( sizeof($var, COUNT_NORMAL, $extra_arg) ); +echo "-- Testing sizeof() function with more than two arguments under COUNT_RECURSIVE mode --\n"; +var_dump( sizeof($var, COUNT_RECURSIVE, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : error conditions *** +-- Testing sizeof() with zero arguments -- + +Warning: sizeof() expects at least 1 parameter, 0 given in %s on line %d +NULL +-- Testing sizeof() function with more than two arguments under COUNT_NORMAL mode -- + +Warning: sizeof() expects at most 2 parameters, 3 given in %s on line %d +NULL +-- Testing sizeof() function with more than two arguments under COUNT_RECURSIVE mode -- + +Warning: sizeof() expects at most 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/sizeof_object1.phpt b/ext/standard/tests/array/sizeof_object1.phpt new file mode 100644 index 0000000..4705996 --- /dev/null +++ b/ext/standard/tests/array/sizeof_object1.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test sizeof() function : object functionality - object with Countable interface +--SKIPIF-- +<?php +// Skip the test case if Standard PHP Library(spl) is not installed + if( !extension_loaded('spl')) + { + die('skip spl is not installed'); + } +?> +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : object functionality ***\n"; + +echo "-- Testing sizeof() with an object which implements Countable interface --\n"; +class sizeof_class implements Countable +{ + public $member1; + private $member2; + protected $member3; + + public function count() + { + return 3; // return the count of member variables in the object + } +} + +$obj = new sizeof_class(); + +echo "-- Testing sizeof() in default mode --\n"; +var_dump( sizeof($obj) ); +echo "-- Testing sizeof() in COUNT_NORMAL mode --\n"; +var_dump( sizeof($obj, COUNT_NORMAL) ); +echo "-- Testing sizeof() in COUNT_RECURSIVE mode --\n"; +var_dump( sizeof($obj, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : object functionality *** +-- Testing sizeof() with an object which implements Countable interface -- +-- Testing sizeof() in default mode -- +int(3) +-- Testing sizeof() in COUNT_NORMAL mode -- +int(3) +-- Testing sizeof() in COUNT_RECURSIVE mode -- +int(3) +Done diff --git a/ext/standard/tests/array/sizeof_object2.phpt b/ext/standard/tests/array/sizeof_object2.phpt new file mode 100644 index 0000000..e2c0816 --- /dev/null +++ b/ext/standard/tests/array/sizeof_object2.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test sizeof() function : object functionality - objects without Countable interface +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode] ) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : object functionality ***\n"; + +echo "--- Testing sizeof() with objects which doesn't implement Countable interface ---\n"; + +// class without member +class test +{ + // no members +} + +// class with only members and with out member functions +class test1 +{ + public $member1; + var $var1; + private $member2; + protected $member3; + + // no member functions +} + +// class with only member functions +class test2 +{ + // no data members + + public function display() + { + echo " Class Name : test2\n"; + } +} + +// child class which inherits parent test2 +class child_test2 extends test2 +{ + public $child_member1; + private $child_member2; +} + +// abstract class +abstract class abstract_class +{ + public $member1; + private $member2; + + abstract protected function display(); +} + +// implement abstract 'abstract_class' class +class concrete_class extends abstract_class +{ + protected function display() + { + echo " class name is : concrete_class \n "; + } +} + +$objects = array ( + /* 1 */ new test(), + new test1(), + new test2(), + new child_test2(), + /* 5 */ new concrete_class() +); + +$counter = 1; +for($i = 0; $i < count($objects); $i++) +{ + echo "-- Iteration $counter --\n"; + $var = $objects[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : object functionality *** +--- Testing sizeof() with objects which doesn't implement Countable interface --- +-- Iteration 1 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 2 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 3 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 4 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 5 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +Done diff --git a/ext/standard/tests/array/sizeof_variation1.phpt b/ext/standard/tests/array/sizeof_variation1.phpt new file mode 100644 index 0000000..328645f --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation1.phpt @@ -0,0 +1,215 @@ +--TEST-- +Test sizeof() function : usage variations - for all scalar types and resource variable +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "--- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode ---\n"; +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// array containing all scalar types +$values = array ( + // int values + /* 1 */ 0, + 1, + + // float values + /* 3 */ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + /* 7 */ .5, + + // NULL values + /* 8 */ NULL, + null, + + // boolean values + /* 10 */ TRUE, + FALSE, + true, + /* 13 */ false, + + // string data + /* 14 */ "", + '', + "string", + /* 17 */ 'string', + + // undefined variable + @$undefined_var, + + // resource variable + /* 19 */ $fp +); + +// loop through the each value of the array for 'var' argument and check the behaviour of sizeof() +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + + $var = $values[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() for all scalar types in default,COUNT_NORMAL and COUNT_RECURSIVE mode --- +-- Iteration 1 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 2 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 3 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 4 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 5 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 6 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 7 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 8 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 9 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 10 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 11 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 12 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 13 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 14 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 15 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 16 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 17 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +-- Iteration 18 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 19 -- +Default Mode: int(1) + +COUNT_NORMAL Mode: int(1) + +COUNT_RECURSIVE Mode: int(1) + +Done diff --git a/ext/standard/tests/array/sizeof_variation2.phpt b/ext/standard/tests/array/sizeof_variation2.phpt new file mode 100644 index 0000000..a224579 --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation2.phpt @@ -0,0 +1,163 @@ +--TEST-- +Test sizeof() function : usage variations - different array values for 'var' argument +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +echo "--- Testing sizeof() with different array values for 'var' argument ---\n"; + +// array containing different types of array values for 'var' argument +$values = array ( + /* 1 */ array($fp, "resource" => $fp), + array(1, array(3, 4, array(6, array(8)))), + array("a" => 1, 'b' => 2, array( "c" =>3, array( "d" => 5))), + array(), + /* 5 */ array(1, 2, 3, 4), + array("Saffron", "White", "Green"), + array('saffron', 'white', 'green'), + array(1 => "Hi", 2 => "Hello" ), + array("color" => "red", "item" => "pen"), + /* 10 */ array('color' => 'red', 'item' => 'pen'), + array(TRUE => "red", FALSE => "pen" ), + array(false => 'red', true => 'pen' ), + array('color' => "red", "item" => 'pen', 1 => "Hi", "" => "Hello" ), + /* 14 */ array($fp, "resource1" => $fp, 'resource2' => $fp, array( $fp, 'type' => $fp) ) +); + +// loop through each element of the values array for 'var' argument +// check the working of sizeof() +$counter = 1; +for($i = 0; $i < count($values); $i++) +{ + echo "-- Iteration $counter --\n"; + $var = $values[$i]; + + echo "Default Mode: "; + var_dump( sizeof($var) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($var, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($var, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() with different array values for 'var' argument --- +-- Iteration 1 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 2 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(8) + +-- Iteration 3 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(6) + +-- Iteration 4 -- +Default Mode: int(0) + +COUNT_NORMAL Mode: int(0) + +COUNT_RECURSIVE Mode: int(0) + +-- Iteration 5 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(4) + +-- Iteration 6 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(3) + +-- Iteration 7 -- +Default Mode: int(3) + +COUNT_NORMAL Mode: int(3) + +COUNT_RECURSIVE Mode: int(3) + +-- Iteration 8 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 9 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 10 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 11 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 12 -- +Default Mode: int(2) + +COUNT_NORMAL Mode: int(2) + +COUNT_RECURSIVE Mode: int(2) + +-- Iteration 13 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(4) + +-- Iteration 14 -- +Default Mode: int(4) + +COUNT_NORMAL Mode: int(4) + +COUNT_RECURSIVE Mode: int(6) + +Done diff --git a/ext/standard/tests/array/sizeof_variation3.phpt b/ext/standard/tests/array/sizeof_variation3.phpt new file mode 100644 index 0000000..ba8afb8 --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation3.phpt @@ -0,0 +1,34 @@ +--TEST-- +Test sizeof() function : usage variations - checking for infinite recursion in COUNT_RECURSIVE mode +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "-- Testing sizeof() for infinite recursion with arrays as argument in COUNT_RECURSIVE mode --\n"; + +$array2 = array ( "Hi", "Hello",@$a); +$array3 = array( 'hi', 'hello'); +$a = array ( 1, @$array1, $array2, $array3); +$array1 = array( array(1, 2), $a); +$array4 = array( 100, @$array4); + +var_dump( sizeof($array1, COUNT_RECURSIVE) ); +echo "\n"; +var_dump( sizeof($array4, COUNT_RECURSIVE) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +-- Testing sizeof() for infinite recursion with arrays as argument in COUNT_RECURSIVE mode -- +int(13) + +int(2) +Done diff --git a/ext/standard/tests/array/sizeof_variation4.phpt b/ext/standard/tests/array/sizeof_variation4.phpt new file mode 100644 index 0000000..a246275 --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation4.phpt @@ -0,0 +1,350 @@ +--TEST-- +Test sizeof() function : usage variations - all kinds of unset variables for 'var' argument +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "--- Testing sizeof() for all kinds of unset variables in default, Normal and Recursive Modes ---\n"; + +// class declaration +class test +{ + public $member1; +} + +// get an resource variable +$fp = fopen(__FILE__, "r"); + +// array containing different types of variables +$values = array ( + // int values + /* 1 */ 0, + 1, + // float values + /* 3 */ 10.5, + -10.5, + 12.34e3, + /* 6 */ 12.34E-3, + // string values + /* 7 */ "string", + 'string', + "", + /* 10 */ '', + // NULL values + /* 11 */ NULL, + null, + // Boolean Values + /* 12 */ TRUE, + true, + false, + /* 16 */ FALSE, + // array values + /* 17 */ array(), + array(1, 2, 3,4 , array(5, 6)), + // object variable + /* 19 */ new test(), + // resource variable + /* 20 */ $fp +); + +// loop through the each element of the $values array for 'var' arugment +// and check the functionality of sizeof() +$counter = 1; +foreach($values as $value) +{ + echo "-- Iteration $counter --\n"; + + // unset the variable + unset($value); + + // now check the size of unset variable when different modes are given + echo "Default Mode: "; + var_dump( sizeof($value) ); + echo "\n"; + + echo "COUNT_NORMAL Mode: "; + var_dump( sizeof($value, COUNT_NORMAL) ); + echo "\n"; + + echo "COUNT_RECURSIVE Mode: "; + var_dump( sizeof($value, COUNT_RECURSIVE) ); + echo "\n"; + + $counter++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() for all kinds of unset variables in default, Normal and Recursive Modes --- +-- Iteration 1 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 2 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 3 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 4 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 5 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 6 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 7 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 8 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 9 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 10 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 11 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 12 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 13 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 14 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 15 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 16 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 17 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 18 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 19 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +-- Iteration 20 -- +Default Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_NORMAL Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +COUNT_RECURSIVE Mode: +Notice: Undefined variable: value in %s on line %d +int(0) + +Done diff --git a/ext/standard/tests/array/sizeof_variation5.phpt b/ext/standard/tests/array/sizeof_variation5.phpt new file mode 100644 index 0000000..6e40f7e --- /dev/null +++ b/ext/standard/tests/array/sizeof_variation5.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test sizeof() function : usage variations - different values for 'mode' argument +--FILE-- +<?php +/* Prototype : int sizeof($mixed var[, int $mode]) + * Description: Counts an elements in an array. If Standard PHP library is installed, + * it will return the properties of an object. + * Source code: ext/standard/basic_functions.c + * Alias to functions: count() + */ + +echo "*** Testing sizeof() : usage variations ***\n"; + +echo "--- Testing sizeof() with different values for 'mode' argument ---\n"; +$array1 = array(1, 2, 3, 4, array(1.0, 2.0, array()), array() ); + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +//unset variable +$unset_var = 10; +unset($unset_var); + +//class declaration +class test +{ + public $member1; +} + +$mode_values = array ( + /* 1 */ COUNT_NORMAL, + COUNT_RECURSIVE, + 0, // same as COUNT_NORMAL + 1, // same as COUNT_RECURSIVE + + /* 5 */ TRUE, // same as COUNT_RECURSIVE + true, // same as COUNT_RECURSIVE + FALSE, // same as COUNT_NORMAL + false, // same as COUNT_NORMAL + NULL, // same as COUNT_NORMAL + /* 10 */ null, // same as COUNT_NORMAL + 100, + 10.5, + 12.34e3, + 12.34E-2, + /* 15 */ .5, + "", + '', + "string", + 'string', + /* 20 */ @$unset_var, + new test(), + /* 22 */ $fp +); + +// loop through the each element of $modes_array for 'mode' argument +// and check the working of sizeof() +$counter = 1; +for($i = 0; $i < count($mode_values); $i++) +{ + echo "-- Iteration $counter --\n"; + $mode = $mode_values[$i]; + + var_dump( sizeof($array1, $mode) ); + + $counter++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing sizeof() : usage variations *** +--- Testing sizeof() with different values for 'mode' argument --- +-- Iteration 1 -- +int(6) +-- Iteration 2 -- +int(9) +-- Iteration 3 -- +int(6) +-- Iteration 4 -- +int(9) +-- Iteration 5 -- +int(9) +-- Iteration 6 -- +int(9) +-- Iteration 7 -- +int(6) +-- Iteration 8 -- +int(6) +-- Iteration 9 -- +int(6) +-- Iteration 10 -- +int(6) +-- Iteration 11 -- +int(6) +-- Iteration 12 -- +int(6) +-- Iteration 13 -- +int(6) +-- Iteration 14 -- +int(6) +-- Iteration 15 -- +int(6) +-- Iteration 16 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: sizeof() expects parameter 2 to be long, string given in %s on line %d +NULL +-- Iteration 20 -- +int(6) +-- Iteration 21 -- + +Warning: sizeof() expects parameter 2 to be long, object given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: sizeof() expects parameter 2 to be long, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/sort_basic.phpt b/ext/standard/tests/array/sort_basic.phpt new file mode 100644 index 0000000..460b572 --- /dev/null +++ b/ext/standard/tests/array/sort_basic.phpt @@ -0,0 +1,246 @@ +--TEST-- +Test sort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing sort() by providing arrays with default keys and assoc arrays + * to check the basic functionality with following flag values. + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing sort() : basic functionality ***\n"; + +// associative array containing unsorted string values +$unsorted_strings = array( + "l" => "lemon", "o" => "orange", + "O" => "Orange", "O1" => "Orange1", "o2" => "orange2", "O3" => "Orange3", "o20" => "orange20", + "b" => "banana", +); + +// array with default keys containing unsorted numeric values +$unsorted_numerics = array( 100, 33, 555, 22 ); + +echo "\n-- Testing sort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_STRING|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array (natural), 'flag' = SORT_NATURAL --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_NATURAL) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE --\n"; +$temp_array = $unsorted_strings; +var_dump( sort($temp_array, SORT_NATURAL|SORT_FLAG_CASE) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : basic functionality *** + +-- Testing sort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + int(22) + [1]=> + int(33) + [2]=> + int(100) + [3]=> + int(555) +} + +-- Testing sort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + int(22) + [1]=> + int(33) + [2]=> + int(100) + [3]=> + int(555) +} + +-- Testing sort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying string array (case insensitive), 'flag' = SORT_STRING|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(6) "banana" + [1]=> + string(5) "lemon" + [2]=> + string(6) "orange" + [3]=> + string(6) "Orange" + [4]=> + string(7) "Orange1" + [5]=> + string(7) "orange2" + [6]=> + string(8) "orange20" + [7]=> + string(7) "Orange3" +} + +-- Testing sort() by supplying string array (natural), 'flag' = SORT_NATURAL -- +bool(true) +array(8) { + [0]=> + string(6) "Orange" + [1]=> + string(7) "Orange1" + [2]=> + string(7) "Orange3" + [3]=> + string(6) "banana" + [4]=> + string(5) "lemon" + [5]=> + string(6) "orange" + [6]=> + string(7) "orange2" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying string array (natural, case insensitive), 'flag' = SORT_NATURAL|SORT_FLAG_CASE -- +bool(true) +array(8) { + [0]=> + string(6) "banana" + [1]=> + string(5) "lemon" + [2]=> + string(6) "orange" + [3]=> + string(6) "Orange" + [4]=> + string(7) "Orange1" + [5]=> + string(7) "orange2" + [6]=> + string(7) "Orange3" + [7]=> + string(8) "orange20" +} + +-- Testing sort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + int(22) + [1]=> + int(33) + [2]=> + int(100) + [3]=> + int(555) +} +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/sort_error.phpt b/ext/standard/tests/array/sort_error.phpt new file mode 100644 index 0000000..4864ef3 --- /dev/null +++ b/ext/standard/tests/array/sort_error.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test sort() function : error conditions +--FILE-- +<?php +/* Prototype : bool sort(array &array_arg [, int sort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* +* Testing sort() function with all possible error conditions +*/ + +echo "*** Testing sort() : error conditions ***\n"; + +// zero arguments +echo "\n-- Testing sort() function with Zero arguments --\n"; +var_dump( sort() ); + +//Test sort with more than the expected number of arguments +echo "\n-- Testing sort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and setting all possible flag values +foreach($flag_value as $key => $flag){ + echo "\nSort flag = $key\n"; + var_dump( sort($array_arg,$flag, $extra_arg) ); + + // dump the input array to ensure that it wasn't changed + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sort() : error conditions *** + +-- Testing sort() function with Zero arguments -- + +Warning: sort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing sort() function with more than expected no. of arguments -- + +Sort flag = SORT_REGULAR + +Warning: sort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_STRING + +Warning: sort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_NUMERIC + +Warning: sort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/sort_object1.phpt b/ext/standard/tests/array/sort_object1.phpt new file mode 100644 index 0000000..caa9c8d --- /dev/null +++ b/ext/standard/tests/array/sort_object1.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test sort() function : object functionality - sorting objects, 'sort_flags' as default/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ +/* + * testing sort() by providing integer/string object arrays with flag values are defualt, SORT_REGULAR +*/ + +echo "*** Testing sort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_sort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + +} + +// class declaration for string objects +class for_string_sort +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array( + new for_integer_sort(11), new for_integer_sort(66), + new for_integer_sort(23), new for_integer_sort(-5), + new for_integer_sort(0.001), new for_integer_sort(0) +); + +// array of string objects +$unsorted_str_obj = array ( + new for_string_sort("axx"), new for_string_sort("t"), + new for_string_sort("w"), new for_string_sort("py"), + new for_string_sort("apple"), new for_string_sort("Orange"), + new for_string_sort("Lemon"), new for_string_sort("aPPle") +); + + +echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing sort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(sort($temp_array) ); +var_dump($temp_array); + +// testing sort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(sort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing sort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(sort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing sort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(sort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : object functionality *** + +-- Testing sort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [0]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(-5) + } + [1]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(0) + } + [2]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [3]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(11) + } + [4]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(23) + } + [5]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [1]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [2]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [3]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [4]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [5]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [6]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [7]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} + +-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [0]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(-5) + } + [1]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(0) + } + [2]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + float(0.001) + } + [3]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(11) + } + [4]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(23) + } + [5]=> + object(for_integer_sort)#%d (1) { + ["class_value"]=> + int(66) + } +} +bool(true) +array(8) { + [0]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } + [1]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + [2]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + [3]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + [4]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + [5]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(2) "py" + } + [6]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "t" + } + [7]=> + object(for_string_sort)#%d (1) { + ["class_value"]=> + string(1) "w" + } +} +Done diff --git a/ext/standard/tests/array/sort_object2.phpt b/ext/standard/tests/array/sort_object2.phpt new file mode 100644 index 0000000..93b0fa2 --- /dev/null +++ b/ext/standard/tests/array/sort_object2.phpt @@ -0,0 +1,256 @@ +--TEST-- +Test sort() function : object functionality - sorting objects with diff. accessibility of member vars +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing integer/string object arrays with flag values are defualt, SORT_REGULAR +*/ + +echo "*** Testing sort() : object functionality ***\n"; + +// class declaration for integer objects +class for_integer_sort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } +} + +// class declaration for string objects +class for_string_sort +{ + public $public_class_value; + private $private_class_value; + protected $protected_class_value; + // initializing object member value + function __construct($value1, $value2,$value3){ + $this->public_class_value = $value1; + $this->private_class_value = $value2; + $this->protected_class_value = $value3; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects +$unsorted_int_obj = array( + new for_integer_sort(11,33,30), + new for_integer_sort(66,44,4), + new for_integer_sort(-88,-5,5), + new for_integer_sort(0.001,99.5,0.1) +); + +// array of string objects +$unsorted_str_obj = array ( + new for_string_sort("axx","AXX","ass"), + new for_string_sort("t","eee","abb"), + new for_string_sort("w","W", "c"), + new for_string_sort("py","PY", "pt"), +); + + +echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing sort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(sort($temp_array) ); +var_dump($temp_array); + +// testing sort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(sort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing sort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(sort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing sort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(sort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : object functionality *** + +-- Testing sort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_sort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } + [1]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_sort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [2]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_sort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [3]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_sort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_sort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } + [1]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_sort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [2]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_sort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [3]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_sort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} + +-- Testing sort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(-88) + ["private_class_value":"for_integer_sort":private]=> + int(-5) + ["protected_class_value":protected]=> + int(5) + } + [1]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + float(0.001) + ["private_class_value":"for_integer_sort":private]=> + float(99.5) + ["protected_class_value":protected]=> + float(0.1) + } + [2]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value":"for_integer_sort":private]=> + int(33) + ["protected_class_value":protected]=> + int(30) + } + [3]=> + object(for_integer_sort)#%d (3) { + ["public_class_value"]=> + int(66) + ["private_class_value":"for_integer_sort":private]=> + int(44) + ["protected_class_value":protected]=> + int(4) + } +} +bool(true) +array(4) { + [0]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(3) "axx" + ["private_class_value":"for_string_sort":private]=> + string(3) "AXX" + ["protected_class_value":protected]=> + string(3) "ass" + } + [1]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(2) "py" + ["private_class_value":"for_string_sort":private]=> + string(2) "PY" + ["protected_class_value":protected]=> + string(2) "pt" + } + [2]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "t" + ["private_class_value":"for_string_sort":private]=> + string(3) "eee" + ["protected_class_value":protected]=> + string(3) "abb" + } + [3]=> + object(for_string_sort)#%d (3) { + ["public_class_value"]=> + string(1) "w" + ["private_class_value":"for_string_sort":private]=> + string(1) "W" + ["protected_class_value":protected]=> + string(1) "c" + } +} +Done diff --git a/ext/standard/tests/array/sort_variation1.phpt b/ext/standard/tests/array/sort_variation1.phpt new file mode 100644 index 0000000..f6991bd --- /dev/null +++ b/ext/standard/tests/array/sort_variation1.phpt @@ -0,0 +1,398 @@ +--TEST-- +Test sort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool sort(array &array_arg [, int $sort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing different unexpected values for array argument + * with following flag values. + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +//array of values to iterate over +$unexpected_values = array ( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e3, + 10.6E-2, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new stdclass(), + + // undefined data +/*21*/ @undefined_var, + + // unset data +/*22*/ @unset_var, + + // resource variable +/*23*/ $fp +); + +// loop though each element of the array and check the working of sort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing sort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( sort($value) ); // expecting : bool(false) + var_dump( sort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( sort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( sort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: sort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: sort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: sort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/sort_variation10.phpt b/ext/standard/tests/array/sort_variation10.phpt new file mode 100644 index 0000000..0a5a580 --- /dev/null +++ b/ext/standard/tests/array/sort_variation10.phpt @@ -0,0 +1,112 @@ +--TEST-- +Test sort() function : usage variations - sort octal values +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing different octal array for $array argument + * with following flag values + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * 3.SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +// an array containing unsorted octal values +$unsorted_oct_array = array(01235, 0321, 0345, 066, 0772, 077, -066, -0345, 0); + +echo "\n-- Testing sort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump(sort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump(sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump(sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [0]=> + int(-229) + [1]=> + int(-54) + [2]=> + int(0) + [3]=> + int(54) + [4]=> + int(63) + [5]=> + int(209) + [6]=> + int(229) + [7]=> + int(506) + [8]=> + int(669) +} + +-- Testing sort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [0]=> + int(-229) + [1]=> + int(-54) + [2]=> + int(0) + [3]=> + int(54) + [4]=> + int(63) + [5]=> + int(209) + [6]=> + int(229) + [7]=> + int(506) + [8]=> + int(669) +} + +-- Testing sort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [0]=> + int(-229) + [1]=> + int(-54) + [2]=> + int(0) + [3]=> + int(54) + [4]=> + int(63) + [5]=> + int(209) + [6]=> + int(229) + [7]=> + int(506) + [8]=> + int(669) +} +Done diff --git a/ext/standard/tests/array/sort_variation11.phpt b/ext/standard/tests/array/sort_variation11.phpt Binary files differnew file mode 100644 index 0000000..56583d2 --- /dev/null +++ b/ext/standard/tests/array/sort_variation11.phpt diff --git a/ext/standard/tests/array/sort_variation2.phpt b/ext/standard/tests/array/sort_variation2.phpt new file mode 100644 index 0000000..7cb8ed6 --- /dev/null +++ b/ext/standard/tests/array/sort_variation2.phpt @@ -0,0 +1,311 @@ +--TEST-- +Test sort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- +<?php +/* Prototype : bool sort(array &array_arg [, int $sort_flags]) + * Description: Sort an array + * Source code: ext/standard/array.c +*/ + +/* + * Testing sort() by providing different unexpected values for flag argument +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// resource variable +$fp = fopen(__FILE__, "r"); + +// temperory array for checking unexpected behavior +$unsorted_values = array(10, 2, 45); + +//array of values to iterate over +$unexpected_values = array( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of sort() +// when $flag arugment is supplied with different values +echo "\n-- Testing sort() by supplying different unexpected values for 'flag' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + + // sort the array, retain a temp. copy of input array for next iteration + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( sort($temp_array, $value) ); + + //dump the sorted array + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying different unexpected values for 'flag' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 2 -- +bool(true) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 3 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 4 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 5 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 6 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 7 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 8 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 9 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 10 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 11 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 12 -- +bool(true) +array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(45) +} +-- Iteration 13 -- + +Warning: sort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 14 -- + +Warning: sort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 15 -- + +Warning: sort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 16 -- + +Warning: sort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 17 -- + +Warning: sort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 18 -- + +Warning: sort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 19 -- + +Warning: sort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +-- Iteration 20 -- + +Warning: sort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [0]=> + int(10) + [1]=> + int(2) + [2]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/sort_variation3.phpt b/ext/standard/tests/array/sort_variation3.phpt new file mode 100644 index 0000000..1ad058d --- /dev/null +++ b/ext/standard/tests/array/sort_variation3.phpt @@ -0,0 +1,328 @@ +--TEST-- +Test sort() function : usage variations - sort integer/float values +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing sort() by providing different integer/float value arrays for $array argument + * with following flag values + * 1. flag value as defualt + * 2. SORT_REGULAR - compare items normally + * 3. SORT_NUMERIC - compare items numerically + * 4. SORT_STRING - compare items as strings +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +// group of various arrays +$various_arrays = array ( + // negative/posative integers array + array(11, -11, 21, -21, 31, -31, 0, 41, -41), + + // float value array + array(10.5, -10.5, 10.5e2, 10.6E-2, .5, .01, -.1), + + // mixed value array + array(.0001, .0021, -.01, -1, 0, .09, 2, -.9, 10.6E-2, -10.6E-2, 33), + + // array values contains minimum and maximum ranges + array(2147483647, 2147483648, -2147483647, -2147483648, -0, 0, -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing sort() by supplying various integer/float arrays --\n"; + +// loop through to test sort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Defualt sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(sort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With Defualt sort flag - +bool(true) +array(9) { + [0]=> + int(-41) + [1]=> + int(-31) + [2]=> + int(-21) + [3]=> + int(-11) + [4]=> + int(0) + [5]=> + int(11) + [6]=> + int(21) + [7]=> + int(31) + [8]=> + int(41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [0]=> + int(-41) + [1]=> + int(-31) + [2]=> + int(-21) + [3]=> + int(-11) + [4]=> + int(0) + [5]=> + int(11) + [6]=> + int(21) + [7]=> + int(31) + [8]=> + int(41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [0]=> + int(-41) + [1]=> + int(-31) + [2]=> + int(-21) + [3]=> + int(-11) + [4]=> + int(0) + [5]=> + int(11) + [6]=> + int(21) + [7]=> + int(31) + [8]=> + int(41) +} + +-- Iteration 2 -- +- With Defualt sort flag - +bool(true) +array(7) { + [0]=> + float(-10.5) + [1]=> + float(-0.1) + [2]=> + float(0.01) + [3]=> + float(0.106) + [4]=> + float(0.5) + [5]=> + float(10.5) + [6]=> + float(1050) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + float(-10.5) + [1]=> + float(-0.1) + [2]=> + float(0.01) + [3]=> + float(0.106) + [4]=> + float(0.5) + [5]=> + float(10.5) + [6]=> + float(1050) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + float(-10.5) + [1]=> + float(-0.1) + [2]=> + float(0.01) + [3]=> + float(0.106) + [4]=> + float(0.5) + [5]=> + float(10.5) + [6]=> + float(1050) +} + +-- Iteration 3 -- +- With Defualt sort flag - +bool(true) +array(11) { + [0]=> + int(-1) + [1]=> + float(-0.9) + [2]=> + float(-0.106) + [3]=> + float(-0.01) + [4]=> + int(0) + [5]=> + float(0.0001) + [6]=> + float(0.0021) + [7]=> + float(0.09) + [8]=> + float(0.106) + [9]=> + int(2) + [10]=> + int(33) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [0]=> + int(-1) + [1]=> + float(-0.9) + [2]=> + float(-0.106) + [3]=> + float(-0.01) + [4]=> + int(0) + [5]=> + float(0.0001) + [6]=> + float(0.0021) + [7]=> + float(0.09) + [8]=> + float(0.106) + [9]=> + int(2) + [10]=> + int(33) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [0]=> + int(-1) + [1]=> + float(-0.9) + [2]=> + float(-0.106) + [3]=> + float(-0.01) + [4]=> + int(0) + [5]=> + float(0.0001) + [6]=> + float(0.0021) + [7]=> + float(0.09) + [8]=> + float(0.106) + [9]=> + int(2) + [10]=> + int(33) +} + +-- Iteration 4 -- +- With Defualt sort flag - +bool(true) +array(7) { + [0]=> + %s(-2147483649) + [1]=> + %s(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) + [4]=> + int(0) + [5]=> + int(2147483647) + [6]=> + %s(2147483648) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(7) { + [0]=> + %s(-2147483649) + [1]=> + %s(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) + [4]=> + int(0) + [5]=> + int(2147483647) + [6]=> + %s(2147483648) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(7) { + [0]=> + %s(-2147483649) + [1]=> + %s(-2147483648) + [2]=> + int(-2147483647) + [3]=> + int(0) + [4]=> + int(0) + [5]=> + int(2147483647) + [6]=> + %s(2147483648) +} +Done diff --git a/ext/standard/tests/array/sort_variation4.phpt b/ext/standard/tests/array/sort_variation4.phpt new file mode 100644 index 0000000..82e3d97 --- /dev/null +++ b/ext/standard/tests/array/sort_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test sort() function : usage variations - sort reference values +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing sort() by providing reference variable array with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing sort() :usage variations ***\n"; + +$value1 = 100; +$value2 = 33; +$value3 = 555; + +// an array containing integer references +$unsorted_numerics = array( &$value1 , &$value2, &$value3); + +echo "\n-- Testing sort() by supplying reference variable array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( sort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing sort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() :usage variations *** + +-- Testing sort() by supplying reference variable array, 'flag' value is defualt -- +bool(true) +array(3) { + [0]=> + &int(33) + [1]=> + &int(100) + [2]=> + &int(555) +} + +-- Testing sort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [0]=> + &int(33) + [1]=> + &int(100) + [2]=> + &int(555) +} + +-- Testing sort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [0]=> + &int(33) + [1]=> + &int(100) + [2]=> + &int(555) +} +Done diff --git a/ext/standard/tests/array/sort_variation5.phpt b/ext/standard/tests/array/sort_variation5.phpt new file mode 100644 index 0000000..a06c22c --- /dev/null +++ b/ext/standard/tests/array/sort_variation5.phpt @@ -0,0 +1,238 @@ +--TEST-- +Test sort() function : usage variations - sort strings +--SKIPIF-- +<?php +if (substr(PHP_OS, 0, 3) == 'WIN') { + die("skip Output tested contains chars that are not shown the same on windows concole (ESC and co)"); +} +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing different string arrays for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_STRING - compare items as strings +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +$various_arrays = array ( + // group of escape sequences + array(null, NULL, "\a", "\cx", "\e", "\f", "\n", "\r", "\t", "\xhh", "\ddd", "\v"), + + // array contains combination of capital/small letters + array("lemoN", "Orange", "banana", "apple", "Test", "TTTT", "ttt", "ww", "x", "X", "oraNGe", "BANANA") +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing sort() by supplying various string arrays --\n"; + +// loop through to test sort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Default sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(sort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various string arrays -- + +-- Iteration 1 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + NULL + [1]=> + NULL + [2]=> + string(1) " " + [3]=> + string(1) " +" + [4]=> + string(1) "" + [5]=> + string(1) "" + [6]=> + string(1) "
" + [7]=> + string(1) "" + [8]=> + string(2) "\a" + [9]=> + string(3) "\cx" + [10]=> + string(4) "\ddd" + [11]=> + string(4) "\xhh" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + NULL + [1]=> + NULL + [2]=> + string(1) " " + [3]=> + string(1) " +" + [4]=> + string(1) "" + [5]=> + string(1) "" + [6]=> + string(1) "
" + [7]=> + string(1) "" + [8]=> + string(2) "\a" + [9]=> + string(3) "\cx" + [10]=> + string(4) "\ddd" + [11]=> + string(4) "\xhh" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + NULL + [1]=> + NULL + [2]=> + string(1) " " + [3]=> + string(1) " +" + [4]=> + string(1) "" + [5]=> + string(1) "" + [6]=> + string(1) "
" + [7]=> + string(1) "" + [8]=> + string(2) "\a" + [9]=> + string(3) "\cx" + [10]=> + string(4) "\ddd" + [11]=> + string(4) "\xhh" +} + +-- Iteration 2 -- +- With Default sort flag - +bool(true) +array(12) { + [0]=> + string(6) "BANANA" + [1]=> + string(6) "Orange" + [2]=> + string(4) "TTTT" + [3]=> + string(4) "Test" + [4]=> + string(1) "X" + [5]=> + string(5) "apple" + [6]=> + string(6) "banana" + [7]=> + string(5) "lemoN" + [8]=> + string(6) "oraNGe" + [9]=> + string(3) "ttt" + [10]=> + string(2) "ww" + [11]=> + string(1) "x" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(12) { + [0]=> + string(6) "BANANA" + [1]=> + string(6) "Orange" + [2]=> + string(4) "TTTT" + [3]=> + string(4) "Test" + [4]=> + string(1) "X" + [5]=> + string(5) "apple" + [6]=> + string(6) "banana" + [7]=> + string(5) "lemoN" + [8]=> + string(6) "oraNGe" + [9]=> + string(3) "ttt" + [10]=> + string(2) "ww" + [11]=> + string(1) "x" +} +- Sort flag = SORT_STRING - +bool(true) +array(12) { + [0]=> + string(6) "BANANA" + [1]=> + string(6) "Orange" + [2]=> + string(4) "TTTT" + [3]=> + string(4) "Test" + [4]=> + string(1) "X" + [5]=> + string(5) "apple" + [6]=> + string(6) "banana" + [7]=> + string(5) "lemoN" + [8]=> + string(6) "oraNGe" + [9]=> + string(3) "ttt" + [10]=> + string(2) "ww" + [11]=> + string(1) "x" +} +Done diff --git a/ext/standard/tests/array/sort_variation6.phpt b/ext/standard/tests/array/sort_variation6.phpt new file mode 100644 index 0000000..7a93f0e --- /dev/null +++ b/ext/standard/tests/array/sort_variation6.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test sort() function : usage variations - sort hexadecimal values +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing different hexa-decimal array for $array argument with following flag values + * flag value as defualt + * SORT_REGULAR - compare items normally + * SORT_NUMERIC - compare items numerically +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +// an array contains unsorted hexadecimal values +$unsorted_hex_array = array(0x1AB, 0xFFF, 0xF, 0xFF, 0x2AA, 0xBB, 0x1ab, 0xff, -0xFF, 0, -0x2aa); + +echo "\n-- Testing sort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(sort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(sort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(sort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(11) { + [0]=> + int(-682) + [1]=> + int(-255) + [2]=> + int(0) + [3]=> + int(15) + [4]=> + int(187) + [5]=> + int(255) + [6]=> + int(255) + [7]=> + int(427) + [8]=> + int(427) + [9]=> + int(682) + [10]=> + int(4095) +} + +-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(11) { + [0]=> + int(-682) + [1]=> + int(-255) + [2]=> + int(0) + [3]=> + int(15) + [4]=> + int(187) + [5]=> + int(255) + [6]=> + int(255) + [7]=> + int(427) + [8]=> + int(427) + [9]=> + int(682) + [10]=> + int(4095) +} + +-- Testing sort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(11) { + [0]=> + int(-682) + [1]=> + int(-255) + [2]=> + int(0) + [3]=> + int(15) + [4]=> + int(187) + [5]=> + int(255) + [6]=> + int(255) + [7]=> + int(427) + [8]=> + int(427) + [9]=> + int(682) + [10]=> + int(4095) +} +Done diff --git a/ext/standard/tests/array/sort_variation7.phpt b/ext/standard/tests/array/sort_variation7.phpt new file mode 100644 index 0000000..19d888a --- /dev/null +++ b/ext/standard/tests/array/sort_variation7.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test sort() function : usage variations - sort boolean values +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing bool value array for $array argument with following flag values. + * flag value as defualt + * SORT_REGULAR - compare items normally +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +// bool value array +$bool_values = array (true, false, TRUE, FALSE); + +echo "\n-- Testing sort() by supplying bool value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(sort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(sort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(sort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing sort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(sort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying bool value array, 'flag' value is defualt -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing sort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing sort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} + +-- Testing sort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(true) +} +Done diff --git a/ext/standard/tests/array/sort_variation8.phpt b/ext/standard/tests/array/sort_variation8.phpt new file mode 100644 index 0000000..9a33031 --- /dev/null +++ b/ext/standard/tests/array/sort_variation8.phpt @@ -0,0 +1,178 @@ +--TEST-- +Test sort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as defualt/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * testing sort() by providing arrays contains sub arrays for $array argument with flowing flag values + * flag value as defualt + * SORT_REGULAR - compare items normally +*/ + +echo "*** Testing sort() : usage variations ***\n"; + +// array of arrays +$various_arrays = array ( + // null array + array(), + + // array contains null sub array + array( array() ), + + // array of arrays along with some values + array(44, 11, array(64, 61) ), + + // array containing sub arrays + array(array(33, -5, 6), array(11), array(22, -55), array() ) +); + + +$count = 1; +echo "\n-- Testing sort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test sort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing sort() function by supplying different arrays, flag value is defualt + echo "- With Defualt sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); + var_dump($temp_array); + + // testing sort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(sort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With Defualt sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With Defualt sort flag - +bool(true) +array(1) { + [0]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [0]=> + array(0) { + } +} + +-- Iteration 3 -- +- With Defualt sort flag - +bool(true) +array(3) { + [0]=> + int(11) + [1]=> + int(44) + [2]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + int(11) + [1]=> + int(44) + [2]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } +} + +-- Iteration 4 -- +- With Defualt sort flag - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(11) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } +} +Done diff --git a/ext/standard/tests/array/sort_variation9.phpt b/ext/standard/tests/array/sort_variation9.phpt new file mode 100644 index 0000000..faab166 --- /dev/null +++ b/ext/standard/tests/array/sort_variation9.phpt @@ -0,0 +1,259 @@ +--TEST-- +Test sort() function : usage variations - sort diff. associative arrays, 'sort_flags' as defualt/SORT_REGULAR +--FILE-- +<?php +/* Prototype : bool sort ( array &$array [, int $sort_flags] ) + * Description: This function sorts an array. + Elements will be arranged from lowest to highest when this function has completed. + * Source code: ext/standard/array.c +*/ + +/* + * Testing sort() by providing arrays with key values for $array argument + * with following flag values. + * 1.flag value as defualt + * 2.SORT_REGULAR - compare items normally + * To test the new keys for the elements in the sorted array. + */ + +echo "*** Testing sort() : usage variations ***\n"; + +// list of arrays with key and values +$various_arrays = array( + array(5 => 55, 6 => 66, 2 => 22, 3 => 33, 1 => 11), + array ("fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), + "numbers" => array(1, 2, 3, 4, 5, 6), + "holes" => array("first", 5 => "second", "third") + ), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a' => 1,'b' => array('e' => 2,'f' => 3),'c' => array('g' => 4),'d' => 5), +); + +$count = 1; +echo "\n-- Testing sort() by supplying various arrays with key values --\n"; + +// loop through to test sort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With Defualt sort flag -\n"; + $temp_array = $array; + var_dump(sort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(sort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sort() : usage variations *** + +-- Testing sort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With Defualt sort flag - +bool(true) +array(5) { + [0]=> + int(11) + [1]=> + int(22) + [2]=> + int(33) + [3]=> + int(55) + [4]=> + int(66) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [0]=> + int(11) + [1]=> + int(22) + [2]=> + int(33) + [3]=> + int(55) + [4]=> + int(66) +} + +-- Iteration 2 -- +- With Defualt sort flag - +bool(true) +array(3) { + [0]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [1]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } + [2]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [0]=> + array(3) { + [0]=> + string(5) "first" + [5]=> + string(6) "second" + [6]=> + string(5) "third" + } + [1]=> + array(3) { + ["a"]=> + string(6) "orange" + ["b"]=> + string(6) "banana" + ["c"]=> + string(5) "apple" + } + [2]=> + array(6) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) + [5]=> + int(6) + } +} + +-- Iteration 3 -- +- With Defualt sort flag - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(13) + [5]=> + int(19) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [2]=> + int(1) + [3]=> + int(1) + [4]=> + int(13) + [5]=> + int(19) +} + +-- Iteration 4 -- +- With Defualt sort flag - +bool(true) +array(2) { + [0]=> + string(3) "baz" + [1]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(2) { + [0]=> + string(3) "baz" + [1]=> + int(1) +} + +-- Iteration 5 -- +- With Defualt sort flag - +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + array(1) { + ["g"]=> + int(4) + } + [3]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + array(1) { + ["g"]=> + int(4) + } + [3]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/uasort_basic1.phpt b/ext/standard/tests/array/uasort_basic1.phpt new file mode 100644 index 0000000..70dd04c --- /dev/null +++ b/ext/standard/tests/array/uasort_basic1.phpt @@ -0,0 +1,116 @@ +--TEST-- +Test uasort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +echo "*** Testing uasort() : basic functionality ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Numeric array with default keys --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("This", "is", 'a', "test"); +echo "-- String array with default keys --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +// Associative array with numeric keys +$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9); +echo "-- Associative array with numeric keys --\n"; +var_dump( uasort($numeric_key_arg, 'cmp') ); +var_dump($numeric_key_arg); + +// Associative array with string keys +$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10); +echo "-- Associative array with string keys --\n"; +var_dump( uasort($string_key_arg, 'cmp') ); +var_dump($string_key_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : basic functionality *** +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + string(4) "This" + [2]=> + string(1) "a" + [1]=> + string(2) "is" + [3]=> + string(4) "test" +} +-- Associative array with numeric keys -- +bool(true) +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [5]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} +-- Associative array with string keys -- +bool(true) +array(4) { + ["three"]=> + int(1) + ["two"]=> + int(2) + ["one"]=> + int(4) + ["four"]=> + int(10) +} +Done diff --git a/ext/standard/tests/array/uasort_basic2.phpt b/ext/standard/tests/array/uasort_basic2.phpt new file mode 100644 index 0000000..e1b4ac9 --- /dev/null +++ b/ext/standard/tests/array/uasort_basic2.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test uasort() function : basic functionality - duplicate values +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +echo "*** Testing uasort() : basic functionality with duplicate values ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// increasing values +$int_values1 = array(1, 1, 2, 2, 3, 3); +echo "-- Numeric array with increasing values --\n"; +var_dump( uasort($int_values1, 'cmp') ); +var_dump($int_values1); + +// decreasing values +$int_values2 = array(3, 3, 2, 2, 1, 1); +echo "-- Numeric array with decreasing values --\n"; +var_dump( uasort($int_values2, 'cmp') ); +var_dump($int_values2); + +// increasing and decreasing values +$int_values3 = array(1, 2, 3, 3, 2, 1); +echo "-- Numeric array with increasing and decreasing values --\n"; +var_dump( uasort($int_values3, 'cmp') ); +var_dump($int_values3); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : basic functionality with duplicate values *** +-- Numeric array with increasing values -- +bool(true) +array(6) { + [0]=> + int(1) + [1]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [5]=> + int(3) + [4]=> + int(3) +} +-- Numeric array with decreasing values -- +bool(true) +array(6) { + [4]=> + int(1) + [5]=> + int(1) + [3]=> + int(2) + [2]=> + int(2) + [1]=> + int(3) + [0]=> + int(3) +} +-- Numeric array with increasing and decreasing values -- +bool(true) +array(6) { + [5]=> + int(1) + [0]=> + int(1) + [1]=> + int(2) + [4]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/uasort_error.phpt b/ext/standard/tests/array/uasort_error.phpt new file mode 100644 index 0000000..820ab58 --- /dev/null +++ b/ext/standard/tests/array/uasort_error.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test uasort() function : error conditions +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +echo "*** Testing uasort() : error conditions ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Initialize 'array_arg' +$array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25); + +// With zero arguments +echo "-- Testing uasort() function with Zero argument --\n"; +var_dump( uasort() ); + +// With one more than the expected number of arguments +echo "-- Testing uasort() function with more than expected no. of arguments --\n"; +$extra_arg = 10; +var_dump( uasort($array_arg, 'cmp', $extra_arg) ); + +// With one less than the expected number of arguments +echo "-- Testing uasort() function with less than expected no. of arguments --\n"; +var_dump( uasort($array_arg) ); + +// With non existent comparison function +echo "-- Testing uasort() function with non-existent compare function --\n"; +var_dump( uasort($array_arg, 'non_existent') ); + +// With non existent comparison function and extra arguemnt +echo "-- Testing uasort() function with non-existent compare function and extra argument --\n"; +var_dump( uasort($array_arg, 'non_existent', $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : error conditions *** +-- Testing uasort() function with Zero argument -- + +Warning: uasort() expects exactly 2 parameters, 0 given in %s on line %d +NULL +-- Testing uasort() function with more than expected no. of arguments -- + +Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +-- Testing uasort() function with less than expected no. of arguments -- + +Warning: uasort() expects exactly 2 parameters, 1 given in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function -- + +Warning: uasort() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function and extra argument -- + +Warning: uasort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_object1.phpt b/ext/standard/tests/array/uasort_object1.phpt new file mode 100644 index 0000000..5d5b0b5 --- /dev/null +++ b/ext/standard/tests/array/uasort_object1.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test uasort() function : object functionality +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* + * Testing uasort() function with the array of objects + * array of objects which has only one member variable & more than one member variables + */ + +echo "*** Testing uasort() : object functionality ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value3 + * Description : compares value1 and value2 + */ +function simple_cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// comparison function for SimpleClass2 objects which has more than one members +function multiple_cmp($value1, $value2) +{ + if($value1->getValue() == $value2->getValue()) + return 0; + else if($value1->getValue() > $value2->getValue()) + return 1; + else + return -1; +} + +// Simple class with single member variable +class SimpleClass1 +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } +} + +// Simple class with more than one member variables +class SimpleClass2 +{ + private $int_value; + protected $float_value; + public $string_value; + public function __construct($int, $float, $str) { + $this->int_value = $int; + $this->float_value = $float; + $this->string_value = $str; + } + public function getValue() { + return $this->int_value; + } +} + +// array of SimpleClass objects with only one member +$array_arg = array( + 0 => new SimpleClass1(10), + 1 => new SimpleClass1(1), + 2 => new SimpleClass1(100), + 3 => new SimpleClass1(50) +); +var_dump( uasort($array_arg, 'simple_cmp') ); +var_dump($array_arg); + +// array of SimpleClass objects having more than one members +$array_arg = array( + 0 => new SimpleClass2(2, 3.4, "mango"), + 1 => new SimpleClass2(10, 1.2, "apple"), + 2 => new SimpleClass2(5, 2.5, "orange"), +); +var_dump( uasort($array_arg, 'multiple_cmp') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +bool(true) +array(4) { + [1]=> + object(SimpleClass1)#2 (1) { + ["int_value":"SimpleClass1":private]=> + int(1) + } + [0]=> + object(SimpleClass1)#1 (1) { + ["int_value":"SimpleClass1":private]=> + int(10) + } + [3]=> + object(SimpleClass1)#4 (1) { + ["int_value":"SimpleClass1":private]=> + int(50) + } + [2]=> + object(SimpleClass1)#3 (1) { + ["int_value":"SimpleClass1":private]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#5 (3) { + ["int_value":"SimpleClass2":private]=> + int(2) + ["float_value":protected]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [2]=> + object(SimpleClass2)#7 (3) { + ["int_value":"SimpleClass2":private]=> + int(5) + ["float_value":protected]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [1]=> + object(SimpleClass2)#6 (3) { + ["int_value":"SimpleClass2":private]=> + int(10) + ["float_value":protected]=> + float(1.2) + ["string_value"]=> + string(5) "apple" + } +} +Done diff --git a/ext/standard/tests/array/uasort_object2.phpt b/ext/standard/tests/array/uasort_object2.phpt new file mode 100644 index 0000000..cd32d8d --- /dev/null +++ b/ext/standard/tests/array/uasort_object2.phpt @@ -0,0 +1,187 @@ +--TEST-- +Test uasort() function : object functionality - sort diff. objects +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +* + +/* + * This testcase tests uasort() functionality with differnt objects + * Objects of different classes: + * simple class, + * child class, + * empty class & + * static class + */ + +echo "*** Testing uasort() : object functionality ***\n"; + +// comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + + +// Simple class with single member variable +class SimpleClass +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } + +} + +// Class without any member +class EmptyClass +{ +} + +// Class with static member +class StaticClass +{ + public static $static_value; + public function __construct($value) { + StaticClass::$static_value = $value; + } +} + +// Abstract class +abstract class AbstractClass +{ + public $pub_value; + public abstract function abstractMethod(); +} + +// Child class extending abstract class +class ChildClass extends AbstractClass +{ + public $child_value = 100; + public function abstractMethod() { + $pub_value = 5; + } + public function __construct($value) { + $this->child_value = $value; + } +} + +// Testing uasort with StaticClass objects as elements of 'array_arg' +echo "-- Testing uasort() with StaticClass objects --\n"; +$array_arg = array( + 0 => new StaticClass(20), + 1 => new StaticClass(50), + 2 => new StaticClass(15), + 3 => new StaticClass(70), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with EmptyClass objects as elements of 'array_arg' +echo "-- Testing uasort() with EmptyClass objects --\n"; +$array_arg = array( + 0 => new EmptyClass(), + 1 => new EmptyClass(), + 2 => new EmptyClass(), + 3 => new EmptyClass(), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with ChildClass objects as elements of 'array_arg' +echo "-- Testing uasort() with ChildClass objects --\n"; +$array_arg = array( + 0 => new ChildClass(20), + 1 => new ChildClass(500), + 2 => new ChildClass(15), + 3 => new ChildClass(700), +); +var_dump( uasort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : object functionality *** +-- Testing uasort() with StaticClass objects -- +bool(true) +array(4) { + [3]=> + object(StaticClass)#%d (0) { + } + [2]=> + object(StaticClass)#%d (0) { + } + [1]=> + object(StaticClass)#%d (0) { + } + [0]=> + object(StaticClass)#%d (0) { + } +} +-- Testing uasort() with EmptyClass objects -- +bool(true) +array(4) { + [3]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(EmptyClass)#%d (0) { + } + [1]=> + object(EmptyClass)#%d (0) { + } + [0]=> + object(EmptyClass)#%d (0) { + } +} +-- Testing uasort() with ChildClass objects -- +bool(true) +array(4) { + [2]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(15) + ["pub_value"]=> + NULL + } + [0]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(20) + ["pub_value"]=> + NULL + } + [1]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(500) + ["pub_value"]=> + NULL + } + [3]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(700) + ["pub_value"]=> + NULL + } +} +Done diff --git a/ext/standard/tests/array/uasort_variation1.phpt b/ext/standard/tests/array/uasort_variation1.phpt new file mode 100644 index 0000000..96dcaee --- /dev/null +++ b/ext/standard/tests/array/uasort_variation1.phpt @@ -0,0 +1,188 @@ +--TEST-- +Test uasort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() function by passing different scalar/nonscalar values as 'array_arg' argument +*/ + +echo "*** Testing uasort() : unexpected values for 'array_arg' ***\n"; + +// Comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get resource variable +$fp = fopen(__FILE__,'r'); + +//array of values to iterate over +$input_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // resource data +/*20*/ $fp, + + // undefined data + @$undefined_var, + + // unset data +/*22*/ @$unset_var, +); + +// loop through each value of input_values +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( uasort($input_values[$count], 'cmp_function') ); +}; + +//closing resource +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : unexpected values for 'array_arg' *** +-- Iteration 1 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: uasort() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: uasort() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: uasort() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: uasort() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: uasort() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: uasort() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_variation10.phpt b/ext/standard/tests/array/uasort_variation10.phpt new file mode 100644 index 0000000..809cb78 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation10.phpt @@ -0,0 +1,74 @@ +--TEST-- +Test uasort() function : usage variations - sort array with reference variables +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() with 'array_arg' containing different reference variables +*/ + +// comparision function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : 'array_arg' with elements as reference ***\n"; + +// different variables which are used as elements of 'array_arg' +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// array_args an array containing elements with reference variables +$array_arg = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +echo "-- Sorting 'array_arg' containing different references --\n"; +var_dump( uasort($array_arg, 'cmp_function') ); // expecting: bool(true) +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : 'array_arg' with elements as reference *** +-- Sorting 'array_arg' containing different references -- +bool(true) +array(5) { + [1]=> + &int(-5) + [4]=> + &int(0) + [0]=> + int(10) + [2]=> + &int(100) + [3]=> + int(200) +} +Done diff --git a/ext/standard/tests/array/uasort_variation11.phpt b/ext/standard/tests/array/uasort_variation11.phpt new file mode 100644 index 0000000..6d523ea --- /dev/null +++ b/ext/standard/tests/array/uasort_variation11.phpt @@ -0,0 +1,82 @@ +--TEST-- +Test uasort() function : usage variations - different associative arrays +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* Testing uasort() with different associative arrays having keys as + * string, integer, default & duplicate keys + */ + +echo "*** Testing uasort() : sorting different associative arrays ***\n"; + +// comparison function +/* Prototype : int cmp(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Array with duplicate string and integer keys +$array_arg = array(0 => 2, "a" => 8, "d" => 9, 3 => 3, 5 => 2, "o" => 6, "z" => -99, 0 => 1, "z" => 3); +echo "-- Array with duplicate keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +// Array with default and assigned keys +$array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); +echo "-- Array with default/assigned keys --\n"; +var_dump( uasort($array_arg, 'cmp') ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : sorting different associative arrays *** +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [5]=> + int(2) + ["z"]=> + int(3) + [3]=> + int(3) + ["o"]=> + int(6) + ["a"]=> + int(8) + ["d"]=> + int(9) +} +-- Array with default/assigned keys -- +bool(true) +array(4) { + [2]=> + string(5) "Apple" + [0]=> + string(6) "Banana" + [1]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} +Done diff --git a/ext/standard/tests/array/uasort_variation2.phpt b/ext/standard/tests/array/uasort_variation2.phpt new file mode 100644 index 0000000..6283245 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation2.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test uasort() function : usage variations - unexpected values for 'cmp_function' argument +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() function with different scalar and nonscalar values in place of 'cmp_function' +*/ + +echo "*** Testing uasort() : Unexpected values in place of comparison function ***\n"; + +// Class definition for object variable +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +$array_arg = array(0 => 1, 1 => -1, 2 => 3, 3 => 10, 4 => 4, 5 => 2, 6 => 8, 7 => 5); + +// Get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Get resource variable +$fp = fopen(__FILE__,'r'); + +// different values for 'cmp_function' +$cmp_values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data + "string", + 'string', + + // object data +/*25*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*28*/ @$unset_var, +); + +// loop through each element of the cmp_values for 'cmp_function' +for($count = 0; $count < count($cmp_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( uasort($array_arg, $cmp_values[$count]) ); +}; + +//closing resource +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : Unexpected values in place of comparison function *** +-- Iteration 1 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 11 -- + +Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 12 -- + +Warning: uasort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL +-- Iteration 13 -- + +Warning: uasort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL +-- Iteration 14 -- + +Warning: uasort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL +-- Iteration 15 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: uasort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 22 -- + +Warning: uasort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL +-- Iteration 23 -- + +Warning: uasort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL +-- Iteration 24 -- + +Warning: uasort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL +-- Iteration 25 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 26 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 27 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +-- Iteration 28 -- + +Warning: uasort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_variation3.phpt b/ext/standard/tests/array/uasort_variation3.phpt Binary files differnew file mode 100644 index 0000000..9147d59 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation3.phpt diff --git a/ext/standard/tests/array/uasort_variation4.phpt b/ext/standard/tests/array/uasort_variation4.phpt new file mode 100644 index 0000000..c2844bf --- /dev/null +++ b/ext/standard/tests/array/uasort_variation4.phpt @@ -0,0 +1,150 @@ +--TEST-- +Test uasort() function : usage variations - sort different numeric values +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* sorting different types of numeric arrays containing data of following type: +* integer, octal, hexadecimal & float +*/ + +// comparision function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : different numeric arrays as 'array_arg' ***\n"; + +// Int array +$int_values = array(0 => 3, 1 => 2, 3 => 100, 4 => 150, 5 => 25, 6 => 350, 7 => 0, 8 => -3, 9 => -1200); +echo "-- Sorting Integer array --\n"; +var_dump( uasort($int_values, 'cmp_function') ); // expecting: bool(true) +var_dump($int_values); + +// Octal array +$octal_values = array(0 => 056, 1 => 023, 2 => 090, 3 => 015, 4 => -045, 5 => 01, 6 => -078); +echo "-- Sorting Octal array --\n"; +var_dump( uasort($octal_values, 'cmp_function') ); // expecting: bool(true) +var_dump($octal_values); + +// Hexadecimal array +$hex_values = array(0 => 0xAE, 1 => 0x2B, 2 => 0X10, 3 => -0xCF, 4 => 0X12, 5 => -0XF2); +echo "-- Sorting Hex array --\n"; +var_dump( uasort($hex_values, 'cmp_function') ); // expecting: bool(true) +var_dump($hex_values); + +// Float array +$float_values = array( 0 => 10.2, 1 => 2.4, 2 => -3.4, 3 => 0, 4 => 0.5, 5 => 7.3e3, 6 => -9.34E-2); +echo "-- Sorting Float array --\n"; +var_dump( uasort($float_values, 'cmp_function') ); // expecting: bool(true) +var_dump($float_values); + +// empty array +$empty_array = array(); +echo "-- Sorting empty array --\n"; +var_dump( uasort($empty_array, 'cmp_function') ); // expecting: bool(true) +var_dump($empty_array); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : different numeric arrays as 'array_arg' *** +-- Sorting Integer array -- +bool(true) +array(9) { + [9]=> + int(-1200) + [8]=> + int(-3) + [7]=> + int(0) + [1]=> + int(2) + [0]=> + int(3) + [5]=> + int(25) + [3]=> + int(100) + [4]=> + int(150) + [6]=> + int(350) +} +-- Sorting Octal array -- +bool(true) +array(7) { + [4]=> + int(-37) + [6]=> + int(-7) + [2]=> + int(0) + [5]=> + int(1) + [3]=> + int(13) + [1]=> + int(19) + [0]=> + int(46) +} +-- Sorting Hex array -- +bool(true) +array(6) { + [5]=> + int(-242) + [3]=> + int(-207) + [2]=> + int(16) + [4]=> + int(18) + [1]=> + int(43) + [0]=> + int(174) +} +-- Sorting Float array -- +bool(true) +array(7) { + [2]=> + float(-3.4) + [6]=> + float(-0.0934) + [3]=> + int(0) + [4]=> + float(0.5) + [1]=> + float(2.4) + [0]=> + float(10.2) + [5]=> + float(7300) +} +-- Sorting empty array -- +bool(true) +array(0) { +} +Done diff --git a/ext/standard/tests/array/uasort_variation5.phpt b/ext/standard/tests/array/uasort_variation5.phpt new file mode 100644 index 0000000..e6996a5 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation5.phpt @@ -0,0 +1,145 @@ +--TEST-- +Test uasort() function : usage variations - sort diff. strings +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* sorting different strings: +* single quoted, double quoted and heredoc strings +*/ + +// comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Different heredoc strings to be sorted +$empty_heredoc =<<<EOT +EOT; + +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + + +echo "*** Testing uasort() : different string arrays as 'array_arg' ***\n"; + +// Single quoted strings +$single_quoted_values = array( + 0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', + 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', 9 => '\'', 10 => '@#$%' +); +echo "-- Sorting Single Quoted String values --\n"; +var_dump( uasort($single_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($single_quoted_values); + +// Double quoted strings +$double_quoted_values = array( + 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", + 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", 9 => "\"", 10 => "@#$%" +); +echo "-- Sorting Double Quoted String values --\n"; +var_dump( uasort($double_quoted_values, 'cmp_function') ); // expecting: bool(true) +var_dump($double_quoted_values); + +// Heredoc strings +$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, 2 => $simple_heredoc2, 3 => $multiline_heredoc); +echo "-- Sorting Heredoc String values --\n"; +var_dump( uasort($heredoc_values, 'cmp_function') ); // expecting: bool(true) +var_dump($heredoc_values); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : different string arrays as 'array_arg' *** +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [0]=> + string(1) " " + [9]=> + string(1) "'" + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [6]=> + string(2) "\t" + [1]=> + string(4) "test" +} +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [5]=> + string(0) "" + [6]=> + string(1) " " + [0]=> + string(1) " " + [9]=> + string(1) """ + [7]=> + string(1) "0" + [8]=> + string(8) "123Hello" + [10]=> + string(4) "@#$%" + [4]=> + string(5) "HELLO" + [3]=> + string(5) "Hello" + [1]=> + string(4) "test" +} +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + string(0) "" + [2]=> + string(7) "HEREDOC" + [1]=> + string(7) "Heredoc" + [3]=> + string(4%d) "heredoc string with!@# and 123 +Test this!!!" +} +Done diff --git a/ext/standard/tests/array/uasort_variation6.phpt b/ext/standard/tests/array/uasort_variation6.phpt new file mode 100644 index 0000000..48d9c03 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation6.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test uasort() function : usage variations - sort array having subarrays +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Testing uasort() with 'array_arg' having different subarrays as array elements +*/ + +// comparison function +/* Prototype : int cmp_function(mixed $value1, mixed $value2) + * Parameters : $value1 and $value2 - values to be compared + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +echo "*** Testing uasort() : sorting array having different subarrays ***\n"; + +$array_args = array( + 0 => array(2, 10, -1), + 1 => array(100), + 2 => array(), + 3 => array(0), + 4 => array(-1), + 5 => array(-9, 34, 54, 0, 20), + 6 => array(''), + 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe") +); +$temp_array = $array_args; +// sorting array_arg as whole array +var_dump( uasort($temp_array, 'cmp_function') ); // expecting: bool(true) +var_dump($temp_array); + +?> +--EXPECTF-- +*** Testing uasort() : sorting array having different subarrays *** +bool(true) +array(8) { + [2]=> + array(0) { + } + [4]=> + array(1) { + [0]=> + int(-1) + } + [6]=> + array(1) { + [0]=> + string(0) "" + } + [3]=> + array(1) { + [0]=> + int(0) + } + [1]=> + array(1) { + [0]=> + int(100) + } + [0]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [5]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + string(5) "apple" + [1]=> + string(5) "Apple" + [2]=> + string(5) "APPLE" + [3]=> + string(5) "aPPle" + [4]=> + string(5) "aPpLe" + } +} diff --git a/ext/standard/tests/array/uasort_variation7.phpt b/ext/standard/tests/array/uasort_variation7.phpt new file mode 100644 index 0000000..44a2bb3 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation7.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test uasort() function : usage variations - anonymous function as 'cmp_function' +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Passing different anonymous functions as 'cmp_function' +* arguments passed by value +* arguments passed by reference +*/ + +echo "*** Testing uasort() : anonymous function as 'cmp_function' ***\n"; + +$cmp_function = 'if($value1 == $value2) {return 0;} else if($value1 > $value2) {return 1;} else{return -1;}'; + +$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90); +echo "-- Anonymous 'cmp_function' with parameters passed by value --\n"; +var_dump( uasort($array_arg, create_function('$value1, $value2',$cmp_function) ) ); +var_dump($array_arg); + +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple"); +echo "-- Anonymous 'cmp_function' with parameters passed by reference --\n"; +var_dump( uasort($array_arg, create_function('&$value1, &$value2', $cmp_function) ) ); +var_dump($array_arg); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : anonymous function as 'cmp_function' *** +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [2]=> + int(-70) + [1]=> + int(3) + [3]=> + int(24) + [4]=> + int(90) + [0]=> + int(100) +} +-- Anonymous 'cmp_function' with parameters passed by reference -- +bool(true) +array(4) { + ["a"]=> + string(5) "Apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" +} +Done diff --git a/ext/standard/tests/array/uasort_variation8.phpt b/ext/standard/tests/array/uasort_variation8.phpt new file mode 100644 index 0000000..dd0a7a3 --- /dev/null +++ b/ext/standard/tests/array/uasort_variation8.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test uasort() function : usage variations - built-in function as 'cmp_function' +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* +* Passing different built-in library functions in place of 'cmp_function' +* valid comparison functions: strcmp() & strcasecmp() +* language constructs: echo & exit +*/ + +echo "*** Testing uasort() : built in function as 'cmp_function' ***\n"; +// Initializing variables +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "apple", "p" => "Pineapple", "o" => "orange"); +$builtin_fun_arg = $array_arg; +$languageConstruct_fun_arg = $array_arg; + +// Testing library functions as comparison function +echo "-- Testing uasort() with built-in 'cmp_function': strcasecmp() --\n"; +var_dump( uasort($builtin_fun_arg, 'strcasecmp') ); // expecting: bool(true) +var_dump($builtin_fun_arg); + +echo "-- Testing uasort() with built-in 'cmp_function': strcmp() --\n"; +var_dump( uasort($array_arg, 'strcmp') ); // expecting: bool(true) +var_dump($array_arg); + +// Testing with language construct as comparison function +echo "-- Testing uasort() with language construct as 'cmp_function' --\n"; +var_dump( uasort($languageConstruct_fun_arg, 'echo') ); // expecting: bool(false) + +echo "-- Testing uasort() with language construct as 'cmp_function' --\n"; +var_dump( uasort($languageConstruct_fun_arg, 'exit') ); // expecting: bool(false) + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : built in function as 'cmp_function' *** +-- Testing uasort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + ["a"]=> + string(5) "apple" + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["o"]=> + string(6) "orange" + ["p"]=> + string(9) "Pineapple" +} +-- Testing uasort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + ["b"]=> + string(6) "Banana" + ["m"]=> + string(5) "Mango" + ["p"]=> + string(9) "Pineapple" + ["a"]=> + string(5) "apple" + ["o"]=> + string(6) "orange" +} +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/uasort_variation9.phpt b/ext/standard/tests/array/uasort_variation9.phpt new file mode 100644 index 0000000..486042e --- /dev/null +++ b/ext/standard/tests/array/uasort_variation9.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test uasort() function : usage variations - 'cmp_function' with reference argument +--FILE-- +<?php +/* Prototype : bool uasort(array $array_arg, string $cmp_function) + * Description: Sort an array with a user-defined comparison function and maintain index association + * Source code: ext/standard/array.c +*/ + +/* Testing uasort() functionality with comparison function having arguments as reference + */ + +echo "*** Testing uasort() : 'cmp_function' with reference arguments ***\n"; + +// comparison function +/* Prototype : int cmp(mixed &$value1, mixed &$value2) + * Parameters : $value1 and $value2 - values recieved by reference + * Return value : 0 - if both values are same + * 1 - if value1 is greater than value2 + * -1 - if value1 is less than value2 + * Description : compares value1 and value2 + */ +function cmp(&$value1, &$value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); +echo "-- Passing integer values to 'cmp_function' --\n"; +var_dump( uasort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("Mango", "Apple", "Orange", "Banana"); +echo "-- Passing string values to 'cmp_function' --\n"; +var_dump( uasort($string_values, 'cmp') ); +var_dump($string_values); + +echo "Done" +?> +--EXPECTF-- +*** Testing uasort() : 'cmp_function' with reference arguments *** +-- Passing integer values to 'cmp_function' -- +bool(true) +array(7) { + [0]=> + int(1) + [4]=> + int(2) + [3]=> + int(3) + [5]=> + int(6) + [6]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +-- Passing string values to 'cmp_function' -- +bool(true) +array(4) { + [1]=> + string(5) "Apple" + [3]=> + string(6) "Banana" + [0]=> + string(5) "Mango" + [2]=> + string(6) "Orange" +} +Done diff --git a/ext/standard/tests/array/uksort_basic.phpt b/ext/standard/tests/array/uksort_basic.phpt new file mode 100644 index 0000000..f83c032 --- /dev/null +++ b/ext/standard/tests/array/uksort_basic.phpt @@ -0,0 +1,26 @@ +--TEST-- +Test uksort(): basic functionality +--FILE-- +<?php +/* +* proto bool uksort ( array &$array, callback $cmp_function ) +* Function is implemented in ext/standard/array.c +*/ +function cmp($a, $b) { + if ($a == $b) { + return 0; + } + return ($a < $b) ? -1 : 1; +} +$a = array(3, 2, 5, 6, 1); +uasort($a, "cmp"); +foreach($a as $key => $value) { + echo "$key: $value\n"; +} +?> +--EXPECT-- +4: 1 +1: 2 +0: 3 +2: 5 +3: 6
\ No newline at end of file diff --git a/ext/standard/tests/array/uksort_error.phpt b/ext/standard/tests/array/uksort_error.phpt new file mode 100644 index 0000000..241ed2f --- /dev/null +++ b/ext/standard/tests/array/uksort_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test uksort() function : error conditions +--FILE-- +<?php +/* Prototype : bool uksort(array array_arg, string cmp_function) + * Description: Sort an array by keys using a user-defined comparison function + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing uksort() : error conditions ***\n"; + +echo "\n-- Testing uksort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$cmp_function = 'string_val'; +$extra_arg = 10; +var_dump( uksort($array_arg, $cmp_function, $extra_arg) ); + +echo "\n-- Testing uksort() function with less than expected no. of arguments --\n"; +$array_arg = array(1, 2); +var_dump( uksort($array_arg) ); + +echo "\n-- Testing uksort() function with zero arguments --\n"; +var_dump( uksort() ); + +?> +===DONE=== +--EXPECTF-- +*** Testing uksort() : error conditions *** + +-- Testing uksort() function with more than expected no. of arguments -- + +Warning: uksort() expects exactly 2 parameters, 3 given in %suksort_error.php on line %d +NULL + +-- Testing uksort() function with less than expected no. of arguments -- + +Warning: uksort() expects exactly 2 parameters, 1 given in %suksort_error.php on line %d +NULL + +-- Testing uksort() function with zero arguments -- + +Warning: uksort() expects exactly 2 parameters, 0 given in %suksort_error.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/uksort_variation1.phpt b/ext/standard/tests/array/uksort_variation1.phpt new file mode 100644 index 0000000..3189f7f --- /dev/null +++ b/ext/standard/tests/array/uksort_variation1.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test uksort() function : usage variation +--FILE-- +<?php +/* Prototype : bool uksort(array array_arg, string cmp_function) + * Description: Sort an array by keys using a user-defined comparison function + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing uksort() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$cmp_function = 'string_val'; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for array_arg + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( uksort($value, $cmp_function) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing uksort() : usage variation *** + +--int 0-- + +Warning: uksort() expects parameter 1 to be array, integer given in %suksort_variation1.php on line %d +NULL + +--int 1-- + +Warning: uksort() expects parameter 1 to be array, integer given in %suksort_variation1.php on line %d +NULL + +--int 12345-- + +Warning: uksort() expects parameter 1 to be array, integer given in %suksort_variation1.php on line %d +NULL + +--int -12345-- + +Warning: uksort() expects parameter 1 to be array, integer given in %suksort_variation1.php on line %d +NULL + +--float 10.5-- + +Warning: uksort() expects parameter 1 to be array, double given in %suksort_variation1.php on line %d +NULL + +--float -10.5-- + +Warning: uksort() expects parameter 1 to be array, double given in %suksort_variation1.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: uksort() expects parameter 1 to be array, double given in %suksort_variation1.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: uksort() expects parameter 1 to be array, double given in %suksort_variation1.php on line %d +NULL + +--float .5-- + +Warning: uksort() expects parameter 1 to be array, double given in %suksort_variation1.php on line %d +NULL + +--uppercase NULL-- + +Warning: uksort() expects parameter 1 to be array, null given in %suksort_variation1.php on line %d +NULL + +--lowercase null-- + +Warning: uksort() expects parameter 1 to be array, null given in %suksort_variation1.php on line %d +NULL + +--lowercase true-- + +Warning: uksort() expects parameter 1 to be array, boolean given in %suksort_variation1.php on line %d +NULL + +--lowercase false-- + +Warning: uksort() expects parameter 1 to be array, boolean given in %suksort_variation1.php on line %d +NULL + +--uppercase TRUE-- + +Warning: uksort() expects parameter 1 to be array, boolean given in %suksort_variation1.php on line %d +NULL + +--uppercase FALSE-- + +Warning: uksort() expects parameter 1 to be array, boolean given in %suksort_variation1.php on line %d +NULL + +--empty string DQ-- + +Warning: uksort() expects parameter 1 to be array, string given in %suksort_variation1.php on line %d +NULL + +--empty string SQ-- + +Warning: uksort() expects parameter 1 to be array, string given in %suksort_variation1.php on line %d +NULL + +--string DQ-- + +Warning: uksort() expects parameter 1 to be array, string given in %suksort_variation1.php on line %d +NULL + +--string SQ-- + +Warning: uksort() expects parameter 1 to be array, string given in %suksort_variation1.php on line %d +NULL + +--mixed case string-- + +Warning: uksort() expects parameter 1 to be array, string given in %suksort_variation1.php on line %d +NULL + +--heredoc-- + +Warning: uksort() expects parameter 1 to be array, string given in %suksort_variation1.php on line %d +NULL + +--instance of classWithToString-- + +Warning: uksort() expects parameter 1 to be array, object given in %suksort_variation1.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: uksort() expects parameter 1 to be array, object given in %suksort_variation1.php on line %d +NULL + +--undefined var-- + +Warning: uksort() expects parameter 1 to be array, null given in %suksort_variation1.php on line %d +NULL + +--unset var-- + +Warning: uksort() expects parameter 1 to be array, null given in %suksort_variation1.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/uksort_variation2.phpt b/ext/standard/tests/array/uksort_variation2.phpt new file mode 100644 index 0000000..2f5b8b5 --- /dev/null +++ b/ext/standard/tests/array/uksort_variation2.phpt @@ -0,0 +1,224 @@ +--TEST-- +Test uksort() function : usage variation +--FILE-- +<?php +/* Prototype : bool uksort(array array_arg, string cmp_function) + * Description: Sort an array by keys using a user-defined comparison function + * Source code: ext/standard/array.c + * Alias to functions: + */ + +echo "*** Testing uksort() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array_arg = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // array data + 'empty array' => array(), + 'int indexed array' => $index_array, + 'associative array' => $assoc_array, + 'nested arrays' => array('foo', $index_array, $assoc_array), + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for cmp_function + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( uksort($array_arg, $value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing uksort() : usage variation *** + +--int 0-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--int 1-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--int 12345-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--int -12345-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--float 10.5-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--float -10.5-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--float .5-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--empty array-- + +Warning: uksort() expects parameter 2 to be a valid callback, array must have exactly two members in %suksort_variation2.php on line %d +NULL + +--int indexed array-- + +Warning: uksort() expects parameter 2 to be a valid callback, array must have exactly two members in %suksort_variation2.php on line %d +NULL + +--associative array-- + +Warning: uksort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %suksort_variation2.php on line %d +NULL + +--nested arrays-- + +Warning: uksort() expects parameter 2 to be a valid callback, array must have exactly two members in %suksort_variation2.php on line %d +NULL + +--uppercase NULL-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--lowercase null-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--lowercase true-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--lowercase false-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--uppercase TRUE-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--uppercase FALSE-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--empty string DQ-- + +Warning: uksort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %suksort_variation2.php on line %d +NULL + +--empty string SQ-- + +Warning: uksort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %suksort_variation2.php on line %d +NULL + +--instance of classWithToString-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--undefined var-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL + +--unset var-- + +Warning: uksort() expects parameter 2 to be a valid callback, no array or string given in %suksort_variation2.php on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/unexpected_array_mod_bug.phpt b/ext/standard/tests/array/unexpected_array_mod_bug.phpt new file mode 100644 index 0000000..58f2249 --- /dev/null +++ b/ext/standard/tests/array/unexpected_array_mod_bug.phpt @@ -0,0 +1,21 @@ +--TEST-- +Crash when function parameter modified via reference +--FILE-- +<?php +function usercompare($a,$b) { + unset($GLOBALS['my_var'][2]); + return 0; +} +$my_var = array(1 => "entry_1", +2 => "entry_2", +3 => "entry_3", +4 => "entry_4", +5 => "entry_5"); +usort($my_var, "usercompare"); + +echo "Done.\n"; +?> +--EXPECTF-- + +Warning: usort(): Array was modified by the user comparison function in %s on line %d +Done. diff --git a/ext/standard/tests/array/usort_basic.phpt b/ext/standard/tests/array/usort_basic.phpt new file mode 100644 index 0000000..eaf3018 --- /dev/null +++ b/ext/standard/tests/array/usort_basic.phpt @@ -0,0 +1,119 @@ +--TEST-- +Test usort() function : basic functionality +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of usort() with indexed and associative arrays + */ + +echo "*** Testing usort() : basic functionality ***\n"; + +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Int array with default keys +$int_values = array(1, 8, 9, 3, 2, 6, 7); + +echo "\n-- Numeric array with default keys --\n"; +var_dump( usort($int_values, 'cmp') ); +var_dump($int_values); + +// String array with default keys +$string_values = array("This", "is", 'a', "test"); + +echo "\n-- String array with default keys --\n"; +var_dump( usort($string_values, 'cmp') ); +var_dump($string_values); + +// Associative array with numeric keys +$numeric_key_arg = array(1=> 1, 2 => 2, 3 => 7, 5 => 4, 4 => 9); + +echo "\n-- Associative array with numeric keys --\n"; +var_dump( usort($numeric_key_arg, 'cmp') ); +var_dump($numeric_key_arg); + +// Associative array with string keys +$string_key_arg = array('one' => 4, 'two' => 2, 'three' => 1, 'four' => 10); + +echo "\n-- Associative array with string keys --\n"; +var_dump( usort($string_key_arg, 'cmp') ); +var_dump($string_key_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : basic functionality *** + +-- Numeric array with default keys -- +bool(true) +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(6) + [4]=> + int(7) + [5]=> + int(8) + [6]=> + int(9) +} + +-- String array with default keys -- +bool(true) +array(4) { + [0]=> + string(4) "This" + [1]=> + string(1) "a" + [2]=> + string(2) "is" + [3]=> + string(4) "test" +} + +-- Associative array with numeric keys -- +bool(true) +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(4) + [3]=> + int(7) + [4]=> + int(9) +} + +-- Associative array with string keys -- +bool(true) +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(4) + [3]=> + int(10) +} +===DONE=== diff --git a/ext/standard/tests/array/usort_error1.phpt b/ext/standard/tests/array/usort_error1.phpt new file mode 100644 index 0000000..70c555e --- /dev/null +++ b/ext/standard/tests/array/usort_error1.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test usort() function : error conditions - Pass incorrect number of arguments +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass incorrect number of arguments to usort() to test behaviour + */ + +echo "*** Testing usort() : error conditions ***\n"; + +//Test usort with one more than the expected number of arguments +echo "\n-- Testing usort() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$cmp_function = 'string_val'; +$extra_arg = 10; +var_dump( usort($array_arg, $cmp_function, $extra_arg) ); + +// Testing usort with one less than the expected number of arguments +echo "\n-- Testing usort() function with less than expected no. of arguments --\n"; +$array_arg = array(1, 2); +var_dump( usort($array_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : error conditions *** + +-- Testing usort() function with more than expected no. of arguments -- + +Warning: usort() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +-- Testing usort() function with less than expected no. of arguments -- + +Warning: usort() expects exactly 2 parameters, 1 given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_error2.phpt b/ext/standard/tests/array/usort_error2.phpt new file mode 100644 index 0000000..308199f --- /dev/null +++ b/ext/standard/tests/array/usort_error2.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test usort() function : error conditions - Pass unknown 'cmp_function' +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an unknown comparison function to usort() to test behaviour. + * Pass incorrect number of arguments and an unknown function to test which error + * is generated. + */ + +echo "*** Testing usort() : error conditions ***\n"; + +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Initialize 'array_arg' +$array_arg = array(0 => 1, 1 => 10, 2 => 'string', 3 => 3, 4 => 2, 5 => 100, 6 => 25); +$extra_arg = 10; + +// With non existent comparison function +echo "\n-- Testing usort() function with non-existent compare function --\n"; +var_dump( usort($array_arg, 'non_existent') ); + +// With non existent comparison function and extra arguemnt +echo "\n-- Testing usort() function with non-existent compare function and extra argument --\n"; +var_dump( usort($array_arg, 'non_existent', $extra_arg) ); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : error conditions *** + +-- Testing usort() function with non-existent compare function -- + +Warning: usort() expects parameter 2 to be a valid callback, function 'non_existent' not found or invalid function name in %s on line %d +NULL + +-- Testing usort() function with non-existent compare function and extra argument -- + +Warning: usort() expects exactly 2 parameters, 3 given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_object1.phpt b/ext/standard/tests/array/usort_object1.phpt new file mode 100644 index 0000000..0e87443 --- /dev/null +++ b/ext/standard/tests/array/usort_object1.phpt @@ -0,0 +1,141 @@ +--TEST-- +Test usort() function : object functionality - different number of properties +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of objects which have a different number of properties + * to test behaviour of usort() + */ + +echo "*** Testing usort() : object functionality ***\n"; + +function simple_cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// comparison function for SimpleClass2 objects which has more than one member +function multiple_cmp($value1, $value2) +{ + if($value1->getValue() == $value2->getValue()) + return 0; + else if($value1->getValue() > $value2->getValue()) + return 1; + else + return -1; +} + +// Simple class with single property +class SimpleClass1 +{ + private $int_value; + + public function __construct($value) { + $this->int_value = $value; + } +} + +// Simple class with more than one property +class SimpleClass2 +{ + private $int_value; + protected $float_value; + public $string_value; + public function __construct($int, $float, $str) { + $this->int_value = $int; + $this->float_value = $float; + $this->string_value = $str; + } + public function getValue() { + return $this->int_value; + } +} + +// array of SimpleClass objects with only one property +$array_arg = array( +0 => new SimpleClass1(10), +1 => new SimpleClass1(1), +2 => new SimpleClass1(100), +3 => new SimpleClass1(50) +); +var_dump( usort($array_arg, 'simple_cmp') ); +var_dump($array_arg); + +// array of SimpleClass objects having more than one properties +$array_arg = array( +0 => new SimpleClass2(2, 3.4, "mango"), +1 => new SimpleClass2(10, 1.2, "apple"), +2 => new SimpleClass2(5, 2.5, "orange"), +); +var_dump( usort($array_arg, 'multiple_cmp') ); +var_dump($array_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : object functionality *** +bool(true) +array(4) { + [0]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(1) + } + [1]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(10) + } + [2]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(50) + } + [3]=> + object(SimpleClass1)#%d (1) { + ["int_value":"SimpleClass1":private]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#%d (3) { + ["int_value":"SimpleClass2":private]=> + int(2) + ["float_value":protected]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [1]=> + object(SimpleClass2)#%d (3) { + ["int_value":"SimpleClass2":private]=> + int(5) + ["float_value":protected]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [2]=> + object(SimpleClass2)#%d (3) { + ["int_value":"SimpleClass2":private]=> + int(10) + ["float_value":protected]=> + float(1.2) + ["string_value"]=> + string(5) "apple" + } +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_object2.phpt b/ext/standard/tests/array/usort_object2.phpt new file mode 100644 index 0000000..00d302f --- /dev/null +++ b/ext/standard/tests/array/usort_object2.phpt @@ -0,0 +1,165 @@ +--TEST-- +Test usort() function : object functionality - Different types of classes +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of objects which are either: + * 1. Empty + * 2. Static + * 2. Inherited + * to test behaviour of usort() + */ + +echo "*** Testing usort() : object functionality ***\n"; + +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Class without any member +class EmptyClass +{ +} + +// Class with static member +class StaticClass +{ + public static $static_value; + public function __construct($value) { + StaticClass::$static_value = $value; + } +} + +// Abstract class +abstract class AbstractClass +{ + public $pub_value; + public abstract function abstractMethod(); +} + +// Child class extending abstract class +class ChildClass extends AbstractClass +{ + public $child_value = 100; + public function abstractMethod() { + $pub_value = 5; + } + public function __construct($value) { + $this->child_value = $value; + } +} + +// Testing uasort with StaticClass objects as elements of 'array_arg' +echo "-- Testing usort() with StaticClass objects --\n"; +$array_arg = array( + 0 => new StaticClass(20), + 1 => new StaticClass(50), + 2 => new StaticClass(15), + 3 => new StaticClass(70), +); +var_dump( usort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with EmptyClass objects as elements of 'array_arg' +echo "-- Testing usort() with EmptyClass objects --\n"; +$array_arg = array( + 0 => new EmptyClass(), + 1 => new EmptyClass(), + 2 => new EmptyClass(), + 3 => new EmptyClass(), +); +var_dump( usort($array_arg, 'cmp_function') ); +var_dump($array_arg); + +// Testing uasort with ChildClass objects as elements of 'array_arg' +echo "-- Testing usort() with ChildClass objects --\n"; +$array_arg = array( + 0 => new ChildClass(20), + 1 => new ChildClass(500), + 2 => new ChildClass(15), + 3 => new ChildClass(700), +); +var_dump( usort($array_arg, 'cmp_function') ); +var_dump($array_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : object functionality *** +-- Testing usort() with StaticClass objects -- +bool(true) +array(4) { + [0]=> + object(StaticClass)#%d (0) { + } + [1]=> + object(StaticClass)#%d (0) { + } + [2]=> + object(StaticClass)#%d (0) { + } + [3]=> + object(StaticClass)#%d (0) { + } +} +-- Testing usort() with EmptyClass objects -- +bool(true) +array(4) { + [0]=> + object(EmptyClass)#%d (0) { + } + [1]=> + object(EmptyClass)#%d (0) { + } + [2]=> + object(EmptyClass)#%d (0) { + } + [3]=> + object(EmptyClass)#%d (0) { + } +} +-- Testing usort() with ChildClass objects -- +bool(true) +array(4) { + [0]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(15) + ["pub_value"]=> + NULL + } + [1]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(20) + ["pub_value"]=> + NULL + } + [2]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(500) + ["pub_value"]=> + NULL + } + [3]=> + object(ChildClass)#%d (2) { + ["child_value"]=> + int(700) + ["pub_value"]=> + NULL + } +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_variation1.phpt b/ext/standard/tests/array/usort_variation1.phpt new file mode 100644 index 0000000..73fdc08 --- /dev/null +++ b/ext/standard/tests/array/usort_variation1.phpt @@ -0,0 +1,236 @@ +--TEST-- +Test usort() function : usage variations - Pass different data types as $array_arg arg +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $array_arg argument to usort() to test behaviour + */ + +echo "*** Testing usort() : usage variations ***\n"; + +// Initialise function arguments not being substituted +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + array(), + + // string data +/*19*/ "string", + 'string', + $heredoc, + + // object data +/*22*/ new classA(), + + // undefined data +/*23*/ @$undefined_var, + + // unset data +/*24*/ @$unset_var, + + // resource variable +/*25*/ $fp +); + +// loop through each element of $inputs to check the behavior of usort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( usort($input, 'cmp_function') ); + $iterator++; +}; + +//closing resource +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variations *** + +-- Iteration 1 -- + +Warning: usort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: usort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: usort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: usort() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: usort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: usort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: usort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: usort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: usort() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: usort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: usort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: usort() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: usort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: usort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- +bool(true) + +-- Iteration 19 -- + +Warning: usort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: usort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: usort() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: usort() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: usort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: usort() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: usort() expects parameter 1 to be array, resource given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_variation10.phpt b/ext/standard/tests/array/usort_variation10.phpt new file mode 100644 index 0000000..b343419 --- /dev/null +++ b/ext/standard/tests/array/usort_variation10.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test usort() function : usage variations - duplicate keys and values +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an array with duplicate keys and values to usort() to test behaviour + */ + +echo "*** Testing usort() : usage variation ***\n"; + +function cmp($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else + return -1; +} + +// Array with duplicate string and integer keys and values +$array_arg = array(0 => 2, "a" => 8, "d" => 9, + 3 => 3, 5 => 2, "o" => 6, + "z" => -99, 0 => 1, "z" => 3); + +echo "\n-- Array with duplicate keys --\n"; +var_dump( usort($array_arg, 'cmp') ); +var_dump($array_arg); + +// Array with default and assigned keys +$array_arg = array(0 => "Banana", 1 => "Mango", "Orange", 2 => "Apple", "Pineapple"); + +echo "\n-- Array with default/assigned keys --\n"; +var_dump( usort($array_arg, 'cmp') ); +var_dump($array_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Array with duplicate keys -- +bool(true) +array(7) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(3) + [4]=> + int(6) + [5]=> + int(8) + [6]=> + int(9) +} + +-- Array with default/assigned keys -- +bool(true) +array(4) { + [0]=> + string(5) "Apple" + [1]=> + string(6) "Banana" + [2]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} +===DONE=== diff --git a/ext/standard/tests/array/usort_variation2.phpt b/ext/standard/tests/array/usort_variation2.phpt new file mode 100644 index 0000000..70d2164 --- /dev/null +++ b/ext/standard/tests/array/usort_variation2.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test usort() function : usage variations - Pass different data types as $cmp_function arg +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass different data types as $cmp_function argument to usort() to test behaviour + */ + +echo "*** Testing usort() : usage variation ***\n"; + +// Class definition for object variable +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +$array_arg = array(0 => 1, 1 => -1, 2 => 3, 3 => 10, 4 => 4, 5 => 2, 6 => 8, 7 => 5); + +// Get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Get resource variable +$fp = fopen(__FILE__,'r'); + +// different values for $cmp_function +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, + .5, + + // array data +/*10*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data + "string", + 'string', + + // object data +/*25*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*28*/ @$unset_var, +); + +// loop through each element of $inputs to check the behavior of usort() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( usort($array_arg, $input) ); + $iterator++; +}; + +//closing resource +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Iteration 1 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: usort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: usort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: usort() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: usort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: usort() expects parameter 2 to be a valid callback, first array member is not a valid class name or object in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: usort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: usort() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: usort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: usort() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 26 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 27 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Iteration 28 -- + +Warning: usort() expects parameter 2 to be a valid callback, no array or string given in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_variation3.phpt b/ext/standard/tests/array/usort_variation3.phpt new file mode 100644 index 0000000..3758fe9 --- /dev/null +++ b/ext/standard/tests/array/usort_variation3.phpt @@ -0,0 +1,115 @@ +--TEST-- +Test usort() function : usage variations - diff. array values +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an array with different data types as keys to usort() to test how it is re-ordered + */ + +echo "*** Testing usort() : usage variation ***\n"; + +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return -1; + } + else { + return 1; + } +} + +// different heredoc strings + +// single line heredoc string +$simple_heredoc = <<<EOT2 +simple +EOT2; + +// multiline heredoc string +$multiline_heredoc = <<<EOT3 +multiline heredoc with 123 +and speci@! ch@r..\ncheck\talso +EOT3; + +$array_arg = array( + // numeric keys + -2 => 9, + 8.9 => 8, + 012 => 7, + 0x34 => 6, + + // string keys + 'key' => 5, //single quoted key + "two" => 4, //double quoted key + " " => 0, // space as key + + // bool keys + TRUE => 100, + FALSE => 25, + + // null keys + NULL => 35, + + // binary key + "a".chr(0)."b" => 45, + b"binary" => 30, + + //heredoc keys + $simple_heredoc => 75, + $multiline_heredoc => 200, + + // default key + 1, +); + +var_dump( usort($array_arg, 'cmp_function') ); +echo "\n-- Sorted array after usort() function call --\n"; +var_dump($array_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** +bool(true) + +-- Sorted array after usort() function call -- +array(15) { + [0]=> + int(200) + [1]=> + int(100) + [2]=> + int(75) + [3]=> + int(45) + [4]=> + int(35) + [5]=> + int(30) + [6]=> + int(25) + [7]=> + int(9) + [8]=> + int(8) + [9]=> + int(7) + [10]=> + int(6) + [11]=> + int(5) + [12]=> + int(4) + [13]=> + int(1) + [14]=> + int(0) +} +===DONE=== diff --git a/ext/standard/tests/array/usort_variation4.phpt b/ext/standard/tests/array/usort_variation4.phpt new file mode 100644 index 0000000..4de45cc --- /dev/null +++ b/ext/standard/tests/array/usort_variation4.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test usort() function : usage variations - numeric data +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of numeric data to usort() to test how it is re-ordered + */ + +echo "*** Testing usort() : usage variation ***\n"; + +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Int array +$int_values = array(0 => 3, 1 => 2, 3 => 100, + 4 => 150, 5 => 25, 6 => 350, + 7 => 0, 8 => -3, 9 => -1200); + +echo "\n-- Sorting Integer array --\n"; +var_dump( usort($int_values, 'cmp_function') ); +var_dump($int_values); + +// Octal array +$octal_values = array(0 => 056, 1 => 023, 2 => 090, + 3 => 015, 4 => -045, 5 => 01, 6 => -078); + +echo "\n-- Sorting Octal array --\n"; +var_dump( usort($octal_values, 'cmp_function') ); +var_dump($octal_values); + +// Hexadecimal array +$hex_values = array(0 => 0xAE, 1 => 0x2B, 2 => 0X10, + 3 => -0xCF, 4 => 0X12, 5 => -0XF2); + +echo "\n-- Sorting Hex array --\n"; +var_dump( usort($hex_values, 'cmp_function') ); +var_dump($hex_values); + +// Float array +$float_values = array( 0 => 10.2, 1 => 2.4, 2 => -3.4, + 3 => 0, 4 => 0.5, 5 => 7.3e3, 6 => -9.34E-2); + +echo "\n-- Sorting Float array --\n"; +var_dump( usort($float_values, 'cmp_function') ); +var_dump($float_values); + +// empty array +$empty_array = array(); + +echo "\n-- Sorting empty array --\n"; +var_dump( usort($empty_array, 'cmp_function') ); +var_dump($empty_array); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Sorting Integer array -- +bool(true) +array(9) { + [0]=> + int(-1200) + [1]=> + int(-3) + [2]=> + int(0) + [3]=> + int(2) + [4]=> + int(3) + [5]=> + int(25) + [6]=> + int(100) + [7]=> + int(150) + [8]=> + int(350) +} + +-- Sorting Octal array -- +bool(true) +array(7) { + [0]=> + int(-37) + [1]=> + int(-7) + [2]=> + int(0) + [3]=> + int(1) + [4]=> + int(13) + [5]=> + int(19) + [6]=> + int(46) +} + +-- Sorting Hex array -- +bool(true) +array(6) { + [0]=> + int(-242) + [1]=> + int(-207) + [2]=> + int(16) + [3]=> + int(18) + [4]=> + int(43) + [5]=> + int(174) +} + +-- Sorting Float array -- +bool(true) +array(7) { + [0]=> + float(-3.4) + [1]=> + float(-0.0934) + [2]=> + int(0) + [3]=> + float(0.5) + [4]=> + float(2.4) + [5]=> + float(10.2) + [6]=> + float(7300) +} + +-- Sorting empty array -- +bool(true) +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/usort_variation5.phpt b/ext/standard/tests/array/usort_variation5.phpt new file mode 100644 index 0000000..922321c --- /dev/null +++ b/ext/standard/tests/array/usort_variation5.phpt @@ -0,0 +1,143 @@ +--TEST-- +Test usort() function : usage variations - string data +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass arrays of string data to usort() to test how it is re-ordered + */ + +echo "*** Testing usort() : usage variation ***\n"; + +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// Different heredoc strings to be sorted +$empty_heredoc =<<<EOT +EOT; + +$simple_heredoc1 =<<<EOT +Heredoc +EOT; + +$simple_heredoc2 =<<<EOT +HEREDOC +EOT; + +$multiline_heredoc =<<<EOT +heredoc string\twith!@# and 123 +Test this!!! +EOT; + +// Single quoted strings +$single_quoted_values = array( + 0 => ' ', 1 => 'test', 3 => 'Hello', 4 => 'HELLO', + 5 => '', 6 => '\t', 7 => '0', 8 => '123Hello', + 9 => '\'', 10 => '@#$%' +); + +echo "\n-- Sorting Single Quoted String values --\n"; +var_dump( usort($single_quoted_values, 'cmp_function') ); +var_dump($single_quoted_values); + +// Double quoted strings +$double_quoted_values = array( + 0 => " ", 1 => "test", 3 => "Hello", 4 => "HELLO", + 5 => "", 6 => "\t", 7 => "0", 8 => "123Hello", + 9 => "\"", 10 => "@#$%" +); + +echo "\n-- Sorting Double Quoted String values --\n"; +var_dump( usort($double_quoted_values, 'cmp_function') ); +var_dump($double_quoted_values); + +// Heredoc strings +$heredoc_values = array(0 => $empty_heredoc, 1 => $simple_heredoc1, + 2 => $simple_heredoc2, 3 => $multiline_heredoc); + +echo "\n-- Sorting Heredoc String values --\n"; +var_dump( usort($heredoc_values, 'cmp_function') ); +var_dump($heredoc_values); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Sorting Single Quoted String values -- +bool(true) +array(10) { + [0]=> + string(0) "" + [1]=> + string(1) " " + [2]=> + string(1) "'" + [3]=> + string(1) "0" + [4]=> + string(8) "123Hello" + [5]=> + string(4) "@#$%" + [6]=> + string(5) "HELLO" + [7]=> + string(5) "Hello" + [8]=> + string(2) "\t" + [9]=> + string(4) "test" +} + +-- Sorting Double Quoted String values -- +bool(true) +array(10) { + [0]=> + string(0) "" + [1]=> + string(1) " " + [2]=> + string(1) " " + [3]=> + string(1) """ + [4]=> + string(1) "0" + [5]=> + string(8) "123Hello" + [6]=> + string(4) "@#$%" + [7]=> + string(5) "HELLO" + [8]=> + string(5) "Hello" + [9]=> + string(4) "test" +} + +-- Sorting Heredoc String values -- +bool(true) +array(4) { + [0]=> + string(0) "" + [1]=> + string(7) "HEREDOC" + [2]=> + string(7) "Heredoc" + [3]=> + string(%d) "heredoc string with!@# and 123 +Test this!!!" +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_variation6.phpt b/ext/standard/tests/array/usort_variation6.phpt new file mode 100644 index 0000000..ab4b3d4 --- /dev/null +++ b/ext/standard/tests/array/usort_variation6.phpt @@ -0,0 +1,139 @@ +--TEST-- +Test usort() function : usage variations - multi-dimensional arrays +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass a multi-dimensional array as $array_arg argument to usort() + * to test how array is re-ordered + */ + +echo "*** Testing usort() : usage variation ***\n"; + +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +$array_args = array( + 0 => array(2, 10, -1), + 1 => array(100), + 2 => array(), + 3 => array(0), + 4 => array(-1), + 5 => array(-9, 34, 54, 0, 20), + 6 => array(''), + 7 => array("apple", "Apple", "APPLE", "aPPle", "aPpLe") +); + +$temp_array = $array_args; + +echo "\n-- Pass usort() a two-dimensional array --\n"; +// sorting array_arg as whole array +var_dump( usort($temp_array, 'cmp_function') ); + +echo "-- Array after call to usort() --\n"; +var_dump($temp_array); + +echo "\n-- Pass usort() a sub-array --\n"; +var_dump( usort($array_args[5], 'cmp_function') ); + +echo "-- Array after call to usort() --\n"; +var_dump($array_args[5]); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Pass usort() a two-dimensional array -- +bool(true) +-- Array after call to usort() -- +array(8) { + [0]=> + array(0) { + } + [1]=> + array(1) { + [0]=> + int(-1) + } + [2]=> + array(1) { + [0]=> + string(0) "" + } + [3]=> + array(1) { + [0]=> + int(0) + } + [4]=> + array(1) { + [0]=> + int(100) + } + [5]=> + array(3) { + [0]=> + int(2) + [1]=> + int(10) + [2]=> + int(-1) + } + [6]=> + array(5) { + [0]=> + int(-9) + [1]=> + int(34) + [2]=> + int(54) + [3]=> + int(0) + [4]=> + int(20) + } + [7]=> + array(5) { + [0]=> + string(5) "apple" + [1]=> + string(5) "Apple" + [2]=> + string(5) "APPLE" + [3]=> + string(5) "aPPle" + [4]=> + string(5) "aPpLe" + } +} + +-- Pass usort() a sub-array -- +bool(true) +-- Array after call to usort() -- +array(5) { + [0]=> + int(-9) + [1]=> + int(0) + [2]=> + int(20) + [3]=> + int(34) + [4]=> + int(54) +} +===DONE=== diff --git a/ext/standard/tests/array/usort_variation7.phpt b/ext/standard/tests/array/usort_variation7.phpt new file mode 100644 index 0000000..e567341 --- /dev/null +++ b/ext/standard/tests/array/usort_variation7.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test usort() function : usage variations - Anonymous comparison function +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an anonymous comparison function as $cmp_function argument to test behaviour() + */ + +echo "*** Testing usort() : usage variation ***\n"; + +$cmp_function = 'if($value1 == $value2) {return 0;} else if($value1 > $value2) {return 1;} else{return -1;}'; + +$array_arg = array(0 => 100, 1 => 3, 2 => -70, 3 => 24, 4 => 90); + +echo "\n-- Anonymous 'cmp_function' with parameters passed by value --\n"; +var_dump( usort($array_arg, create_function('$value1, $value2',$cmp_function) ) ); +var_dump($array_arg); + +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "Apple", "p" => "Pineapple"); + +echo "\n-- Anonymous 'cmp_function' with parameters passed by reference --\n"; +var_dump( usort($array_arg, create_function('&$value1, &$value2', $cmp_function) ) ); +var_dump($array_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Anonymous 'cmp_function' with parameters passed by value -- +bool(true) +array(5) { + [0]=> + int(-70) + [1]=> + int(3) + [2]=> + int(24) + [3]=> + int(90) + [4]=> + int(100) +} + +-- Anonymous 'cmp_function' with parameters passed by reference -- +bool(true) +array(4) { + [0]=> + string(5) "Apple" + [1]=> + string(6) "Banana" + [2]=> + string(5) "Mango" + [3]=> + string(9) "Pineapple" +} +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_variation8.phpt b/ext/standard/tests/array/usort_variation8.phpt new file mode 100644 index 0000000..87107f8 --- /dev/null +++ b/ext/standard/tests/array/usort_variation8.phpt @@ -0,0 +1,85 @@ +--TEST-- +Test usort() function : usage variations - use built in functions as $cmp_function arg +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Test usort() when comparison function is: + * 1. a built in comparison function + * 2. a language construct + */ + +echo "*** Testing usort() : usage variation ***\n"; + +// Initializing variables +$array_arg = array("b" => "Banana", "m" => "Mango", "a" => "apple", + "p" => "Pineapple", "o" => "orange"); + +// Testing library functions as comparison function +echo "\n-- Testing usort() with built-in 'cmp_function': strcasecmp() --\n"; +$temp_array1 = $array_arg; +var_dump( usort($temp_array1, 'strcasecmp') ); +var_dump($temp_array1); + +echo "\n-- Testing usort() with built-in 'cmp_function': strcmp() --\n"; +$temp_array2 = $array_arg; +var_dump( usort($temp_array2, 'strcmp') ); +var_dump($temp_array2); + +// Testing with language construct as comparison function +echo "\n-- Testing usort() with language construct as 'cmp_function' --\n"; +$temp_array3 = $array_arg; +var_dump( usort($temp_array3, 'echo') ); + +echo "\n-- Testing usort() with language construct as 'cmp_function' --\n"; +$temp_array4 = $array_arg; +var_dump( usort($temp_array4, 'exit') ); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Testing usort() with built-in 'cmp_function': strcasecmp() -- +bool(true) +array(5) { + [0]=> + string(5) "apple" + [1]=> + string(6) "Banana" + [2]=> + string(5) "Mango" + [3]=> + string(6) "orange" + [4]=> + string(9) "Pineapple" +} + +-- Testing usort() with built-in 'cmp_function': strcmp() -- +bool(true) +array(5) { + [0]=> + string(6) "Banana" + [1]=> + string(5) "Mango" + [2]=> + string(9) "Pineapple" + [3]=> + string(5) "apple" + [4]=> + string(6) "orange" +} + +-- Testing usort() with language construct as 'cmp_function' -- + +Warning: usort() expects parameter 2 to be a valid callback, function 'echo' not found or invalid function name in %s on line %d +NULL + +-- Testing usort() with language construct as 'cmp_function' -- + +Warning: usort() expects parameter 2 to be a valid callback, function 'exit' not found or invalid function name in %s on line %d +NULL +===DONE===
\ No newline at end of file diff --git a/ext/standard/tests/array/usort_variation9.phpt b/ext/standard/tests/array/usort_variation9.phpt new file mode 100644 index 0000000..6a06799 --- /dev/null +++ b/ext/standard/tests/array/usort_variation9.phpt @@ -0,0 +1,66 @@ +--TEST-- +Test usort() function : usage variations - referenced variables +--FILE-- +<?php +/* Prototype : bool usort(array $array_arg, string $cmp_function) + * Description: Sort an array by values using a user-defined comparison function + * Source code: ext/standard/array.c + */ + +/* + * Pass an array of referenced variables as $array_arg to test behaviour + */ + +echo "*** Testing usort() : usage variation ***\n"; + +function cmp_function($value1, $value2) +{ + if($value1 == $value2) { + return 0; + } + else if($value1 > $value2) { + return 1; + } + else { + return -1; + } +} + +// different variables which are used as elements of $array_arg +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// array_args an array containing elements with reference variables +$array_arg = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +echo "\n-- Sorting \$array_arg containing different references --\n"; +var_dump( usort($array_arg, 'cmp_function') ); +var_dump($array_arg); +?> +===DONE=== +--EXPECTF-- +*** Testing usort() : usage variation *** + +-- Sorting $array_arg containing different references -- +bool(true) +array(5) { + [0]=> + &int(-5) + [1]=> + &int(0) + [2]=> + int(10) + [3]=> + &int(100) + [4]=> + int(200) +} +===DONE=== diff --git a/ext/standard/tests/array/var_export.phpt b/ext/standard/tests/array/var_export.phpt new file mode 100644 index 0000000..8caf407 --- /dev/null +++ b/ext/standard/tests/array/var_export.phpt @@ -0,0 +1,13 @@ +--TEST-- +var_export() and objects with numeric indexes properties +--FILE-- +<?php +$a = (object) array (1, 3, "foo" => "bar"); +var_export($a); +?> +--EXPECT-- +stdClass::__set_state(array( + 0 => 1, + 1 => 3, + 'foo' => 'bar', +)) diff --git a/ext/standard/tests/array/var_export2.phpt b/ext/standard/tests/array/var_export2.phpt new file mode 100644 index 0000000..6db44d5 --- /dev/null +++ b/ext/standard/tests/array/var_export2.phpt @@ -0,0 +1,13 @@ +--TEST-- +var_export() and empty array keys +--FILE-- +<?php +$a = array ("\0" => 'null', "" => 'empty', "0" => 'nul'); +var_export($a); +?> +--EXPECT-- +array ( + '' . "\0" . '' => 'null', + '' => 'empty', + 0 => 'nul', +) diff --git a/ext/standard/tests/array/var_export3.phpt b/ext/standard/tests/array/var_export3.phpt new file mode 100644 index 0000000..6d39946 --- /dev/null +++ b/ext/standard/tests/array/var_export3.phpt @@ -0,0 +1,24 @@ +--TEST-- +var_export() and classes +--FILE-- +<?php +class kake { + public $mann; + protected $kvinne; + + function __construct() + { + $this->mann = 42; + $this->kvinne = 43; + } +} + +$kake = new kake; + +var_export($kake); +?> +--EXPECT-- +kake::__set_state(array( + 'mann' => 42, + 'kvinne' => 43, +)) |