diff options
author | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:39:08 -0400 |
---|---|---|
committer | Mark A. Hershberger <mah@debian.(none)> | 2009-03-25 00:39:08 -0400 |
commit | 993e1866df547532a05ab6db76c9ff5aefc9a3df (patch) | |
tree | 169d3bde0974235d3cde164786ef6f381a4749a7 /ext/standard/tests/array | |
parent | 1f589a2bd44ba835ad1b009a5d83abd453724829 (diff) | |
download | php-993e1866df547532a05ab6db76c9ff5aefc9a3df.tar.gz |
Imported Upstream version 5.2.6upstream/5.2.6
Diffstat (limited to 'ext/standard/tests/array')
369 files changed, 48114 insertions, 428 deletions
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 000000000..e70774e01 --- /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(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: array_change_key_case(): The argument should be an array in %s on line %d +bool(false) +Done 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 000000000..cce432e8d --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation2.phpt @@ -0,0 +1,318 @@ +--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 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 17 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 18 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 19 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 20 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- Iteration 21 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} + +-- 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 000000000..596703385 --- /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 000000000..ad9ad75a3 --- /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 000000000..aa3852a41 --- /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 000000000..d4371d345 --- /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 000000000..173a7ec4d --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation7.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_change_key_case() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- \$input is an array passed by reference --\n"; +echo "Result:\n"; +var_dump(array_change_key_case(&$input, CASE_UPPER)); +echo "Original:\n"; +var_dump($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" +} + +-- $input is an array passed by reference -- +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" +} +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 000000000..f9893da79 --- /dev/null +++ b/ext/standard/tests/array/array_change_key_case_variation8.phpt @@ -0,0 +1,128 @@ +--TEST-- +Test array_change_key_case() function : usage variations - Different strings 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 + */ + +/* + * 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) + ["\e"]=> + 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) + ["\E"]=> + 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
\ No newline at end of file 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 000000000..56a90f479 --- /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 000000000..f96d863e1 --- /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 000000000..519794599 --- /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 000000000..caaf274dd --- /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_variation2.phpt b/ext/standard/tests/array/array_chunk_variation2.phpt new file mode 100644 index 000000000..8cfe99440 --- /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_variation3.phpt b/ext/standard/tests/array/array_chunk_variation3.phpt new file mode 100644 index 000000000..452006a44 --- /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_variation4.phpt b/ext/standard/tests/array/array_chunk_variation4.phpt new file mode 100644 index 000000000..7f04f51bf --- /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 000000000..8d3609282 --- /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 000000000..f44eb3960 --- /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 000000000..c8a71964f --- /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_combine_basic.phpt b/ext/standard/tests/array/array_combine_basic.phpt new file mode 100644 index 000000000..5d855cfec --- /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 000000000..aa5a1afe1 --- /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 000000000..c06fdb490 --- /dev/null +++ b/ext/standard/tests/array/array_combine_error2.phpt @@ -0,0 +1,53 @@ +--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 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) + +-- 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 000000000..c69d4ebaf --- /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 000000000..e58893bae --- /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 000000000..51d8462d5 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation3.phpt @@ -0,0 +1,279 @@ +--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 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) +-- 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 000000000..02ec6efd2 --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation4.phpt @@ -0,0 +1,192 @@ +--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 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) +-- 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 000000000..c3d1d57aa --- /dev/null +++ b/ext/standard/tests/array/array_combine_variation5.phpt @@ -0,0 +1,186 @@ +--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 -- + +Warning: array_combine(): Both parameters should have at least 1 element in %s on line %d +bool(false) +-- 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 000000000..94c7b4d66 --- /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_diff_assoc_basic.phpt b/ext/standard/tests/array/array_diff_assoc_basic.phpt new file mode 100644 index 000000000..c6b3aef00 --- /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 000000000..0c9da2f2c --- /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() 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() function with zero arguments -- + +Warning: Wrong parameter count for array_diff_assoc() in %s on line %d +NULL + +-- Testing array_diff_assoc() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_diff_assoc() 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 000000000..b6c63794b --- /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 000000000..0687ed8a5 --- /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 000000000..5de94424e --- /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 000000000..1d4aaf2e4 --- /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 000000000..34e979ab2 --- /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 000000000..c89c65642 --- /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 000000000..d6190b658 --- /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 000000000..6fab0aebf --- /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 000000000..3189c11f2 --- /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 000000000..5ab623265 --- /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 000000000..30aead657 --- /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 000000000..2e4e86f08 --- /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: Wrong parameter count for array_diff() in %s on line %d +NULL + +-- Testing array_diff() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_diff() in %s on line %d +NULL +Done
\ No newline at end of file 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 000000000..6f6fcb9a4 --- /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_variation1.phpt b/ext/standard/tests/array/array_diff_key_variation1.phpt new file mode 100644 index 000000000..00da7afa9 --- /dev/null +++ b/ext/standard/tests/array/array_diff_key_variation1.phpt @@ -0,0 +1,89 @@ +--TEST-- +array_diff_key() : type variations +--FILE-- +<?php +/* +* proto array array_diff_key(array arr1, array arr2 [, array ...]) +* Function is implemented in ext/standard/array.c +*/ +/* +* Testing how array_diff_key treats keys that are numbers, floating point numbers or strings. +*/ +$arr1 = array(1 => 'a', 2 => 'b', 3 => 'c', 'key1' => 'value'); +$arr2 = array(1.00 => 'a', 2.00 => 'b', 3.00 => 'c', 'key2' => 'value'); +$arr3 = array('1' => 'a', '2' => 'b', '3' => 'c', 'key3' => 'value'); +$arr4 = array('1.00' => 'a', '2.00' => 'b', '3.00' => 'c', 'key4' => 'value'); //$arr4 looks different to the other three arrays. +print "Result of comparing integers and floating point value:\n"; //1 and 1.00 are treated as the same thing +print_r(array_diff_key($arr1, $arr2)); +print_r(array_diff_key($arr2, $arr1)); +print "Result of comparing integers and strings containing an integers:\n"; //1 and the string 1 are treated as the same thing +print_r(array_diff_key($arr1, $arr3)); +print_r(array_diff_key($arr3, $arr1)); +print "Result of comparing integers and strings containing floating points:\n"; //1 and the string 1.00 are not treated as the same thing +print_r(array_diff_key($arr1, $arr4)); +print_r(array_diff_key($arr4, $arr1)); +print "Result of comparing floating points and strings containing integers:\n"; +print_r(array_diff_key($arr2, $arr3)); //1.00 and the string 1 are treated as the same thing +print_r(array_diff_key($arr3, $arr2)); +print "Result of comparing strings containing integers and strings containing floating points:\n"; //the strings 1 and 1.00 are not treated as the same thing. +print_r(array_diff_key($arr3, $arr4)); +print_r(array_diff_key($arr4, $arr3)); +?> +--EXPECTF-- +Result of comparing integers and floating point value: +Array +( + [key1] => value +) +Array +( + [key2] => value +) +Result of comparing integers and strings containing an integers: +Array +( + [key1] => value +) +Array +( + [key3] => value +) +Result of comparing integers and strings containing floating points: +Array +( + [1] => a + [2] => b + [3] => c + [key1] => value +) +Array +( + [1.00] => a + [2.00] => b + [3.00] => c + [key4] => value +) +Result of comparing floating points and strings containing integers: +Array +( + [key2] => value +) +Array +( + [key3] => value +) +Result of comparing strings containing integers and strings containing floating points: +Array +( + [1] => a + [2] => b + [3] => c + [key3] => value +) +Array +( + [1.00] => a + [2.00] => b + [3.00] => c + [key4] => value +) 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 000000000..6a96be6b7 --- /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_ukey_basic.phpt b/ext/standard/tests/array/array_diff_ukey_basic.phpt new file mode 100644 index 000000000..7ac309a01 --- /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_variation1.phpt b/ext/standard/tests/array/array_diff_variation1.phpt new file mode 100644 index 000000000..f9a34b0a5 --- /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 000000000..9442b946d --- /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 000000000..be68c40c2 --- /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 000000000..84f73fd28 --- /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 000000000..75b01adaa --- /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 000000000..cb6b5d3da --- /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 000000000..8ea84bb9d --- /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 000000000..c53cbb3d1 --- /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 000000000..99f9614d7 --- /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 000000000..58d9c201b --- /dev/null +++ b/ext/standard/tests/array/array_diff_variation9.phpt @@ -0,0 +1,100 @@ +--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 -- +array(0) { +} +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 -- +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_intersect_key_basic.phpt b/ext/standard/tests/array/array_intersect_key_basic.phpt new file mode 100644 index 000000000..fc6e177f5 --- /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_uassoc_basic.phpt b/ext/standard/tests/array/array_intersect_uassoc_basic.phpt new file mode 100644 index 000000000..1a2d57ec3 --- /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_ukey_basic.phpt b/ext/standard/tests/array/array_intersect_ukey_basic.phpt new file mode 100644 index 000000000..db21b9b01 --- /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_key_exists_basic.phpt b/ext/standard/tests/array/array_key_exists_basic.phpt new file mode 100644 index 000000000..6fbd415dc --- /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 000000000..f87d2199e --- /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: Wrong parameter count for array_key_exists() in %s on line %d +NULL + +-- Testing array_key_exists() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_key_exists() 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 000000000..6c85f5389 --- /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)#%d (3) { + ["var1"]=> + string(1) "a" + ["var2"]=> + string(1) "b" + ["var3"]=> + NULL +} + +-- Assign a value to $class2->var3 -- +$key = var3: +bool(true) +$class2: +object(myClass)#%d (3) { + ["var1"]=> + string(1) "x" + ["var2"]=> + string(1) "y" + ["var3"]=> + string(1) "z" +} +Done
\ No newline at end of file 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 000000000..07c93b2f8 --- /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)#%d (3) { + ["var1"]=> + string(1) "a" + ["var2:protected"]=> + string(1) "b" + ["var3:private"]=> + NULL +} + +-- Assign a value to $class2->var3 -- +$key = var3: +bool(false) +$class2: +object(myClass)#%d (3) { + ["var1"]=> + string(1) "x" + ["var2:protected"]=> + string(1) "y" + ["var3:private"]=> + string(1) "z" +} +Done
\ No newline at end of file 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 000000000..2f50d3e86 --- /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 000000000..0804006f6 --- /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(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: array_key_exists(): The second argument should be either an array or an object in %s on line %d +bool(false) +Done
\ No newline at end of file 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 000000000..e8a52a705 --- /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 000000000..edc39269a --- /dev/null +++ b/ext/standard/tests/array/array_key_exists_variation4.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_key_exists() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- \$key is a referenced variable --\n"; +$key = 'two'; +var_dump(array_key_exists(&$key, $array)); + +echo "\n-- Both arguments are referenced variables --\n"; +var_dump(array_key_exists(&$key, &$array)); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_key_exists() : usage variations *** + +-- $search is a reference to $array -- +bool(true) + +-- $key is a referenced variable -- +bool(true) + +-- Both arguments are referenced variables -- +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 000000000..9c15759fc --- /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 000000000..d19e58e76 --- /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 000000000..845c1e54b --- /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 000000000..d5bad62e2 --- /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_map.phpt b/ext/standard/tests/array/array_map.phpt deleted file mode 100644 index 78815e083..000000000 --- a/ext/standard/tests/array/array_map.phpt +++ /dev/null @@ -1,423 +0,0 @@ ---TEST-- -Test array_map() function ---FILE-- -<?php -/* Prototype: array array_map ( callback $callback, array $arr1 [, array $...] ); - Description: array_map() returns an array containing all the elements of arr1 - after applying the callback function to each one. The number of - parameters that the callback function accepts should match the - number of arrays passed to the array_map() -*/ - -echo "*** Testing basic operations ***\n"; -/* array_map with null as function and different arrays */ -var_dump( array_map(NULL, array()) ); -var_dump( array_map(NULL, array(), array()) ); -var_dump( array_map(NULL, array(1,2,3), array(1,2,3)) ); -var_dump( array_map(NULL, array(1,2), array(1,2,3,4)) ); -var_dump( array_map(NULL, array("Jan", "Feb", "March"), array("31","28","31")) ); -var_dump( array_map(NULL, array("Text", "Words", "Lineup"), array(4, 5, 6)) ); -var_dump( array_map(NULL, array("a", "ab", "abc", "abcd"), array()) ); -var_dump( array_map(NULL, - array("Jan"=>"01", "Feb"=>"02", "March"=>"03"), - array("31"=>"Jan", "28"=>"Feb", "031"=>"March") - ) - ); - -/* using key as "string" where no.of arguments passed to array_map() is 2 */ -var_dump( array_map( create_function('$n', 'return $n*$n;'), - array("key1"=>1, "key2"=>2, "key3"=>3) - ) - ); - -echo "\n*** Testing possible variations ***\n"; -/* anonymous callback function */ -var_dump( array_map( create_function('$a,$b', 'return $a+$b;'), - array(1,2,3), - array(5,6,7,8,9) - ) - ); - -/* anonymous callback function with reference */ -var_dump( array_map( create_function('&$a, $b', 'return array($a,$b);'), - array("Hello","Good"), - array("World","Day") - ) - ); - -/* callback function with reference */ -$a = array(1,2,3); -function square(&$var) { - return( $var * $var ); -} -print_r( array_map('square', $a) ); - -/* array_map in recursion */ -function square_recur($var) { - if (is_array($var)) - return array_map('square_recur', $var); - return $var * $var; -} -$rec_array = array(1, 2, array(3, 4, array(5, 2), array() ) ); -var_dump( array_map('square_recur', $rec_array) ); - -/* callback function as string variable containing the function name */ -$string_var = "square"; -var_dump( array_map("square", $a) ); -var_dump( array_map($string_var, $a) ); - -echo "\n*** Testing error conditions ***\n"; -/* arguments of non array type */ -$int_var=10; -$float_var = 10.5; -var_dump( array_map('square', $int_var) ); -var_dump( array_map('square', $float_var) ); -var_dump( array_map('square', $string_var) ); - -/* Zero argument */ -var_dump( array_map() ); - -/* use array(), echo(), empty(), eval(), exit(), isset(), list(), print() - and unset() as callback, failure expected */ -var_dump( array_map( 'echo', array(1) ) ); -var_dump( array_map( 'array', array(1) ) ); -var_dump( array_map( 'empty', array(1) ) ); -var_dump( array_map( 'eval', array(1) ) ); -var_dump( array_map( 'exit', array(1) ) ); -var_dump( array_map( 'isset', array(1) ) ); -var_dump( array_map( 'list', array(1) ) ); -var_dump( array_map( 'print', array(1) ) ); - - -echo "\n*** Testing operation on objects ***\n"; -/* array_map with class object */ -class check_array_map { - public static function helloWorld() { - return "Static_Function_helloWorld(): Hello World"; - } - public function Message($v) { - return $v; - } - - public static function Square( $n ) { - return $n * $n; - } -} -/* call static member function */ -var_dump( array_map( array('check_array_map', 'Square'), array(1,2,3)) ); - -/* call non static member function - notice should be issues*/ -var_dump( array_map( array('check_array_map', 'Message'), array(1)) ); - -/* call function using object */ -$obj = new check_array_map(); -var_dump( array_map( array($obj, 'helloWorld' ) ) ); // not enough args warning -var_dump( array_map( array($obj, 'helloWorld'), array(1) ) ); - -echo "Done\n"; -?> ---EXPECTF-- -*** Testing basic operations *** -array(0) { -} -array(0) { -} -array(3) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(2) - } - [2]=> - array(2) { - [0]=> - int(3) - [1]=> - int(3) - } -} -array(4) { - [0]=> - array(2) { - [0]=> - int(1) - [1]=> - int(1) - } - [1]=> - array(2) { - [0]=> - int(2) - [1]=> - int(2) - } - [2]=> - array(2) { - [0]=> - NULL - [1]=> - int(3) - } - [3]=> - array(2) { - [0]=> - NULL - [1]=> - int(4) - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(3) "Jan" - [1]=> - string(2) "31" - } - [1]=> - array(2) { - [0]=> - string(3) "Feb" - [1]=> - string(2) "28" - } - [2]=> - array(2) { - [0]=> - string(5) "March" - [1]=> - string(2) "31" - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(4) "Text" - [1]=> - int(4) - } - [1]=> - array(2) { - [0]=> - string(5) "Words" - [1]=> - int(5) - } - [2]=> - array(2) { - [0]=> - string(6) "Lineup" - [1]=> - int(6) - } -} -array(4) { - [0]=> - array(2) { - [0]=> - string(1) "a" - [1]=> - NULL - } - [1]=> - array(2) { - [0]=> - string(2) "ab" - [1]=> - NULL - } - [2]=> - array(2) { - [0]=> - string(3) "abc" - [1]=> - NULL - } - [3]=> - array(2) { - [0]=> - string(4) "abcd" - [1]=> - NULL - } -} -array(3) { - [0]=> - array(2) { - [0]=> - string(2) "01" - [1]=> - string(3) "Jan" - } - [1]=> - array(2) { - [0]=> - string(2) "02" - [1]=> - string(3) "Feb" - } - [2]=> - array(2) { - [0]=> - string(2) "03" - [1]=> - string(5) "March" - } -} -array(3) { - ["key1"]=> - int(1) - ["key2"]=> - int(4) - ["key3"]=> - int(9) -} - -*** Testing possible variations *** -array(5) { - [0]=> - int(6) - [1]=> - int(8) - [2]=> - int(10) - [3]=> - int(8) - [4]=> - int(9) -} -array(2) { - [0]=> - array(2) { - [0]=> - string(5) "Hello" - [1]=> - string(5) "World" - } - [1]=> - array(2) { - [0]=> - string(4) "Good" - [1]=> - string(3) "Day" - } -} -Array -( - [0] => 1 - [1] => 4 - [2] => 9 -) -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - array(4) { - [0]=> - int(9) - [1]=> - int(16) - [2]=> - array(2) { - [0]=> - int(25) - [1]=> - int(4) - } - [3]=> - array(0) { - } - } -} -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - int(9) -} -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - int(9) -} - -*** Testing error conditions *** - -Warning: array_map(): Argument #2 should be an array in %s on line %d -NULL - -Warning: array_map(): Argument #2 should be an array in %s on line %d -NULL - -Warning: array_map(): Argument #2 should be an array in %s on line %d -NULL - -Warning: Wrong parameter count for array_map() %s on line %d -NULL - -Warning: array_map(): The first argument, 'echo', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'array', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'empty', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'eval', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'exit', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'isset', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'list', should be either NULL or a valid callback in %s on line %d -NULL - -Warning: array_map(): The first argument, 'print', should be either NULL or a valid callback in %s on line %d -NULL - -*** Testing operation on objects *** -array(3) { - [0]=> - int(1) - [1]=> - int(4) - [2]=> - int(9) -} - -Strict Standards: Non-static method check_array_map::Message() cannot be called statically in %s on line %d - -Strict Standards: Non-static method check_array_map::Message() cannot be called statically in %s on line %d -array(1) { - [0]=> - int(1) -} - -Warning: Wrong parameter count for array_map() in %s on line %d -NULL -array(1) { - [0]=> - string(41) "Static_Function_helloWorld(): Hello World" -} -Done diff --git a/ext/standard/tests/array/array_map_basic.phpt b/ext/standard/tests/array/array_map_basic.phpt new file mode 100644 index 000000000..53a7bb4e2 --- /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 000000000..a1c93d0fc --- /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: Wrong parameter count for array_map() in %s on line %d +NULL + +-- Testing array_map() function with one less than expected no. of arguments -- + +Warning: Wrong parameter count for array_map() in %s on line %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 + +Notice: Undefined variable: q in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: q in %s on line %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 000000000..1265e3a74 --- /dev/null +++ b/ext/standard/tests/array/array_map_object1.phpt @@ -0,0 +1,200 @@ +--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; + } +} +var_dump( array_map(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; + } +} +var_dump( array_map(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; + } +} +var_dump( array_map(array('SimpleClassPro', 'mul'), array(2)) ); + +echo "\n-- class without members --"; +class EmptyClass +{ +} +var_dump( array_map(array('EmptyClass'), array(1, 2)) ); + +echo "\n-- 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"; + } +} +var_dump( array_map(array('ChildClass', 'emptyFunction'), array(1, 2)) ); + +echo "\n-- class with final method --"; +class FinalClass +{ + private $var4; + final function finalMethod() { + echo "This function can't be overloaded"; + } +} +var_dump( array_map(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); + } +} +var_dump( array_map(array('StaticClass', 'square'), array(1, 2)) ); +var_dump( array_map(array('StaticClass', 'cube'), array(2)) ); +var_dump( array_map(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; + } +} +var_dump( array_map(array('InterClass', 'square'), array(1, 2))); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : object functionality *** +-- simple class with public variable and method -- + +Strict Standards: Non-static method SimpleClass::square() cannot be called statically in %s on line %d + +Strict Standards: Non-static method SimpleClass::square() cannot be called statically in %s on line %d + +Strict Standards: Non-static method SimpleClass::square() cannot be called statically in %s on line %d +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +-- simple class with private variable and method -- + +Strict Standards: Non-static method SimpleClassPri::add() cannot be called statically in %s on line %d + +Warning: array_map(): The first argument, 'SimpleClassPri::add', should be either NULL or a valid callback in %s on line %d +NULL + +-- simple class with protected variable and method -- + +Strict Standards: Non-static method SimpleClassPro::mul() cannot be called statically in %s on line %d + +Warning: array_map(): The first argument, 'SimpleClassPro::mul', should be either NULL or a valid callback in %s on line %d +NULL + +-- class without members -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- abstract class -- +Strict Standards: Non-static method ChildClass::emptyFunction() cannot be called statically in %s on line %d + +Strict Standards: Non-static method ChildClass::emptyFunction() cannot be called statically in %s on line %d +defined in child +Strict Standards: Non-static method ChildClass::emptyFunction() cannot be called statically in %s on line %d +defined in childarray(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with final method -- +Strict Standards: Non-static method FinalClass::finalMethod() cannot be called statically in %s on line %d + +Strict Standards: Non-static method FinalClass::finalMethod() cannot be called statically in %s on line %d +This function can't be overloaded +Strict Standards: Non-static method FinalClass::finalMethod() cannot be called statically in %s on line %d +This function can't be overloadedarray(2) { + [0]=> + NULL + [1]=> + NULL +} + +-- class with static members -- +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +Warning: array_map(): The first argument, 'StaticClass::cube', should be either NULL or a valid callback in %s on line %d +NULL + +Warning: array_map(): The first argument, 'StaticClass::retVal', should be either NULL or a valid callback in %s on line %d +NULL +-- class implementing an interface -- +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 000000000..91f713018 --- /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(): The first argument, 'non-existent::square', should be either NULL or a valid callback in %s on line %d +NULL +-- with existent class and non-existent method -- + +Warning: array_map(): The first argument, 'SimpleClass::non-existent', should be either NULL or a valid callback 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 000000000..56296a0b8 --- /dev/null +++ b/ext/standard/tests/array/array_map_object3.phpt @@ -0,0 +1,91 @@ +--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(): The first argument, 'ParentClass::staticChild', should be either NULL or a valid callback 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(): The first argument, 'ParentClass::staticChild', should be either NULL or a valid callback 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 000000000..cd09be7ba --- /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 000000000..cc7543699 --- /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 000000000..9cad3668d --- /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 000000000..e599ed5a5 --- /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(): The first argument, 'echo', should be either NULL or a valid callback 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 000000000..94babdf96 --- /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 000000000..baa1f7753 --- /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(): The first argument, '', should be either NULL or a valid callback in %s line %d +NULL +-- with empty array -- + +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback 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 000000000..9844d4c8c --- /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(): The first argument, 'non_existent', should be either NULL or a valid callback 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 000000000..e6972972d --- /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(): The first argument, 'echo', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_map(): The first argument, 'array', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_map(): The first argument, 'empty', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_map(): The first argument, 'eval', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_map(): The first argument, 'exit', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_map(): The first argument, 'isset', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_map(): The first argument, 'list', should be either NULL or a valid callback in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_map(): The first argument, 'print', should be either NULL or a valid callback 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 000000000..4c96af230 --- /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(): The first argument, '0', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_map(): The first argument, '1', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_map(): The first argument, '12345', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_map(): The first argument, '-2345', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_map(): The first argument, '10.5', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_map(): The first argument, '-10.5', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_map(): The first argument, '123456789000', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_map(): The first argument, '1.23456789E-9', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_map(): The first argument, '0.5', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_map(): The first argument, '1', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_map(): The first argument, '1', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_map(): The first argument, '', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_map(): The first argument, 'Array', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_map(): The first argument, 'Class A object', should be either NULL or a valid callback in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_map(): The first argument, 'Resource id #%d', should be either NULL or a valid callback 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 000000000..8170fb846 --- /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 +NULL +-- Iteration 2 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 24 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +-- Iteration 25 -- + +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_variation2.phpt b/ext/standard/tests/array/array_map_variation2.phpt new file mode 100644 index 000000000..6cd0096b6 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation2.phpt @@ -0,0 +1,276 @@ +--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]=> + &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]=> + &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]=> + &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]=> + &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]=> + &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]=> + &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]=> + &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 000000000..a0715504e --- /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 000000000..2517d034e --- /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 + +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) { + [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 000000000..55f156921 --- /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 000000000..2409a5763 --- /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 000000000..8f88a0f88 --- /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 000000000..5672e6cd9 --- /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 000000000..b4f69739d --- /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 + +Notice: Undefined variable: b in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %d + +Warning: Missing argument 2 for callback2() in %s on line %d + +Notice: Undefined variable: b in %s on line %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_basic.phpt b/ext/standard/tests/array/array_merge_basic.phpt new file mode 100644 index 000000000..c4dc69638 --- /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 000000000..3a394bbb7 --- /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: Wrong parameter count for array_merge() in %s on line %d +NULL +Done
\ No newline at end of file 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 000000000..a86a8510a --- /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 000000000..3f8c62e7a --- /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 000000000..b2fb1fd6d --- /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: Wrong parameter count for array_merge_recursive() 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 000000000..75e0c2086 --- /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 000000000..42d315eb8 --- /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 000000000..83f237474 --- /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 000000000..722388a01 --- /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 000000000..bacfe3aff --- /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 000000000..3b251220e --- /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 000000000..8e460ba36 --- /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 000000000..b244e7d6b --- /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 000000000..6ad2f6989 --- /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 000000000..d51d2f890 --- /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 000000000..1ce71debb --- /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 000000000..7f08a4bb7 --- /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 000000000..4ebbeb92b --- /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 000000000..717968adb --- /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 000000000..e4eb2570c --- /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 000000000..eca6078e6 --- /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 000000000..13b346eb3 --- /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 000000000..00943f3ea --- /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 000000000..a4cdea74f --- /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 000000000..e42e29282 --- /dev/null +++ b/ext/standard/tests/array/array_merge_variation9.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test array_merge() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- Merge an array and a reference to the first array --\n"; +var_dump(array_merge($arr2, &$arr2)); + +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" +} + +-- Merge an array and a reference to the first array -- +array(3) { + ["key1"]=> + string(4) "val1" + ["key2"]=> + string(4) "val2" + ["key3"]=> + string(4) "val3" +} +Done diff --git a/ext/standard/tests/array/array_pad_basic.phpt b/ext/standard/tests/array/array_pad_basic.phpt new file mode 100644 index 000000000..1dfc71e01 --- /dev/null +++ b/ext/standard/tests/array/array_pad_basic.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test array_pad() function : basic functionality +--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() : basic functionality ***\n"; + +// Initialise $input and $pad_value arguments +$input = array(1, 2, 3); +$pad_value = -3; + +// positive $pad_size +echo "-- Positive pad_size --\n"; +var_dump( array_pad($input, 8, $pad_value) ); + +// negative $pad_size +echo "-- Negative pad_size --\n"; +var_dump( array_pad($input, -8, $pad_value) ); + +// $pad_size less than array size, no padding expected +echo "-- Pad_size lesser than array_size --\n"; +var_dump( array_pad($input, 2, $pad_value) ); + +// $pad_size equal to array size, no padding expected +echo "-- Pad_size equal to array_size --\n"; +var_dump( array_pad($input, 3, $pad_value) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_pad() : basic functionality *** +-- Positive pad_size -- +array(8) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(-3) + [4]=> + int(-3) + [5]=> + int(-3) + [6]=> + int(-3) + [7]=> + int(-3) +} +-- Negative pad_size -- +array(8) { + [0]=> + int(-3) + [1]=> + int(-3) + [2]=> + int(-3) + [3]=> + int(-3) + [4]=> + int(-3) + [5]=> + int(1) + [6]=> + int(2) + [7]=> + int(3) +} +-- Pad_size lesser than array_size -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +-- Pad_size equal to array_size -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +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 000000000..49fa66e86 --- /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: Wrong parameter count for array_pad() in %s on line %d +NULL + +-- Testing array_pad() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_pad() in %s on line %d +NULL + +-- Testing array_pad() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_pad() in %s on line %d +NULL + +Warning: Wrong parameter count for array_pad() 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 000000000..b92f36da7 --- /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(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 19 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 23 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- +Warning: array_pad(): The argument should be an array in %s on line %d +NULL + +Warning: array_pad(): The argument should be an array 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 000000000..0413b9ef2 --- /dev/null +++ b/ext/standard/tests/array/array_pad_variation2.phpt @@ -0,0 +1,288 @@ +--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 -- +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) +} +-- Iteration 11 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- 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 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 19 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 20 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 21 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 22 -- + +Notice: Object of class classA could not be converted to int in %s on line %d +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- 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 000000000..75df11822 --- /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 000000000..83c1e8300 --- /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 000000000..4e8e0f113 --- /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 000000000..2f97e3ee5 --- /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 000000000..887f35194 --- /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_push_basic.phpt b/ext/standard/tests/array/array_push_basic.phpt new file mode 100644 index 000000000..5ccf037da --- /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 000000000..1b427ff93 --- /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: Wrong parameter count for array_push() in %s on line %d +NULL +Done
\ No newline at end of file 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 000000000..86f8df78b --- /dev/null +++ b/ext/standard/tests/array/array_push_error2.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test array_push() function : error conditions - min and max int values as keys +--SKIPIF-- +<?php +if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only"); +?> +--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 minimum and maximum integer values as array keys + * then try and push new elements onto the array + */ + +echo "*** Testing array_push() : error conditions ***\n"; + +$array = array(-PHP_INT_MAX => 'min', PHP_INT_MAX => 'max'); + +var_dump(array_push($array, 'new')); +var_dump($array); +var_dump(array_push($array, 'var')); +var_dump($array); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing array_push() : error conditions *** +int(3) +array(3) { + [-2147483647]=> + string(3) "min" + [2147483647]=> + string(3) "max" + [-2147483648]=> + string(3) "new" +} + +Warning: array_push(): Cannot add element to the array as the next element is already occupied in %s on line %d +bool(false) +array(3) { + [-2147483647]=> + string(3) "min" + [2147483647]=> + string(3) "max" + [-2147483648]=> + string(3) "new" +} +Done 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 000000000..c4451d9e4 --- /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(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 18 -- +int(1) + +-- Iteration 19 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 22 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: array_push(): First argument should be an array in %s on line %d +bool(false) +Done
\ No newline at end of file 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 000000000..7fefcfa49 --- /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 000000000..2bc71a769 --- /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_variation4.phpt b/ext/standard/tests/array/array_push_variation4.phpt new file mode 100644 index 000000000..1048d80cf --- /dev/null +++ b/ext/standard/tests/array/array_push_variation4.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_push() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--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: + * 1. passed referenced variables as $var arguments + * 2. $var argument is a reference to $stack argument + */ + +echo "*** Testing array_push() : usage variations ***\n"; + +$var1 = 'a'; +$var2 = 'b'; +$var3 = 'c'; +$var4 = 'x'; +$var5 = 'y'; +$var6 = 'z'; + +$array = array(1, 2, 3); + +echo "\n-- Pass array_push referenced varialbes as \$var arguments --\n"; +var_dump(array_push($array, &$var1, &$var2, &$var3, &$var4, &$var5, &$var6)); +var_dump($array); + +echo "\n-- Pass \$var argument which is a reference to \$stack argument --\n"; +var_dump(array_push($array, &$array)); +var_dump($array); + +/* break cycle */ +$array[9] = null; + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_push() : usage variations *** + +-- Pass array_push referenced varialbes as $var arguments -- +int(9) +array(9) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" +} + +-- Pass $var argument which is a reference to $stack argument -- +int(10) +array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" + [9]=> + &array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" + [9]=> + &array(10) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + &string(1) "a" + [4]=> + &string(1) "b" + [5]=> + &string(1) "c" + [6]=> + &string(1) "x" + [7]=> + &string(1) "y" + [8]=> + &string(1) "z" + [9]=> + *RECURSION* + } + } +} +Done 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 000000000..4b6f39975 --- /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 000000000..19afebb74 --- /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_reverse_variation5.phpt b/ext/standard/tests/array/array_reverse_variation5.phpt index 2d22be035..6c4c95224 100644 --- a/ext/standard/tests/array/array_reverse_variation5.phpt +++ b/ext/standard/tests/array/array_reverse_variation5.phpt @@ -1,5 +1,7 @@ --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]) @@ -179,7 +181,7 @@ array(1) { - default argument - array(4) { ["f4"]=> - float(33333333.333333) + float(33333333.3333) [0]=> float(4.8999992284) ["f2"]=> @@ -190,7 +192,7 @@ array(4) { - $preserve keys = true - array(4) { ["f4"]=> - float(33333333.333333) + float(33333333.3333) [3]=> float(4.8999992284) ["f2"]=> @@ -201,7 +203,7 @@ array(4) { - $preserve_keys = false - array(4) { ["f4"]=> - float(33333333.333333) + float(33333333.3333) [0]=> float(4.8999992284) ["f2"]=> 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 000000000..2bb4ae93a --- /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 000000000..bbf62de5b --- /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: Wrong parameter count for array_shift() in %s on line %d +NULL + +-- Testing array_shift() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_shift() 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 000000000..eafe7a90e --- /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(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_shift(): The argument should be an array in %s on line %d +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 000000000..2b3adc605 --- /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 000000000..cc260c630 --- /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 000000000..f27681561 --- /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 000000000..2ac15da6b --- /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 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
\ No newline at end of file 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 000000000..9033e7d17 --- /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 000000000..9367cacbc --- /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 000000000..717d98fad --- /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 000000000..fdf932605 --- /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_basic.phpt b/ext/standard/tests/array/array_slice_basic.phpt new file mode 100644 index 000000000..a4cbe4675 --- /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 000000000..0e8f1c757 --- /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 000000000..4c7a148c8 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation1.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_variation10.phpt b/ext/standard/tests/array/array_slice_variation10.phpt new file mode 100644 index 000000000..85c521d6d --- /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_variation2.phpt b/ext/standard/tests/array/array_slice_variation2.phpt new file mode 100644 index 000000000..d293ce58d --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation2.phpt @@ -0,0 +1,309 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types as $offset 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 $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 000000000..0aafa645e --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation3.phpt @@ -0,0 +1,207 @@ +--TEST-- +Test array_slice() function : usage variations - Pass different data types 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 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(0) { +} + +-- 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 000000000..f093d2db8 --- /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 000000000..ed5c82f18 --- /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 000000000..e210b4dd2 --- /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
\ No newline at end of file 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 000000000..abf517d1f --- /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 000000000..aece410c0 --- /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 000000000..030d4bd73 --- /dev/null +++ b/ext/standard/tests/array/array_slice_variation9.phpt @@ -0,0 +1,75 @@ +--TEST-- +Test array_slice() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- Pass array by reference --\n"; +$new_input = array (1, 2, 3); +var_dump(array_slice(&$new_input, 1)); +echo "-- Check passed array: --\n"; +var_dump($new_input); + +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" +} + +-- Pass array by reference -- +array(2) { + [0]=> + int(2) + [1]=> + int(3) +} +-- Check passed array: -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +Done 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 000000000..c178853d7 --- /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 000000000..ffa7e5b6d --- /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: Wrong parameter count for array_sum() in %s on line %d +NULL +-- Testing array_sum() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_sum() 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 000000000..df6238670 --- /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(): The argument should be an array in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_sum(): The argument should be an array in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_sum(): The argument should be an array 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 000000000..a697a15fc --- /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 000000000..9d32c2c38 --- /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 000000000..4959deee7 --- /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 000000000..9068c4565 --- /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 000000000..ba67cfd49 --- /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 000000000..d30987535 --- /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 000000000..9670eef5d --- /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:private"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(23) + } +}
\ No newline at end of file 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 000000000..636e3abf3 --- /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:private"]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(23) + } +}
\ No newline at end of file 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 000000000..0e6d6154d --- /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:private"]=> + int(9) + } + ["0.5"]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(12) + } + [0]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(23) + } +}
\ No newline at end of file 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 000000000..644109ab6 --- /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:private"]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(-15) + } +}
\ No newline at end of file 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 000000000..1c80a959b --- /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:private"]=> + int(9) + } + [1]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(-15) + } +}
\ No newline at end of file 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 000000000..a0bd055e8 --- /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:private"]=> + int(4) + } + [2]=> + object(cr)#%d (1) { + ["priv_member:private"]=> + int(-15) + } +}
\ No newline at end of file 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 000000000..58d3acf1b --- /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 000000000..59d458a2a --- /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, $extra_arg) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : error conditions *** + +-- Testing array_unique() function with zero arguments -- + +Warning: Wrong parameter count for array_unique() in %s on line %d +NULL + +-- Testing array_unique() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_unique() 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 000000000..3a9ae10dd --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation1.phpt @@ -0,0 +1,194 @@ +--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(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- +array(0) { +} +-- Iteration 22 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +Done
\ No newline at end of file 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 000000000..5cdb43a8e --- /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 +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) ); + $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]=> + string(3) "a" + [1]=> + string(5) "aaaa
" + [2]=> + string(1) "b" + [4]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [4]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +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(87) "hello
world +1111 != 2222 +heredoc +double quoted string. withdifferentwhitespaces" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +-- Iteration 10 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(3) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) +} +-- Iteration 12 -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL +} +-- Iteration 15 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [1]=> + string(0) "" + [6]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [""]=> + 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 000000000..49103c815 --- /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 000000000..a1fc13e94 --- /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 000000000..5e3f7c36d --- /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 000000000..fd8b226fa --- /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) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with reference variables for $input argument *** +array(2) { + [0]=> + int(0) + [1]=> + &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 000000000..e998a73c6 --- /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 000000000..ae6e8bb5c --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation8.phpt @@ -0,0 +1,44 @@ +--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) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : two dimensional array for $input argument *** +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_variation5.phpt b/ext/standard/tests/array/array_unshift_variation5.phpt index ff6bf28f8..7f083694a 100644 --- a/ext/standard/tests/array/array_unshift_variation5.phpt +++ b/ext/standard/tests/array/array_unshift_variation5.phpt @@ -1,5 +1,7 @@ --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 ...]) @@ -209,7 +211,7 @@ array(5) { [1]=> float(4.8999992284) ["f4"]=> - float(33333333.333333) + float(33333333.3333) } int(7) array(7) { @@ -226,7 +228,7 @@ array(7) { [3]=> float(4.8999992284) ["f4"]=> - float(33333333.333333) + float(33333333.3333) } -- Iteration 7 -- int(5) 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 000000000..9cbdf07b8 --- /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_variation1.phpt b/ext/standard/tests/array/array_values_variation1.phpt new file mode 100644 index 000000000..efe08c72b --- /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(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- +array(0) { +} + +-- Iteration 19 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: array_values(): The argument should be an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: array_values(): The argument should be an array 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 000000000..c7e9ad3f7 --- /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 000000000..5c74c0d47 --- /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 000000000..199d23dc9 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation4.phpt @@ -0,0 +1,118 @@ +--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)); + +// break cycle +$input[0] = null; + +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]=> + &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 000000000..d65b4674d --- /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 000000000..e56515076 --- /dev/null +++ b/ext/standard/tests/array/array_values_variation6.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_values() function : usage variations - Referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- Pass \$input argument by reference --\n"; +$array = array(1, 2, 3); +var_dump($result2 = array_values(&$array)); + +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" +} + +-- Pass $input argument by reference -- +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +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 000000000..b71306456 --- /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_walk_basic1.phpt b/ext/standard/tests/array/array_walk_basic1.phpt new file mode 100644 index 000000000..34e8e88c7 --- /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
\ No newline at end of file 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 000000000..e856b580b --- /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 000000000..014885a94 --- /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(): Unable to call non_existent() - function does not exist in %s on line %d +bool(true) +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 000000000..654637ab5 --- /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 Binary files differnew file mode 100644 index 000000000..632b651c0 --- /dev/null +++ b/ext/standard/tests/array/array_walk_object1.phpt 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 000000000..61d052975 --- /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_recursive_basic1.phpt b/ext/standard/tests/array/array_walk_recursive_basic1.phpt new file mode 100644 index 000000000..df192b6a7 --- /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 000000000..c71d92b45 --- /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 000000000..df7092c02 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error1.phpt @@ -0,0 +1,48 @@ +--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) ); + +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(): Unable to call non_existent() - function does not exist in %s on line %d +bool(true) +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 000000000..d628e9327 --- /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 Binary files differnew file mode 100644 index 000000000..30d03a70a --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_object1.phpt 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 000000000..aa12fe869 --- /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 000000000..2673df99a --- /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(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +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 000000000..d94647376 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation2.phpt @@ -0,0 +1,271 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values in place of 'funcname' argument(Bug#43543) +--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; + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// 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, + + // 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(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 11 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 12 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 13 -- + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 14 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 21 -- + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk_recursive(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 22 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk_recursive(): Wrong syntax for function name in %s on line %d +bool(false) +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 000000000..747ba3bb0 --- /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(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 000000000..4db34979a --- /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 000000000..688da57f0 --- /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 000000000..554ade4f4 --- /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 keys +$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 000000000..0cdd6d248 --- /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 000000000..aa73912cf --- /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(1, 2)); + +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(): Unable to call echo() - function does not exist in %s on line %d +bool(true) +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 000000000..f18fe248c --- /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 000000000..e08c0d711 --- /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(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +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 000000000..88fbbf3d5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation2.phpt @@ -0,0 +1,271 @@ +--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; + +// get resource variable +$fp = fopen(__FILE__, 'r'); + +// 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, + + // 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(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 11 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 12 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 13 -- + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call Array() - function does not exist in %s on line %d +bool(true) +-- Iteration 14 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 21 -- + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) + +Warning: array_walk(): Unable to call () - function does not exist in %s on line %d +bool(true) +-- Iteration 22 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) + +Warning: array_walk(): Wrong syntax for function name in %s on line %d +bool(false) +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 000000000..ad2612353 --- /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 000000000..868732daa --- /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 000000000..f42e0f11e --- /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
\ No newline at end of file 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 000000000..c1f23233e --- /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 000000000..da85958b8 --- /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 000000000..2086394dd --- /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(): Unable to call echo() - function does not exist in %s on line %d +bool(true) +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 000000000..42ae20d68 --- /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
\ 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 000000000..676d8265e --- /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_variation1.phpt b/ext/standard/tests/array/arsort_variation1.phpt new file mode 100644 index 000000000..1545abe34 --- /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 000000000..ec483df3a --- /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 000000000..e8bfd772e --- /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 000000000..ab04b4409 --- /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) + [1]=> + int(10) + [2]=> + int(2) +} +-- 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
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation3.phpt b/ext/standard/tests/array/arsort_variation3.phpt new file mode 100644 index 000000000..609155ca7 --- /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 000000000..a76a180f4 --- /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 000000000..e69c26988 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation5.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test arsort() function : usage variations - sort strings +--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" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + 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" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + 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" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + 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
\ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation6.phpt b/ext/standard/tests/array/arsort_variation6.phpt new file mode 100644 index 000000000..687b20a71 --- /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 000000000..97195b709 --- /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 000000000..c2473160c --- /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 000000000..a034db5d9 --- /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/bug26458.phpt b/ext/standard/tests/array/bug26458.phpt Binary files differindex d24e1f151..ecd12ba84 100644 --- a/ext/standard/tests/array/bug26458.phpt +++ b/ext/standard/tests/array/bug26458.phpt diff --git a/ext/standard/tests/array/bug42177.phpt b/ext/standard/tests/array/bug42177.phpt new file mode 100644 index 000000000..63a9b71d9 --- /dev/null +++ b/ext/standard/tests/array/bug42177.phpt @@ -0,0 +1,35 @@ +--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 ); +$a1['key1'] = null; +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/bug42838.phpt b/ext/standard/tests/array/bug42838.phpt new file mode 100644 index 000000000..1f895f31e --- /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 +( +)
\ No newline at end of file diff --git a/ext/standard/tests/array/bug42850.phpt b/ext/standard/tests/array/bug42850.phpt new file mode 100644 index 000000000..737cd170d --- /dev/null +++ b/ext/standard/tests/array/bug42850.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #42850 array_walk_recursive() leaves references, #34982 array_walk_recursive() modifies elements outside function scope +--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 000000000..cd0fab141 --- /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 %s/bug43495.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 000000000..219bbfe29 --- /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/compact_basic.phpt b/ext/standard/tests/array/compact_basic.phpt new file mode 100644 index 000000000..53a946e12 --- /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 000000000..d3d6e2cbb --- /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: Wrong parameter count for compact() in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/count_basic.phpt b/ext/standard/tests/array/count_basic.phpt new file mode 100644 index 000000000..45f63d6a4 --- /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 000000000..76f721364 --- /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_variation1.phpt b/ext/standard/tests/array/count_variation1.phpt new file mode 100644 index 000000000..b40a2ab29 --- /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 000000000..86aecc07b --- /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 000000000..7ec5667d3 --- /dev/null +++ b/ext/standard/tests/array/count_variation3.phpt @@ -0,0 +1,41 @@ +--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)); + +$array1[3] = null; + +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 000000000..cec695977 --- /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 000000000..40362e779 --- /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: Wrong parameter count for current() in %s on line %d +NULL + +-- Testing current() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for current() 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 000000000..cb21df27a --- /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(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- +NULL + +-- Iteration 22 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/current_variation2.phpt b/ext/standard/tests/array/current_variation2.phpt new file mode 100644 index 000000000..49769cea3 --- /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 000000000..bab5e6e0c --- /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 000000000..19864f584 --- /dev/null +++ b/ext/standard/tests/array/current_variation4.phpt @@ -0,0 +1,72 @@ +--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])); +$multi_array[3] = null; +?> +===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/each_basic.phpt b/ext/standard/tests/array/each_basic.phpt new file mode 100644 index 000000000..350b40f9a --- /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 000000000..02c8ef9c0 --- /dev/null +++ b/ext/standard/tests/array/each_error.phpt @@ -0,0 +1,42 @@ +--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: Wrong parameter count for each() in %s on line %d +NULL + +-- Testing each() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for each() in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/each_variation1.phpt b/ext/standard/tests/array/each_variation1.phpt new file mode 100644 index 000000000..0afef3143 --- /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 000000000..3f7211c89 --- /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 000000000..b31ddc61b --- /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 000000000..6ac57a736 --- /dev/null +++ b/ext/standard/tests/array/each_variation4.phpt @@ -0,0 +1,90 @@ +--TEST-- +Test each() function : usage variations - Referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- Pass an array by reference to each(): --\n"; +$arr2 = array('zero', 'one', 'two'); + +var_dump( each(&$arr2) ); +echo "-- Check original array: --\n"; +var_dump($arr2); + +echo "Done"; +?> + +--EXPECTF-- +*** Testing each() : usage variations *** + +-- Array made up of referenced variables: -- +-- Call each until at the end of the array: -- +array(4) { + [1]=> + string(3) "foo" + ["value"]=> + string(3) "foo" + [0]=> + string(3) "one" + ["key"]=> + string(3) "one" +} +array(4) { + [1]=> + string(3) "bar" + ["value"]=> + string(3) "bar" + [0]=> + int(0) + ["key"]=> + int(0) +} +bool(false) + +-- Pass an array by reference to each(): -- +array(4) { + [1]=> + string(4) "zero" + ["value"]=> + string(4) "zero" + [0]=> + int(0) + ["key"]=> + int(0) +} +-- Check original array: -- +array(3) { + [0]=> + string(4) "zero" + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +Done diff --git a/ext/standard/tests/array/each_variation5.phpt b/ext/standard/tests/array/each_variation5.phpt new file mode 100644 index 000000000..941ad5e3a --- /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 000000000..445d63f31 --- /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_basic.phpt b/ext/standard/tests/array/end_basic.phpt new file mode 100644 index 000000000..5a6606d38 --- /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 000000000..1efc5ac54 --- /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: Wrong parameter count for end() in %s on line %d +NULL + +-- Testing end() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for end() 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 000000000..4ed70aeb2 --- /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(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 22 -- +string(12) "hello, world" + +-- Iteration 23 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: end(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/end_variation2.phpt b/ext/standard/tests/array/end_variation2.phpt new file mode 100644 index 000000000..180f7cdfb --- /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 000000000..cd1e2d0ec --- /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/key_basic.phpt b/ext/standard/tests/array/key_basic.phpt new file mode 100644 index 000000000..8fdca1966 --- /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 000000000..ae63bff07 --- /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: Wrong parameter count for key() in %s on line %d +NULL + +-- Testing key() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for key() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/key_variation1.phpt b/ext/standard/tests/array/key_variation1.phpt new file mode 100644 index 000000000..5b4a367ed --- /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(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- +NULL + +-- Iteration 19 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 22 -- +string(4) "var1" + +-- Iteration 23 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: key(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/key_variation2.phpt b/ext/standard/tests/array/key_variation2.phpt new file mode 100644 index 000000000..35389062b --- /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 000000000..a23191781 --- /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 000000000..0ddf05742 --- /dev/null +++ b/ext/standard/tests/array/key_variation4.phpt @@ -0,0 +1,64 @@ +--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])); +$multi_array[3] = null; +?> +===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 000000000..913256897 --- /dev/null +++ b/ext/standard/tests/array/krsort_basic.phpt @@ -0,0 +1,132 @@ +--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" ); +// 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 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(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- 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(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- 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(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- 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 diff --git a/ext/standard/tests/array/krsort_error.phpt b/ext/standard/tests/array/krsort_error.phpt new file mode 100644 index 000000000..1bca5f928 --- /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 000000000..36d8589a8 --- /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 000000000..e4cbaf8d2 --- /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 000000000..f56d2870b --- /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 000000000..0cfa4821a --- /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 000000000..c567f766c --- /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) + [10]=> + int(10) + [2]=> + int(2) +} +-- 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 000000000..8f411a973 --- /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 000000000..3df924ac8 --- /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 000000000..59621654c --- /dev/null +++ b/ext/standard/tests/array/krsort_variation5.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test krsort() function : usage variations - sort 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 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" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + string(1) "
" + [""]=> + string(1) "" + [""]=> + string(1) "" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [""]=> + NULL +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + ["
"]=> + 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 000000000..167d0ee7d --- /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 000000000..9ba3fc544 --- /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 000000000..20276ade6 --- /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 000000000..d7d8343b0 --- /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 000000000..fdc8bd8dc --- /dev/null +++ b/ext/standard/tests/array/ksort_basic.phpt @@ -0,0 +1,131 @@ +--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( "lemon" => "l", "orange" => "o", "banana" => "b" ); +// 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 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(3) { + ["banana"]=> + string(1) "b" + ["lemon"]=> + string(1) "l" + ["orange"]=> + string(1) "o" +} + +-- 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(3) { + ["banana"]=> + string(1) "b" + ["lemon"]=> + string(1) "l" + ["orange"]=> + string(1) "o" +} + +-- 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(3) { + ["banana"]=> + string(1) "b" + ["lemon"]=> + string(1) "l" + ["orange"]=> + string(1) "o" +} + +-- 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 diff --git a/ext/standard/tests/array/ksort_error.phpt b/ext/standard/tests/array/ksort_error.phpt new file mode 100644 index 000000000..f2b102ae0 --- /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 000000000..20e8ba26e --- /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 000000000..d8c037fa9 --- /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 000000000..051bc3061 --- /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 000000000..347df65c4 --- /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 000000000..f765977d2 --- /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) { + [2]=> + int(2) + [10]=> + int(10) + [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 000000000..4029b9b8d --- /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 000000000..d6b3f482b --- /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 000000000..958476c01 --- /dev/null +++ b/ext/standard/tests/array/ksort_variation5.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test ksort() function : usage variations - sort 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 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) "
" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\e"]=> + string(2) "\e" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\e"]=> + string(2) "\e" + ["\xhh"]=> + string(4) "\xhh" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + [""]=> + NULL + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [""]=> + string(1) "" + [""]=> + string(1) "" + ["
"]=> + string(1) "
" + ["\a"]=> + string(2) "\a" + ["\cx"]=> + string(3) "\cx" + ["\ddd"]=> + string(4) "\ddd" + ["\e"]=> + string(2) "\e" + ["\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 000000000..1243ab123 --- /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 000000000..a0f454bbd --- /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 000000000..787e71d61 --- /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 000000000..ed406e20b --- /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/natcasesort_basic.phpt b/ext/standard/tests/array/natcasesort_basic.phpt new file mode 100644 index 000000000..cf6cc5728 --- /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 000000000..0f18677ca --- /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: Wrong parameter count for natcasesort() in %s on line %d +NULL + +-- Testing natcasesort() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for natcasesort() 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 000000000..aab98a45d --- /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 000000000..2b4acec25 --- /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: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: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: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: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 000000000..f6019508c --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation1.phpt @@ -0,0 +1,220 @@ +--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(): The argument should be an array in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 18 -- +bool(true) + +-- Iteration 19 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 22 -- +bool(true) + +-- Iteration 23 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 24 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL + +-- Iteration 25 -- + +Warning: natcasesort(): The argument should be an array in %s on line %d +NULL +Done
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation10.phpt b/ext/standard/tests/array/natcasesort_variation10.phpt new file mode 100644 index 000000000..cffa007b7 --- /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 000000000..98158f15d --- /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 000000000..00edf9434 --- /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 000000000..f15150843 --- /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 diff --git a/ext/standard/tests/array/natcasesort_variation4.phpt b/ext/standard/tests/array/natcasesort_variation4.phpt new file mode 100644 index 000000000..81276ef1c --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation4.phpt @@ -0,0 +1,86 @@ +--TEST-- +Test natcasesort() function : usage variations - different string 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 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) "" + [2]=> + string(2) "\a" + [3]=> + string(3) "\cx" + [9]=> + string(4) "\ddd" + [4]=> + string(2) "\e" + [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
\ No newline at end of file diff --git a/ext/standard/tests/array/natcasesort_variation5.phpt b/ext/standard/tests/array/natcasesort_variation5.phpt new file mode 100644 index 000000000..867d0b89e --- /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 000000000..1d151d80d --- /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 000000000..eefcd1d6f --- /dev/null +++ b/ext/standard/tests/array/natcasesort_variation7.phpt @@ -0,0 +1,98 @@ +--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); + +$array[4] = null; + +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]=> + &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]=> + &array(5) { + [0]=> + int(1) + [3]=> + string(1) "2" + [1]=> + float(3) + [4]=> + *RECURSION* + [2]=> + string(4) "zero" + } + [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 000000000..fbced4a22 --- /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 000000000..98eec05a0 --- /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/next_basic.phpt b/ext/standard/tests/array/next_basic.phpt new file mode 100644 index 000000000..fe8b70c88 --- /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 000000000..ba7596feb --- /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: Wrong parameter count for next() in %s on line %d +NULL + +-- Testing next() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for next() 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 000000000..aa02ac599 --- /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(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 25 -- + +Warning: next(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/next_variation2.phpt b/ext/standard/tests/array/next_variation2.phpt new file mode 100644 index 000000000..e7505096d --- /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/reset_basic.phpt b/ext/standard/tests/array/reset_basic.phpt new file mode 100644 index 000000000..d376e68a2 --- /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 000000000..1bf0f9613 --- /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: Wrong parameter count for reset() in %s on line %d +NULL + +-- Testing reset() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for reset() 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 000000000..0dc99512e --- /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(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 2 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 3 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 4 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 5 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 6 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 7 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 8 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 9 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 10 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 11 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 12 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 13 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 14 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 15 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 16 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 17 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 18 -- +bool(false) + +-- Iteration 19 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 20 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 21 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 22 -- +bool(false) + +-- Iteration 23 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 24 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) + +-- Iteration 25 -- + +Warning: reset(): Passed variable is not an array or object in %s on line %s +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/reset_variation2.phpt b/ext/standard/tests/array/reset_variation2.phpt new file mode 100644 index 000000000..1384affa9 --- /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 000000000..29f965abe --- /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 000000000..5495be925 --- /dev/null +++ b/ext/standard/tests/array/rsort_basic.phpt @@ -0,0 +1,129 @@ +--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", "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 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(3) { + [0]=> + string(6) "orange" + [1]=> + string(5) "lemon" + [2]=> + string(6) "banana" +} + +-- 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(3) { + [0]=> + string(6) "orange" + [1]=> + string(5) "lemon" + [2]=> + string(6) "banana" +} + +-- 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(3) { + [0]=> + string(6) "orange" + [1]=> + string(5) "lemon" + [2]=> + 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 000000000..6f6f2f976 --- /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 000000000..98f7cfec1 --- /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 000000000..216d3c910 --- /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:private"]=> + int(44) + ["protected_class_value:protected"]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value: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: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: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: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: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: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: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:private"]=> + int(44) + ["protected_class_value:protected"]=> + int(4) + } + [1]=> + object(for_integer_rsort)#%d (3) { + ["public_class_value"]=> + int(11) + ["private_class_value: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: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: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: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: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: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: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 000000000..96dac90ae --- /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 000000000..ccf886b07 --- /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 000000000..83bbf84df --- /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 000000000..2196a6494 --- /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 000000000..798e148c7 --- /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 diff --git a/ext/standard/tests/array/rsort_variation4.phpt b/ext/standard/tests/array/rsort_variation4.phpt new file mode 100644 index 000000000..4cab1a933 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation4.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test rsort() function : usage variations - referenced variables +--INI-- +allow_call_time_pass_reference=on +--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 "\n-- 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( rsort(&$temp_array, SORT_NUMERIC) ); +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) +} + +-- 'flag' = SORT_NUMERIC -- +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 000000000..eba6bc420 --- /dev/null +++ b/ext/standard/tests/array/rsort_variation5.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test rsort() function : usage variations - String 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 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(2) "\e" + [2]=> + string(4) "\ddd" + [3]=> + string(3) "\cx" + [4]=> + string(2) "\a" + [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(2) "\e" + [2]=> + string(4) "\ddd" + [3]=> + string(3) "\cx" + [4]=> + string(2) "\a" + [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(2) "\e" + [2]=> + string(4) "\ddd" + [3]=> + string(3) "\cx" + [4]=> + string(2) "\a" + [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
\ No newline at end of file diff --git a/ext/standard/tests/array/rsort_variation6.phpt b/ext/standard/tests/array/rsort_variation6.phpt new file mode 100644 index 000000000..559a1ebaf --- /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 000000000..a996bf6db --- /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 000000000..a4f94b5f0 --- /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 000000000..c08791df1 --- /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/sizeof_basic1.phpt b/ext/standard/tests/array/sizeof_basic1.phpt new file mode 100644 index 000000000..dea4a68ea --- /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 000000000..a2ab2eedf --- /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 000000000..79a75f315 --- /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 000000000..470599605 --- /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 000000000..e2c0816c6 --- /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 000000000..328645f9e --- /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 000000000..a22457978 --- /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 000000000..ba8afb83e --- /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 000000000..a2462757d --- /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 000000000..6e40f7ea7 --- /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/uasort_basic1.phpt b/ext/standard/tests/array/uasort_basic1.phpt new file mode 100644 index 000000000..70dd04c0c --- /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 000000000..e1b4ac9b2 --- /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 000000000..5f3d7ef10 --- /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: Wrong parameter count for uasort() in %s on line %d +NULL +-- Testing uasort() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for uasort() in %s on line %d +NULL +-- Testing uasort() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for uasort() in %s on line %d +NULL +-- Testing uasort() function with non-existent compare function -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Testing uasort() function with non-existent compare function and extra argument -- + +Warning: Wrong parameter count for uasort() 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 000000000..c407ebc1f --- /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)#%d (1) { + ["int_value:private"]=> + int(1) + } + [0]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(10) + } + [3]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(50) + } + [2]=> + object(SimpleClass1)#%d (1) { + ["int_value:private"]=> + int(100) + } +} +bool(true) +array(3) { + [0]=> + object(SimpleClass2)#%d (3) { + ["int_value:private"]=> + int(2) + ["float_value:protected"]=> + float(3.4) + ["string_value"]=> + string(5) "mango" + } + [2]=> + object(SimpleClass2)#%d (3) { + ["int_value:private"]=> + int(5) + ["float_value:protected"]=> + float(2.5) + ["string_value"]=> + string(6) "orange" + } + [1]=> + object(SimpleClass2)#%d (3) { + ["int_value: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 000000000..cd32d8d94 --- /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 000000000..cce86ee0b --- /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(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: uasort(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/uasort_variation10.phpt b/ext/standard/tests/array/uasort_variation10.phpt new file mode 100644 index 000000000..809cb78f5 --- /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 000000000..6d523eaed --- /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 000000000..af1b71c0e --- /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(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 26 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 27 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +-- Iteration 28 -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +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 000000000..9147d5991 --- /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 000000000..c2844bfd2 --- /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 000000000..22d9da31c --- /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(43) "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 000000000..48d9c0357 --- /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 000000000..44a2bb3a2 --- /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 000000000..858ce2009 --- /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(): Invalid comparison function in %s on line %d +bool(false) +-- Testing uasort() with language construct as 'cmp_function' -- + +Warning: uasort(): Invalid comparison function in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/uasort_variation9.phpt b/ext/standard/tests/array/uasort_variation9.phpt new file mode 100644 index 000000000..486042e5e --- /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/var_export2.phpt b/ext/standard/tests/array/var_export2.phpt Binary files differindex 2b8a1f97e..6db44d5ca 100644 --- a/ext/standard/tests/array/var_export2.phpt +++ b/ext/standard/tests/array/var_export2.phpt |