From: Raghubansh Kumar Date: Sat, 22 Sep 2007 06:55:59 +0000 (+0000) Subject: update and split of testcases for functions array_search() and in_array() X-Git-Tag: RELEASE_2_0_0a1~1766 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c35a6365e606acfb5cddc4df066acd1886a6dc4;p=php update and split of testcases for functions array_search() and in_array() --- diff --git a/ext/standard/tests/array/array_search_errors.phpt b/ext/standard/tests/array/array_search_errors.phpt index b4e41eebcb..37b0f2fc40 100644 --- a/ext/standard/tests/array/array_search_errors.phpt +++ b/ext/standard/tests/array/array_search_errors.phpt @@ -1,57 +1,62 @@ --TEST-- -Test array_search() and in_array() functions (errors) +Test array_search() function - error conditions --FILE-- --EXPECTF-- -*** Testing error conditions of in_array() *** +*** Testing error conditions of array_search() *** -Warning: in_array() expects at least 2 parameters, 0 given in %s on line %d +Warning: array_search() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: in_array() expects at most 3 parameters, 4 given in %s on line %d +Warning: array_search() expects at most 3 parameters, 4 given in %s on line %d NULL -Warning: in_array() expects at least 2 parameters, 1 given in %s on line %d +Warning: array_search() expects at least 2 parameters, 1 given in %s on line %d NULL -Warning: in_array() expects parameter 2 to be array, string given in %s on line %d +Warning: array_search() expects parameter 2 to be array, string given in %s on line %d NULL -Warning: in_array() expects parameter 2 to be array, integer given in %s on line %d +Warning: array_search() expects parameter 2 to be array, integer given in %s on line %d NULL Done --UEXPECTF-- -*** Testing error conditions of in_array() *** +*** Testing error conditions of array_search() *** -Warning: in_array() expects at least 2 parameters, 0 given in %s on line %d +Warning: array_search() expects at least 2 parameters, 0 given in %s on line %d NULL -Warning: in_array() expects at most 3 parameters, 4 given in %s on line %d +Warning: array_search() expects at most 3 parameters, 4 given in %s on line %d NULL -Warning: in_array() expects at least 2 parameters, 1 given in %s on line %d +Warning: array_search() expects at least 2 parameters, 1 given in %s on line %d NULL -Warning: in_array() expects parameter 2 to be array, Unicode string given in %s on line %d +Warning: array_search() expects parameter 2 to be array, Unicode string given in %s on line %d NULL -Warning: in_array() expects parameter 2 to be array, integer given in %s on line %d +Warning: array_search() expects parameter 2 to be array, integer given in %s on line %d NULL Done diff --git a/ext/standard/tests/array/array_search_variation1.phpt b/ext/standard/tests/array/array_search_variation1.phpt index 81c9543725..4e1310a94e 100644 --- a/ext/standard/tests/array/array_search_variation1.phpt +++ b/ext/standard/tests/array/array_search_variation1.phpt @@ -1,95 +1,1220 @@ --TEST-- -Test array_search() and in_array() functions (variation-1) +Test array_search() function : usage variations - different needle values --FILE-- 'd', - 3, - ".001" =>-67, - "-.051" =>"k", - 0.091 =>"-.08", - "e" =>"5", - "y" =>NULL, - NULL =>"", - 0, - TRUE, - FALSE, - -27.39999999999, - " ", - "abcd\x00abcd\x00\abcd\x00abcdefghij", - "abcd\nabcd\tabcd\rabcd\0abcd" +echo "*** Testing array_search() with different needle values ***\n"; +$arrays = array ( + array(0), + array("a" => "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL, "b", "ab", "abcd"), + array(4, array(1, 2 => 3), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, -2.989888, "-0.005" => "neg0.005", 2.0 => "float2", "-.9" => -.9), + array(TRUE, FALSE), + array("", array()), + array("abcd\x00abcd\x00abcd"), + array("abcd\tabcd\nabcd\rabcd\0abcdefghij") ); -$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); -/* loop to do loose and strict type check of elements in - $array_type on elements in $misc_array using in_array(); - checking PHP type comparison tables -*/ + +$array_compare = array ( + 4, + "4", + 4.00, + "b", + "5", + -2, + -2.0, + -2.98989, + "-.9", + "True", + "", + array(), + NULL, + "ab", + "abcd", + 0.0, + -0, + "abcd\x00abcd\x00abcd" +); +/* loop to check if elements in $array_compare exist in $arrays + using array_search() */ $counter = 1; -foreach($array_type as $type) { - echo "-- Iteration $counter --\n"; - //loose type checking - var_dump( in_array($type,$misc_array ) ); - //strict type checking - var_dump( in_array($type,$misc_array,true) ); - //loose type checking - var_dump( in_array($type,$misc_array,false) ); - $counter++; +foreach($arrays as $array) { + foreach($array_compare as $compare) { + echo "-- Iteration $counter --\n"; + //strict option OFF + var_dump(array_search($compare,$array)); + //strict option ON + var_dump(array_search($compare,$array,TRUE)); + //strict option OFF + var_dump(array_search($compare,$array,FALSE)); + $counter++; + } } - + echo "Done\n"; ?> --EXPECTF-- -*** Testing loose and strict TYPE comparison of in_array() *** +*** Testing array_search() with different needle values *** -- Iteration 1 -- -bool(true) -bool(true) -bool(true) +bool(false) +bool(false) +bool(false) -- Iteration 2 -- -bool(true) -bool(true) -bool(true) +bool(false) +bool(false) +bool(false) -- Iteration 3 -- -bool(true) bool(false) -bool(true) +bool(false) +bool(false) -- Iteration 4 -- -bool(true) -bool(true) -bool(true) +int(0) +bool(false) +int(0) -- Iteration 5 -- -bool(true) bool(false) -bool(true) +bool(false) +bool(false) -- Iteration 6 -- -bool(true) bool(false) -bool(true) +bool(false) +bool(false) -- Iteration 7 -- -bool(true) bool(false) -bool(true) +bool(false) +bool(false) -- Iteration 8 -- -bool(true) bool(false) -bool(true) +bool(false) +bool(false) -- Iteration 9 -- -bool(true) -bool(true) -bool(true) +bool(false) +bool(false) +bool(false) -- Iteration 10 -- -bool(true) +int(0) bool(false) -bool(true) +int(0) -- Iteration 11 -- -bool(true) +int(0) bool(false) -bool(true) +int(0) -- Iteration 12 -- -bool(true) -bool(true) -bool(true) +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +int(0) +bool(false) +int(0) +-- Iteration 14 -- +int(0) +bool(false) +int(0) +-- Iteration 15 -- +int(0) +bool(false) +int(0) +-- Iteration 16 -- +int(0) +bool(false) +int(0) +-- Iteration 17 -- +int(0) +int(0) +int(0) +-- Iteration 18 -- +int(0) +bool(false) +int(0) +-- Iteration 19 -- +int(4) +int(4) +int(4) +-- Iteration 20 -- +int(4) +bool(false) +int(4) +-- Iteration 21 -- +int(4) +bool(false) +int(4) +-- Iteration 22 -- +int(5) +int(5) +int(5) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 30 -- +string(0) "" +bool(false) +string(0) "" +-- Iteration 31 -- +string(0) "" +string(0) "" +string(0) "" +-- Iteration 32 -- +int(6) +int(6) +int(6) +-- Iteration 33 -- +int(7) +int(7) +int(7) +-- Iteration 34 -- +string(1) "a" +bool(false) +string(1) "a" +-- Iteration 35 -- +string(1) "a" +bool(false) +string(1) "a" +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +int(0) +int(0) +int(0) +-- Iteration 38 -- +int(0) +bool(false) +int(0) +-- Iteration 39 -- +int(0) +bool(false) +int(0) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +int(5) +bool(false) +int(5) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +int(1) +int(1) +int(1) +-- Iteration 61 -- +int(1) +bool(false) +int(1) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +string(3) "-.9" +bool(false) +string(3) "-.9" +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +int(2) +bool(false) +int(2) +-- Iteration 71 -- +int(2) +bool(false) +int(2) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +int(0) +bool(false) +int(0) +-- Iteration 74 -- +int(0) +bool(false) +int(0) +-- Iteration 75 -- +int(0) +bool(false) +int(0) +-- Iteration 76 -- +int(0) +bool(false) +int(0) +-- Iteration 77 -- +int(0) +bool(false) +int(0) +-- Iteration 78 -- +int(0) +bool(false) +int(0) +-- Iteration 79 -- +int(0) +bool(false) +int(0) +-- Iteration 80 -- +int(0) +bool(false) +int(0) +-- Iteration 81 -- +int(0) +bool(false) +int(0) +-- Iteration 82 -- +int(0) +bool(false) +int(0) +-- Iteration 83 -- +int(1) +bool(false) +int(1) +-- Iteration 84 -- +int(1) +bool(false) +int(1) +-- Iteration 85 -- +int(1) +bool(false) +int(1) +-- Iteration 86 -- +int(0) +bool(false) +int(0) +-- Iteration 87 -- +int(0) +bool(false) +int(0) +-- Iteration 88 -- +int(1) +bool(false) +int(1) +-- Iteration 89 -- +int(1) +bool(false) +int(1) +-- Iteration 90 -- +int(0) +bool(false) +int(0) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +int(0) +int(0) +int(0) +-- Iteration 102 -- +int(1) +int(1) +int(1) +-- Iteration 103 -- +int(0) +bool(false) +int(0) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +int(0) +bool(false) +int(0) +-- Iteration 107 -- +int(0) +bool(false) +int(0) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +int(0) +bool(false) +int(0) +-- Iteration 125 -- +int(0) +bool(false) +int(0) +-- Iteration 126 -- +int(0) +int(0) +int(0) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +int(0) +bool(false) +int(0) +-- Iteration 143 -- +int(0) +bool(false) +int(0) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) +Done +--UEXPECTF-- +*** Testing array_search() with different needle values *** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +-- Iteration 4 -- +int(0) +bool(false) +int(0) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +-- Iteration 9 -- +bool(false) +bool(false) +bool(false) +-- Iteration 10 -- +int(0) +bool(false) +int(0) +-- Iteration 11 -- +int(0) +bool(false) +int(0) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +int(0) +bool(false) +int(0) +-- Iteration 14 -- +int(0) +bool(false) +int(0) +-- Iteration 15 -- +int(0) +bool(false) +int(0) +-- Iteration 16 -- +int(0) +bool(false) +int(0) +-- Iteration 17 -- +int(0) +int(0) +int(0) +-- Iteration 18 -- +int(0) +bool(false) +int(0) +-- Iteration 19 -- +int(4) +int(4) +int(4) +-- Iteration 20 -- +int(4) +bool(false) +int(4) +-- Iteration 21 -- +int(4) +bool(false) +int(4) +-- Iteration 22 -- +int(5) +int(5) +int(5) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +unicode(0) "" +bool(false) +unicode(0) "" +-- Iteration 30 -- +unicode(0) "" +bool(false) +unicode(0) "" +-- Iteration 31 -- +unicode(0) "" +unicode(0) "" +unicode(0) "" +-- Iteration 32 -- +int(6) +int(6) +int(6) +-- Iteration 33 -- +int(7) +int(7) +int(7) +-- Iteration 34 -- +unicode(1) "a" +bool(false) +unicode(1) "a" +-- Iteration 35 -- +unicode(1) "a" +bool(false) +unicode(1) "a" +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +int(0) +int(0) +int(0) +-- Iteration 38 -- +int(0) +bool(false) +int(0) +-- Iteration 39 -- +int(0) +bool(false) +int(0) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +int(5) +bool(false) +int(5) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +int(1) +int(1) +int(1) +-- Iteration 61 -- +int(1) +bool(false) +int(1) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +unicode(3) "-.9" +bool(false) +unicode(3) "-.9" +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +int(2) +bool(false) +int(2) +-- Iteration 71 -- +int(2) +bool(false) +int(2) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +int(0) +bool(false) +int(0) +-- Iteration 74 -- +int(0) +bool(false) +int(0) +-- Iteration 75 -- +int(0) +bool(false) +int(0) +-- Iteration 76 -- +int(0) +bool(false) +int(0) +-- Iteration 77 -- +int(0) +bool(false) +int(0) +-- Iteration 78 -- +int(0) +bool(false) +int(0) +-- Iteration 79 -- +int(0) +bool(false) +int(0) +-- Iteration 80 -- +int(0) +bool(false) +int(0) +-- Iteration 81 -- +int(0) +bool(false) +int(0) +-- Iteration 82 -- +int(0) +bool(false) +int(0) +-- Iteration 83 -- +int(1) +bool(false) +int(1) +-- Iteration 84 -- +int(1) +bool(false) +int(1) +-- Iteration 85 -- +int(1) +bool(false) +int(1) +-- Iteration 86 -- +int(0) +bool(false) +int(0) +-- Iteration 87 -- +int(0) +bool(false) +int(0) +-- Iteration 88 -- +int(1) +bool(false) +int(1) +-- Iteration 89 -- +int(1) +bool(false) +int(1) +-- Iteration 90 -- +int(0) +bool(false) +int(0) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +int(0) +int(0) +int(0) +-- Iteration 102 -- +int(1) +int(1) +int(1) +-- Iteration 103 -- +int(0) +bool(false) +int(0) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +int(0) +bool(false) +int(0) +-- Iteration 107 -- +int(0) +bool(false) +int(0) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +int(0) +bool(false) +int(0) +-- Iteration 125 -- +int(0) +bool(false) +int(0) +-- Iteration 126 -- +int(0) +int(0) +int(0) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +int(0) +bool(false) +int(0) +-- Iteration 143 -- +int(0) +bool(false) +int(0) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) Done diff --git a/ext/standard/tests/array/array_search_variation2.phpt b/ext/standard/tests/array/array_search_variation2.phpt index 885ab3e745..308a4145fa 100644 --- a/ext/standard/tests/array/array_search_variation2.phpt +++ b/ext/standard/tests/array/array_search_variation2.phpt @@ -1,53 +1,153 @@ --TEST-- -Test array_search() and in_array() functions (variation-2) +Test array_search() function : usage variations - different haystack values --FILE-- "two", "three" => 3), - 4 => "four", - "five" => 5, - array('', 'i') -); -var_dump( in_array("four", $sub_array) ); -//checking for element in a sub-array -var_dump( in_array(3, $sub_array[1]) ); -var_dump( in_array(array('','i'), $sub_array) ); +/* Test array_search() with different possible haystack values */ -/* checking for objects in in_array() */ -echo "\n*** Testing objects with in_array() ***\n"; -class in_array_check { - public $array_var = array(1=>"one", "two"=>2, 3=>3); - public function foo() { - echo "Public function\n"; - } -} +echo "*** Testing array_search() with different haystack values ***\n"; -$in_array_obj = new in_array_check(); //creating new object -//error: as wrong datatype for second argument -var_dump( in_array("array_var", $in_array_obj) ); -//error: as wrong datatype for second argument -var_dump( in_array("foo", $in_array_obj) ); -//element found as "one" exists in array $array_var -var_dump( in_array("one", $in_array_obj->array_var) ); +$misc_array = array ( + 'a', + 'key' =>'d', + 3, + ".001" =>-67, + "-.051" =>"k", + 0.091 =>"-.08", + "e" =>"5", + "y" =>NULL, + NULL =>"", + 0, + TRUE, + FALSE, + -27.39999999999, + " ", + "abcd\x00abcd\x00\abcd\x00abcdefghij", + "abcd\nabcd\tabcd\rabcd\0abcd" +); +$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); +/* loop to do loose and strict type check of elements in + $array_type on elements in $misc_array using array_search(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( array_search($type,$misc_array ) ); + //strict type checking + var_dump( array_search($type,$misc_array,true) ); + //loose type checking + var_dump( array_search($type,$misc_array,false) ); + $counter++; +} echo "Done\n"; ?> --EXPECTF-- -*** Testing sub-arrays with in_array() *** -bool(true) -bool(true) -bool(true) - -*** Testing objects with in_array() *** - -Warning: in_array() expects parameter 2 to be array, object given in %s on line %d -NULL - -Warning: in_array() expects parameter 2 to be array, object given in %s on line %d -NULL -bool(true) +*** Testing array_search() with different haystack values *** +-- Iteration 1 -- +int(0) +int(3) +int(0) +-- Iteration 2 -- +string(1) "y" +int(4) +string(1) "y" +-- Iteration 3 -- +int(3) +bool(false) +int(3) +-- Iteration 4 -- +string(3) "key" +int(2) +string(3) "key" +-- Iteration 5 -- +int(3) +bool(false) +int(3) +-- Iteration 6 -- +int(3) +bool(false) +int(3) +-- Iteration 7 -- +int(2) +bool(false) +int(2) +-- Iteration 8 -- +int(3) +bool(false) +int(3) +-- Iteration 9 -- +string(1) "y" +string(1) "y" +string(1) "y" +-- Iteration 10 -- +string(1) "y" +bool(false) +string(1) "y" +-- Iteration 11 -- +int(2) +bool(false) +int(2) +-- Iteration 12 -- +string(1) "y" +string(0) "" +string(1) "y" +Done +--UEXPECTF-- +*** Testing array_search() with different haystack values *** +-- Iteration 1 -- +int(0) +int(3) +int(0) +-- Iteration 2 -- +unicode(1) "y" +int(4) +unicode(1) "y" +-- Iteration 3 -- +int(3) +bool(false) +int(3) +-- Iteration 4 -- +unicode(3) "key" +int(2) +unicode(3) "key" +-- Iteration 5 -- +int(3) +bool(false) +int(3) +-- Iteration 6 -- +int(3) +bool(false) +int(3) +-- Iteration 7 -- +int(2) +bool(false) +int(2) +-- Iteration 8 -- +int(3) +bool(false) +int(3) +-- Iteration 9 -- +unicode(1) "y" +unicode(1) "y" +unicode(1) "y" +-- Iteration 10 -- +unicode(1) "y" +bool(false) +unicode(1) "y" +-- Iteration 11 -- +int(2) +bool(false) +int(2) +-- Iteration 12 -- +unicode(1) "y" +unicode(0) "" +unicode(1) "y" Done diff --git a/ext/standard/tests/array/array_search_variation3.phpt b/ext/standard/tests/array/array_search_variation3.phpt index 83b6070213..11f0eed163 100644 --- a/ext/standard/tests/array/array_search_variation3.phpt +++ b/ext/standard/tests/array/array_search_variation3.phpt @@ -1,69 +1,73 @@ --TEST-- -Test array_search() and in_array() functions (variation-3) +Test array_search() function : usage variations - haystack as sub-array/object --FILE-- "two", "three" => 3), + 4 => "four", + "five" => 5, + array('', 'i') +); +var_dump( array_search("four", $sub_array) ); +//checking for element in a sub-array +var_dump( array_search(3, $sub_array[1]) ); +var_dump( array_search(array('','i'), $sub_array) ); -//directory type resource -$dir_handle = opendir( dirname(__FILE__) ); +/* checking for objects in array_search() */ +echo "\n*** Testing objects with array_search() ***\n"; +class array_search_check { + public $array_var = array(1=>"one", "two"=>2, 3=>3); + public function foo() { + echo "Public function\n"; + } +} -//store resources in array for comparision. -$resources = array($file_handle, $dir_handle); +$array_search_obj = new array_search_check(); //creating new object +//error: as wrong datatype for second argument +var_dump( array_search("array_var", $array_search_obj) ); +//error: as wrong datatype for second argument +var_dump( array_search("foo", $array_search_obj) ); +//element found as "one" exists in array $array_var +var_dump( array_search("one", $array_search_obj->array_var) ); -// search for resouce type in the resource array -var_dump( in_array($file_handle, $resources, true) ); -//checking for (int) type resource -var_dump( in_array((int)$dir_handle, $resources, true) ); - -/* Miscellenous input check */ -echo "\n*** Testing miscelleneos inputs with in_array() ***\n"; -//matching "Good" in array(0,"hello"), result:true in loose type check -var_dump( in_array("Good", array(0,"hello")) ); -//false in strict mode -var_dump( in_array("Good", array(0,"hello"), TRUE) ); +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sub-arrays with array_search() *** +int(4) +string(5) "three" +int(5) -//matching integer 0 in array("this"), result:true in loose type check -var_dump( in_array(0, array("this")) ); -// false in strict mode -var_dump( in_array(0, array("this")),TRUE ); +*** Testing objects with array_search() *** -//matching string "this" in array(0), result:true in loose type check -var_dump( in_array("this", array(0)) ); -// false in stric mode -var_dump( in_array("this", array(0), TRUE) ); +Warning: array_search() expects parameter 2 to be array, object given in %s on line %d +NULL -//checking for type FALSE in multidimensional array with loose checking, result:false in loose type check -var_dump( in_array(FALSE, - array("a"=> TRUE, "b"=> TRUE, - array("c"=> TRUE, "d"=>TRUE) - ) - ) - ); +Warning: array_search() expects parameter 2 to be array, object given in %s on line %d +NULL +int(1) +Done +--UEXPECTF-- +*** Testing sub-arrays with array_search() *** +int(4) +unicode(5) "three" +int(5) -//matching string having integer in beginning, result:true in loose type check -var_dump( in_array('123abc', array(123)) ); -var_dump( in_array('123abc', array(123), TRUE) ); // false in strict mode +*** Testing objects with array_search() *** -echo "Done\n"; -?> ---EXPECTF-- -*** Testing resource type with in_array() *** -bool(true) -bool(false) +Warning: array_search() expects parameter 2 to be array, object given in %s on line %d +NULL -*** Testing miscelleneos inputs with in_array() *** -bool(true) -bool(false) -bool(true) -bool(true) -bool(true) -bool(true) -bool(false) -bool(false) -bool(true) -bool(false) +Warning: array_search() expects parameter 2 to be array, object given in %s on line %d +NULL +int(1) Done diff --git a/ext/standard/tests/array/array_search_variation4.phpt b/ext/standard/tests/array/array_search_variation4.phpt new file mode 100644 index 0000000000..92ea4e2905 --- /dev/null +++ b/ext/standard/tests/array/array_search_variation4.phpt @@ -0,0 +1,91 @@ +--TEST-- +Test array_search() function : usage variations - haystack as resource/multi dimentional array +--FILE-- + TRUE, "b"=> TRUE, + array("c"=> TRUE, "d"=>TRUE) + ) + ) + ); + +//matching string having integer in beginning, result:true in loose type check +var_dump( array_search('123abc', array(123)) ); +var_dump( array_search('123abc', array(123), TRUE) ); // false in strict mode + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing resource type with array_search() *** +int(0) +bool(false) + +*** Testing miscelleneos inputs with array_search() *** +int(0) +bool(false) +int(0) +int(0) +bool(true) +int(0) +bool(false) +bool(false) +int(0) +bool(false) +Done +--UEXPECTF-- +*** Testing resource type with array_search() *** +int(0) +bool(false) + +*** Testing miscelleneos inputs with array_search() *** +int(0) +bool(false) +int(0) +int(0) +bool(true) +int(0) +bool(false) +bool(false) +int(0) +bool(false) +Done diff --git a/ext/standard/tests/array/in_array_errors.phpt b/ext/standard/tests/array/in_array_errors.phpt new file mode 100644 index 0000000000..cc27c1e4bd --- /dev/null +++ b/ext/standard/tests/array/in_array_errors.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test in_array() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing error conditions of in_array() *** + +Warning: in_array() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: in_array() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: in_array() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, string given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, integer given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing error conditions of in_array() *** + +Warning: in_array() expects at least 2 parameters, 0 given in %s on line %d +NULL + +Warning: in_array() expects at most 3 parameters, 4 given in %s on line %d +NULL + +Warning: in_array() expects at least 2 parameters, 1 given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, Unicode string given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, integer given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/in_array_variation1.phpt b/ext/standard/tests/array/in_array_variation1.phpt new file mode 100644 index 0000000000..0e1cf7fde2 --- /dev/null +++ b/ext/standard/tests/array/in_array_variation1.phpt @@ -0,0 +1,1221 @@ +--TEST-- +Test in_array() function : usage variations - different needdle values +--FILE-- + "A", 2 => "B", "C" => 3, 4 => 4, "one" => 1, "" => NULL, "b", "ab", "abcd"), + array(4, array(1, 2 => 3), "one" => 1, "5" => 5 ), + array(-1, -2, -3, -4, -2.989888, "-0.005" => "neg0.005", 2.0 => "float2", "-.9" => -.9), + array(TRUE, FALSE), + array("", array()), + array("abcd\x00abcd\x00abcd"), + array("abcd\tabcd\nabcd\rabcd\0abcdefghij") +); + +$array_compare = array ( + 4, + "4", + 4.00, + "b", + "5", + -2, + -2.0, + -2.98989, + "-.9", + "True", + "", + array(), + NULL, + "ab", + "abcd", + 0.0, + -0, + "abcd\x00abcd\x00abcd" +); +/* loop to check if elements in $array_compare exist in $arrays + using in_array() */ +$counter = 1; +foreach($arrays as $array) { + foreach($array_compare as $compare) { + echo "-- Iteration $counter --\n"; + //strict option OFF + var_dump(in_array($compare,$array)); + //strict option ON + var_dump(in_array($compare,$array,TRUE)); + //strict option OFF + var_dump(in_array($compare,$array,FALSE)); + $counter++; + } +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing in_array() with different needle values *** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +-- Iteration 9 -- +bool(false) +bool(false) +bool(false) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +bool(true) +bool(false) +bool(true) +-- Iteration 14 -- +bool(true) +bool(false) +bool(true) +-- Iteration 15 -- +bool(true) +bool(false) +bool(true) +-- Iteration 16 -- +bool(true) +bool(false) +bool(true) +-- Iteration 17 -- +bool(true) +bool(true) +bool(true) +-- Iteration 18 -- +bool(true) +bool(false) +bool(true) +-- Iteration 19 -- +bool(true) +bool(true) +bool(true) +-- Iteration 20 -- +bool(true) +bool(false) +bool(true) +-- Iteration 21 -- +bool(true) +bool(false) +bool(true) +-- Iteration 22 -- +bool(true) +bool(true) +bool(true) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +bool(true) +bool(false) +bool(true) +-- Iteration 30 -- +bool(true) +bool(false) +bool(true) +-- Iteration 31 -- +bool(true) +bool(true) +bool(true) +-- Iteration 32 -- +bool(true) +bool(true) +bool(true) +-- Iteration 33 -- +bool(true) +bool(true) +bool(true) +-- Iteration 34 -- +bool(true) +bool(false) +bool(true) +-- Iteration 35 -- +bool(true) +bool(false) +bool(true) +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +bool(true) +bool(true) +bool(true) +-- Iteration 38 -- +bool(true) +bool(false) +bool(true) +-- Iteration 39 -- +bool(true) +bool(false) +bool(true) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +bool(true) +bool(false) +bool(true) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +bool(true) +bool(true) +bool(true) +-- Iteration 61 -- +bool(true) +bool(false) +bool(true) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +bool(true) +bool(false) +bool(true) +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +bool(true) +bool(false) +bool(true) +-- Iteration 71 -- +bool(true) +bool(false) +bool(true) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +bool(true) +bool(false) +bool(true) +-- Iteration 74 -- +bool(true) +bool(false) +bool(true) +-- Iteration 75 -- +bool(true) +bool(false) +bool(true) +-- Iteration 76 -- +bool(true) +bool(false) +bool(true) +-- Iteration 77 -- +bool(true) +bool(false) +bool(true) +-- Iteration 78 -- +bool(true) +bool(false) +bool(true) +-- Iteration 79 -- +bool(true) +bool(false) +bool(true) +-- Iteration 80 -- +bool(true) +bool(false) +bool(true) +-- Iteration 81 -- +bool(true) +bool(false) +bool(true) +-- Iteration 82 -- +bool(true) +bool(false) +bool(true) +-- Iteration 83 -- +bool(true) +bool(false) +bool(true) +-- Iteration 84 -- +bool(true) +bool(false) +bool(true) +-- Iteration 85 -- +bool(true) +bool(false) +bool(true) +-- Iteration 86 -- +bool(true) +bool(false) +bool(true) +-- Iteration 87 -- +bool(true) +bool(false) +bool(true) +-- Iteration 88 -- +bool(true) +bool(false) +bool(true) +-- Iteration 89 -- +bool(true) +bool(false) +bool(true) +-- Iteration 90 -- +bool(true) +bool(false) +bool(true) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +bool(true) +bool(true) +bool(true) +-- Iteration 102 -- +bool(true) +bool(true) +bool(true) +-- Iteration 103 -- +bool(true) +bool(false) +bool(true) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +bool(true) +bool(false) +bool(true) +-- Iteration 107 -- +bool(true) +bool(false) +bool(true) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +bool(true) +bool(false) +bool(true) +-- Iteration 125 -- +bool(true) +bool(false) +bool(true) +-- Iteration 126 -- +bool(true) +bool(true) +bool(true) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +bool(true) +bool(false) +bool(true) +-- Iteration 143 -- +bool(true) +bool(false) +bool(true) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) +Done +--UEXPECTF-- +*** Testing in_array() with different needle values *** +-- Iteration 1 -- +bool(false) +bool(false) +bool(false) +-- Iteration 2 -- +bool(false) +bool(false) +bool(false) +-- Iteration 3 -- +bool(false) +bool(false) +bool(false) +-- Iteration 4 -- +bool(true) +bool(false) +bool(true) +-- Iteration 5 -- +bool(false) +bool(false) +bool(false) +-- Iteration 6 -- +bool(false) +bool(false) +bool(false) +-- Iteration 7 -- +bool(false) +bool(false) +bool(false) +-- Iteration 8 -- +bool(false) +bool(false) +bool(false) +-- Iteration 9 -- +bool(false) +bool(false) +bool(false) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(false) +bool(false) +bool(false) +-- Iteration 13 -- +bool(true) +bool(false) +bool(true) +-- Iteration 14 -- +bool(true) +bool(false) +bool(true) +-- Iteration 15 -- +bool(true) +bool(false) +bool(true) +-- Iteration 16 -- +bool(true) +bool(false) +bool(true) +-- Iteration 17 -- +bool(true) +bool(true) +bool(true) +-- Iteration 18 -- +bool(true) +bool(false) +bool(true) +-- Iteration 19 -- +bool(true) +bool(true) +bool(true) +-- Iteration 20 -- +bool(true) +bool(false) +bool(true) +-- Iteration 21 -- +bool(true) +bool(false) +bool(true) +-- Iteration 22 -- +bool(true) +bool(true) +bool(true) +-- Iteration 23 -- +bool(false) +bool(false) +bool(false) +-- Iteration 24 -- +bool(false) +bool(false) +bool(false) +-- Iteration 25 -- +bool(false) +bool(false) +bool(false) +-- Iteration 26 -- +bool(false) +bool(false) +bool(false) +-- Iteration 27 -- +bool(false) +bool(false) +bool(false) +-- Iteration 28 -- +bool(false) +bool(false) +bool(false) +-- Iteration 29 -- +bool(true) +bool(false) +bool(true) +-- Iteration 30 -- +bool(true) +bool(false) +bool(true) +-- Iteration 31 -- +bool(true) +bool(true) +bool(true) +-- Iteration 32 -- +bool(true) +bool(true) +bool(true) +-- Iteration 33 -- +bool(true) +bool(true) +bool(true) +-- Iteration 34 -- +bool(true) +bool(false) +bool(true) +-- Iteration 35 -- +bool(true) +bool(false) +bool(true) +-- Iteration 36 -- +bool(false) +bool(false) +bool(false) +-- Iteration 37 -- +bool(true) +bool(true) +bool(true) +-- Iteration 38 -- +bool(true) +bool(false) +bool(true) +-- Iteration 39 -- +bool(true) +bool(false) +bool(true) +-- Iteration 40 -- +bool(false) +bool(false) +bool(false) +-- Iteration 41 -- +bool(true) +bool(false) +bool(true) +-- Iteration 42 -- +bool(false) +bool(false) +bool(false) +-- Iteration 43 -- +bool(false) +bool(false) +bool(false) +-- Iteration 44 -- +bool(false) +bool(false) +bool(false) +-- Iteration 45 -- +bool(false) +bool(false) +bool(false) +-- Iteration 46 -- +bool(false) +bool(false) +bool(false) +-- Iteration 47 -- +bool(false) +bool(false) +bool(false) +-- Iteration 48 -- +bool(false) +bool(false) +bool(false) +-- Iteration 49 -- +bool(false) +bool(false) +bool(false) +-- Iteration 50 -- +bool(false) +bool(false) +bool(false) +-- Iteration 51 -- +bool(false) +bool(false) +bool(false) +-- Iteration 52 -- +bool(false) +bool(false) +bool(false) +-- Iteration 53 -- +bool(false) +bool(false) +bool(false) +-- Iteration 54 -- +bool(false) +bool(false) +bool(false) +-- Iteration 55 -- +bool(false) +bool(false) +bool(false) +-- Iteration 56 -- +bool(false) +bool(false) +bool(false) +-- Iteration 57 -- +bool(false) +bool(false) +bool(false) +-- Iteration 58 -- +bool(false) +bool(false) +bool(false) +-- Iteration 59 -- +bool(false) +bool(false) +bool(false) +-- Iteration 60 -- +bool(true) +bool(true) +bool(true) +-- Iteration 61 -- +bool(true) +bool(false) +bool(true) +-- Iteration 62 -- +bool(false) +bool(false) +bool(false) +-- Iteration 63 -- +bool(true) +bool(false) +bool(true) +-- Iteration 64 -- +bool(false) +bool(false) +bool(false) +-- Iteration 65 -- +bool(false) +bool(false) +bool(false) +-- Iteration 66 -- +bool(false) +bool(false) +bool(false) +-- Iteration 67 -- +bool(false) +bool(false) +bool(false) +-- Iteration 68 -- +bool(false) +bool(false) +bool(false) +-- Iteration 69 -- +bool(false) +bool(false) +bool(false) +-- Iteration 70 -- +bool(true) +bool(false) +bool(true) +-- Iteration 71 -- +bool(true) +bool(false) +bool(true) +-- Iteration 72 -- +bool(false) +bool(false) +bool(false) +-- Iteration 73 -- +bool(true) +bool(false) +bool(true) +-- Iteration 74 -- +bool(true) +bool(false) +bool(true) +-- Iteration 75 -- +bool(true) +bool(false) +bool(true) +-- Iteration 76 -- +bool(true) +bool(false) +bool(true) +-- Iteration 77 -- +bool(true) +bool(false) +bool(true) +-- Iteration 78 -- +bool(true) +bool(false) +bool(true) +-- Iteration 79 -- +bool(true) +bool(false) +bool(true) +-- Iteration 80 -- +bool(true) +bool(false) +bool(true) +-- Iteration 81 -- +bool(true) +bool(false) +bool(true) +-- Iteration 82 -- +bool(true) +bool(false) +bool(true) +-- Iteration 83 -- +bool(true) +bool(false) +bool(true) +-- Iteration 84 -- +bool(true) +bool(false) +bool(true) +-- Iteration 85 -- +bool(true) +bool(false) +bool(true) +-- Iteration 86 -- +bool(true) +bool(false) +bool(true) +-- Iteration 87 -- +bool(true) +bool(false) +bool(true) +-- Iteration 88 -- +bool(true) +bool(false) +bool(true) +-- Iteration 89 -- +bool(true) +bool(false) +bool(true) +-- Iteration 90 -- +bool(true) +bool(false) +bool(true) +-- Iteration 91 -- +bool(false) +bool(false) +bool(false) +-- Iteration 92 -- +bool(false) +bool(false) +bool(false) +-- Iteration 93 -- +bool(false) +bool(false) +bool(false) +-- Iteration 94 -- +bool(false) +bool(false) +bool(false) +-- Iteration 95 -- +bool(false) +bool(false) +bool(false) +-- Iteration 96 -- +bool(false) +bool(false) +bool(false) +-- Iteration 97 -- +bool(false) +bool(false) +bool(false) +-- Iteration 98 -- +bool(false) +bool(false) +bool(false) +-- Iteration 99 -- +bool(false) +bool(false) +bool(false) +-- Iteration 100 -- +bool(false) +bool(false) +bool(false) +-- Iteration 101 -- +bool(true) +bool(true) +bool(true) +-- Iteration 102 -- +bool(true) +bool(true) +bool(true) +-- Iteration 103 -- +bool(true) +bool(false) +bool(true) +-- Iteration 104 -- +bool(false) +bool(false) +bool(false) +-- Iteration 105 -- +bool(false) +bool(false) +bool(false) +-- Iteration 106 -- +bool(true) +bool(false) +bool(true) +-- Iteration 107 -- +bool(true) +bool(false) +bool(true) +-- Iteration 108 -- +bool(false) +bool(false) +bool(false) +-- Iteration 109 -- +bool(false) +bool(false) +bool(false) +-- Iteration 110 -- +bool(false) +bool(false) +bool(false) +-- Iteration 111 -- +bool(false) +bool(false) +bool(false) +-- Iteration 112 -- +bool(false) +bool(false) +bool(false) +-- Iteration 113 -- +bool(false) +bool(false) +bool(false) +-- Iteration 114 -- +bool(false) +bool(false) +bool(false) +-- Iteration 115 -- +bool(false) +bool(false) +bool(false) +-- Iteration 116 -- +bool(false) +bool(false) +bool(false) +-- Iteration 117 -- +bool(false) +bool(false) +bool(false) +-- Iteration 118 -- +bool(false) +bool(false) +bool(false) +-- Iteration 119 -- +bool(false) +bool(false) +bool(false) +-- Iteration 120 -- +bool(false) +bool(false) +bool(false) +-- Iteration 121 -- +bool(false) +bool(false) +bool(false) +-- Iteration 122 -- +bool(false) +bool(false) +bool(false) +-- Iteration 123 -- +bool(false) +bool(false) +bool(false) +-- Iteration 124 -- +bool(true) +bool(false) +bool(true) +-- Iteration 125 -- +bool(true) +bool(false) +bool(true) +-- Iteration 126 -- +bool(true) +bool(true) +bool(true) +-- Iteration 127 -- +bool(false) +bool(false) +bool(false) +-- Iteration 128 -- +bool(false) +bool(false) +bool(false) +-- Iteration 129 -- +bool(false) +bool(false) +bool(false) +-- Iteration 130 -- +bool(false) +bool(false) +bool(false) +-- Iteration 131 -- +bool(false) +bool(false) +bool(false) +-- Iteration 132 -- +bool(false) +bool(false) +bool(false) +-- Iteration 133 -- +bool(false) +bool(false) +bool(false) +-- Iteration 134 -- +bool(false) +bool(false) +bool(false) +-- Iteration 135 -- +bool(false) +bool(false) +bool(false) +-- Iteration 136 -- +bool(false) +bool(false) +bool(false) +-- Iteration 137 -- +bool(false) +bool(false) +bool(false) +-- Iteration 138 -- +bool(false) +bool(false) +bool(false) +-- Iteration 139 -- +bool(false) +bool(false) +bool(false) +-- Iteration 140 -- +bool(false) +bool(false) +bool(false) +-- Iteration 141 -- +bool(false) +bool(false) +bool(false) +-- Iteration 142 -- +bool(true) +bool(false) +bool(true) +-- Iteration 143 -- +bool(true) +bool(false) +bool(true) +-- Iteration 144 -- +bool(false) +bool(false) +bool(false) +Done diff --git a/ext/standard/tests/array/in_array_variation2.phpt b/ext/standard/tests/array/in_array_variation2.phpt new file mode 100644 index 0000000000..d70da2d6ce --- /dev/null +++ b/ext/standard/tests/array/in_array_variation2.phpt @@ -0,0 +1,153 @@ +--TEST-- +Test in_array() function : usage variations - different haystack values +--FILE-- +'d', + 3, + ".001" =>-67, + "-.051" =>"k", + 0.091 =>"-.08", + "e" =>"5", + "y" =>NULL, + NULL =>"", + 0, + TRUE, + FALSE, + -27.39999999999, + " ", + "abcd\x00abcd\x00\abcd\x00abcdefghij", + "abcd\nabcd\tabcd\rabcd\0abcd" +); +$array_type = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "PHP", ""); +/* loop to do loose and strict type check of elements in + $array_type on elements in $misc_array using in_array(); + checking PHP type comparison tables +*/ +$counter = 1; +foreach($array_type as $type) { + echo "-- Iteration $counter --\n"; + //loose type checking + var_dump( in_array($type,$misc_array ) ); + //strict type checking + var_dump( in_array($type,$misc_array,true) ); + //loose type checking + var_dump( in_array($type,$misc_array,false) ); + $counter++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing in_array() with different haystack values *** +-- Iteration 1 -- +bool(true) +bool(true) +bool(true) +-- Iteration 2 -- +bool(true) +bool(true) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +-- Iteration 5 -- +bool(true) +bool(false) +bool(true) +-- Iteration 6 -- +bool(true) +bool(false) +bool(true) +-- Iteration 7 -- +bool(true) +bool(false) +bool(true) +-- Iteration 8 -- +bool(true) +bool(false) +bool(true) +-- Iteration 9 -- +bool(true) +bool(true) +bool(true) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(true) +bool(true) +bool(true) +Done +--UEXPECTF-- +*** Testing in_array() with different haystack values *** +-- Iteration 1 -- +bool(true) +bool(true) +bool(true) +-- Iteration 2 -- +bool(true) +bool(true) +bool(true) +-- Iteration 3 -- +bool(true) +bool(false) +bool(true) +-- Iteration 4 -- +bool(true) +bool(true) +bool(true) +-- Iteration 5 -- +bool(true) +bool(false) +bool(true) +-- Iteration 6 -- +bool(true) +bool(false) +bool(true) +-- Iteration 7 -- +bool(true) +bool(false) +bool(true) +-- Iteration 8 -- +bool(true) +bool(false) +bool(true) +-- Iteration 9 -- +bool(true) +bool(true) +bool(true) +-- Iteration 10 -- +bool(true) +bool(false) +bool(true) +-- Iteration 11 -- +bool(true) +bool(false) +bool(true) +-- Iteration 12 -- +bool(true) +bool(true) +bool(true) +Done diff --git a/ext/standard/tests/array/in_array_variation3.phpt b/ext/standard/tests/array/in_array_variation3.phpt new file mode 100644 index 0000000000..7e56c52717 --- /dev/null +++ b/ext/standard/tests/array/in_array_variation3.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test in_array() function : usage variations - haystack as sub-array/object +--FILE-- + "two", "three" => 3), + 4 => "four", + "five" => 5, + array('', 'i') +); +var_dump( in_array("four", $sub_array) ); +//checking for element in a sub-array +var_dump( in_array(3, $sub_array[1]) ); +var_dump( in_array(array('','i'), $sub_array) ); + +/* checking for objects in in_array() */ +echo "\n*** Testing objects with in_array() ***\n"; +class in_array_check { + public $array_var = array(1=>"one", "two"=>2, 3=>3); + public function foo() { + echo "Public function\n"; + } +} + +$in_array_obj = new in_array_check(); //creating new object +//error: as wrong datatype for second argument +var_dump( in_array("array_var", $in_array_obj) ); +//error: as wrong datatype for second argument +var_dump( in_array("foo", $in_array_obj) ); +//element found as "one" exists in array $array_var +var_dump( in_array("one", $in_array_obj->array_var) ); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing sub-arrays with in_array() *** +bool(true) +bool(true) +bool(true) + +*** Testing objects with in_array() *** + +Warning: in_array() expects parameter 2 to be array, object given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, object given in %s on line %d +NULL +bool(true) +Done +--UEXPECTF-- +*** Testing sub-arrays with in_array() *** +bool(true) +bool(true) +bool(true) + +*** Testing objects with in_array() *** + +Warning: in_array() expects parameter 2 to be array, object given in %s on line %d +NULL + +Warning: in_array() expects parameter 2 to be array, object given in %s on line %d +NULL +bool(true) +Done diff --git a/ext/standard/tests/array/in_array_variation4.phpt b/ext/standard/tests/array/in_array_variation4.phpt new file mode 100644 index 0000000000..625ce6311a --- /dev/null +++ b/ext/standard/tests/array/in_array_variation4.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test in_array() function : usage variations - haystack as resource/multi dimentional array +--FILE-- + TRUE, "b"=> TRUE, + array("c"=> TRUE, "d"=>TRUE) + ) + ) + ); + +//matching string having integer in beginning, result:true in loose type check +var_dump( in_array('123abc', array(123)) ); +var_dump( in_array('123abc', array(123), TRUE) ); // false in strict mode + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing resource type with in_array() *** +bool(true) +bool(false) + +*** Testing miscelleneos inputs with in_array() *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) +Done +--UEXPECTF-- +*** Testing resource type with in_array() *** +bool(true) +bool(false) + +*** Testing miscelleneos inputs with in_array() *** +bool(true) +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) +Done