2 Test is_string() function
5 /* Prototype: bool is_string ( mixed $var );
6 * Description: Finds whether the given variable is a string
9 echo "*** Testing is_string() with valid string values ***\n";
10 // different valid strings
12 /* string created using Heredoc (<<<) */
13 $heredoc_string = <<<EOT
14 This is string defined
17 /* heredoc string with only numerics */
18 $heredoc_numeric_string = <<<EOT
22 /* null heardoc string */
23 $heredoc_empty_string = <<<EOT
25 $heredoc_null_string = <<<EOT
49 $heredoc_numeric_string,
50 $heredoc_empty_string,
53 /* loop to check that is_string() recognizes different
54 strings, expected output bool(true) */
56 foreach ($strings as $string ) {
57 echo "-- Iteration $loop_counter --\n"; $loop_counter++;
58 var_dump( is_string($string) );
61 echo "\n*** Testing is_string() on non string values ***\n";
63 // get a resource type variable
64 $fp = fopen (__FILE__, "r");
65 $dfp = opendir ( __DIR__ );
68 $unset_string1 = "string";
69 $unset_string2 = 'string';
70 $unset_heredoc = <<<EOT
71 this is heredoc string
74 unset($unset_string1, $unset_string2, $unset_heredoc);
76 // other types in a array
77 $not_strings = array (
98 10.0000000000000000005,
127 array(1 => "One", "two" => 2),
129 /* undefined and unset vars */
135 /* loop through the $not_strings to see working of
136 is_string() on non string types, expected output bool(false) */
138 foreach ($not_strings as $type ) {
139 echo "-- Iteration $loop_counter --\n"; $loop_counter++;
140 var_dump( is_string($type) );
145 // close the resources used
151 *** Testing is_string() with valid string values ***
197 *** Testing is_string() on non string values ***