--TEST-- strlen() function --INI-- precision = 12 --FILE-- <-;:$ []{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\ abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$ []{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\ abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$ []{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\\\\ abcdefghijklmnopqrstuvwxyz0123456789" ); /* loop through to find the length of each string */ for($i=0; $i "; var_dump( strlen($strings[$i]) ); } echo "\n#### Testing Miscelleneous inputs ####\n"; echo "--- Testing objects ---\n"; /* we get "Catchable fatal error: saying Object of class could not be converted to string" by default when an object is passed instead of string: The error can be avoided by choosing the __toString magix method as follows: */ class string { function __toString() { return "Hello, world"; } } $obj_string = new string; var_dump(strlen("$obj_string")); echo "\n--- Testing arrays ---\n"; $str_arr = array("hello", "?world", "!$%**()%**[][[[&@#~!", array()); var_dump(strlen($str_arr)); var_dump(strlen("$str_arr[1]")); var_dump(strlen("$str_arr[2]")); echo "\n--- Testing Resources ---\n"; $filename1 = "dummy.txt"; $file1 = fopen($filename1, "w"); // creating new file /* getting resource type for file handle */ $string1 = get_resource_type($file1); $string2 = (int)get_resource_type($file1); // converting stream type to int /* $string1 is of "stream" type */ var_dump(strlen($string1)); // int(6) /* $string2 holds a value of "int(0)" */ var_dump(strlen($string2)); // int(1) fclose($file1); // closing the file "dummy.txt" unlink("$filename1"); // deletes "dummy.txt" echo "\n--- Testing a longer and heredoc string ---\n"; $string = << --EXPECTF-- #### Basic operations and variations #### String length of 'Hello, World' is => int(12) String length of 'Hello, World' is => int(12) String length of '!!Hello, World' is => int(14) String length of '??Hello, World' is => int(14) String length of '$@#%^&*!~,.:;?' is => int(14) String length of '123' is => int(3) String length of '123' is => int(3) String length of '-1.2345' is => int(7) String length of '-1.2344' is => int(7) String length of '' is => int(0) String length of '' is => int(0) String length of ' ' is => int(1) String length of '' is => int(1) String length of '0' is => int(2) String length of '«C' is => int(2) String length of '0' is => int(2) String length of '0' is => int(1) String length of '0' is => int(1) String length of ' ' is => int(1) String length of '\t' is => int(2) String length of '1' is => int(1) String length of '' is => int(0) String length of 'Hello, World' is => int(13) String length of 'HelloWorld' is => int(11) String length of 'Hello, World\0' is => int(14) String length of 'Hello, World ' is => int(13) String length of 'Hello, World ' is => int(13) String length of 'Hello, World ' is => int(13) String length of 'Hello, World\' is => int(13) String length of ' ' is => int(14) String length of '€êAÿ' is => int(5) String length of 'abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$ []{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\ abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$ []{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\ abcdefghijklmnopqrstuvwxyz0123456789~!@#$%^&*()_+=|?><-;:$ []{}{{{}}}[[[[]][]]]***&&&^^%$###@@!!@#$%&^&**/////|\\\ abcdefghijklmnopqrstuvwxyz0123456789' is => int(495) #### Testing Miscelleneous inputs #### --- Testing objects --- int(12) --- Testing arrays --- Warning: strlen() expects parameter 1 to be string, array given in %s on line %d NULL int(6) int(20) --- Testing Resources --- int(6) int(1) --- Testing a longer and heredoc string --- int(639) --- Testing a heredoc null string --- int(0) --- Testing simple and complex syntax strings --- int(5) int(7) Notice: Undefined variable: strS in %s on line %d int(0) int(6) int(6) --- strlen for long float values --- int(13) int(12) --- Nested strlen() --- int(1) #### error conditions #### Warning: strlen() expects exactly 1 parameter, 0 given in %s on line %d Warning: strlen() expects exactly 1 parameter, 2 given in %s on line %d Warning: strlen() expects exactly 1 parameter, 2 given in %s on line %d Done