1--TEST-- 2Test count_chars() function : usage variations - test values for $mode argument 3--SKIPIF-- 4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64-bit only"); 5--FILE-- 6<?php 7 8/* Prototype : mixed count_chars ( string $string [, int $mode ] ) 9 * Description: Return information about characters used in a string 10 * Source code: ext/standard/string.c 11*/ 12 13echo "*** Testing count_chars() function: with unexpected inputs for 'mode' argument ***\n"; 14 15//get an unset variable 16$unset_var = 'string_val'; 17unset($unset_var); 18 19//defining a class 20class sample { 21} 22 23// array with different values for $input 24$inputs = array ( 25 26 // integer values 27/* 1 */ 0, 28 1, 29 255, 30 2147483647, 31 -2147483648, 32 33 // float values 34/* 6 */ 0.0, 35 1.3, 36 10.5, 37 -20.5, 38 10.1234567e10, 39 40 // array values 41/* 11 */ array(), 42 array(1, 2, 3, 4, 5, 6, 7, 8, 9), 43 44 // boolean values 45/* 14 */ true, 46 false, 47 TRUE, 48 FALSE, 49 50 // null values 51/* 18 */ NULL, 52 null, 53 54 // string values 55/* 20 */ "ABCD", 56 'abcd', 57 "1ABC", 58 "5ABC", 59 60 // objects 61/* 24 */ new sample(), 62 63 // undefined variable 64/* 25 */ @$undefined_var, 65 66 // unset variable 67/* 26 */ @$unset_var 68); 69 70// loop through with each element of the $inputs array to test count_chars() function 71// with unexepcted values for the 'mode' argument 72$count = 1; 73$string = "Return information about characters used in a string"; 74foreach($inputs as $input) { 75 echo "-- Iteration $count --\n"; 76 // only list characters with a frequency > 0 77 var_dump(is_array(count_chars($string, $input))); 78 $count ++; 79} 80 81 82?> 83===DONE=== 84--EXPECTF-- 85*** Testing count_chars() function: with unexpected inputs for 'mode' argument *** 86-- Iteration 1 -- 87bool(true) 88-- Iteration 2 -- 89bool(true) 90-- Iteration 3 -- 91 92Warning: count_chars(): Unknown mode in %s on line %d 93bool(false) 94-- Iteration 4 -- 95 96Warning: count_chars(): Unknown mode in %s on line %d 97bool(false) 98-- Iteration 5 -- 99 100Warning: count_chars(): Unknown mode in %s on line %d 101bool(false) 102-- Iteration 6 -- 103bool(true) 104-- Iteration 7 -- 105bool(true) 106-- Iteration 8 -- 107 108Warning: count_chars(): Unknown mode in %s on line %d 109bool(false) 110-- Iteration 9 -- 111 112Warning: count_chars(): Unknown mode in %s on line %d 113bool(false) 114-- Iteration 10 -- 115 116Warning: count_chars(): Unknown mode in %s on line %d 117bool(false) 118-- Iteration 11 -- 119 120Warning: count_chars() expects parameter 2 to be integer, array given in %s on line %d 121bool(false) 122-- Iteration 12 -- 123 124Warning: count_chars() expects parameter 2 to be integer, array given in %s on line %d 125bool(false) 126-- Iteration 13 -- 127bool(true) 128-- Iteration 14 -- 129bool(true) 130-- Iteration 15 -- 131bool(true) 132-- Iteration 16 -- 133bool(true) 134-- Iteration 17 -- 135bool(true) 136-- Iteration 18 -- 137bool(true) 138-- Iteration 19 -- 139 140Warning: count_chars() expects parameter 2 to be integer, string given in %s on line %d 141bool(false) 142-- Iteration 20 -- 143 144Warning: count_chars() expects parameter 2 to be integer, string given in %s on line %d 145bool(false) 146-- Iteration 21 -- 147 148Notice: A non well formed numeric value encountered in %s on line %d 149bool(true) 150-- Iteration 22 -- 151 152Notice: A non well formed numeric value encountered in %s on line %d 153 154Warning: count_chars(): Unknown mode in %s on line %d 155bool(false) 156-- Iteration 23 -- 157 158Warning: count_chars() expects parameter 2 to be integer, object given in %s on line %d 159bool(false) 160-- Iteration 24 -- 161bool(true) 162-- Iteration 25 -- 163bool(true) 164===DONE=== 165