PageRenderTime 26ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/general_functions/is_string.php

http://github.com/facebook/hiphop-php
PHP | 153 lines | 112 code | 17 blank | 24 comment | 0 complexity | f00e46b8a31107bcf5e7d0294417d96d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. /* Prototype: bool is_string ( mixed $var );
  3. * Description: Finds whether the given variable is a string
  4. */
  5. echo "*** Testing is_string() with valid string values ***\n";
  6. // different valid strings
  7. /* string created using Heredoc (<<<) */
  8. $heredoc_string = <<<EOT
  9. This is string defined
  10. using heredoc.
  11. EOT;
  12. /* heredoc string with only numerics */
  13. $heredoc_numeric_string = <<<EOT
  14. 123456 3993
  15. 4849 string
  16. EOT;
  17. /* null heardoc string */
  18. $heredoc_empty_string = <<<EOT
  19. EOT;
  20. $heredoc_null_string = <<<EOT
  21. NULL
  22. EOT;
  23. $strings = array(
  24. "",
  25. " ",
  26. '',
  27. ' ',
  28. "string",
  29. 'string',
  30. "NULL",
  31. 'null',
  32. "FALSE",
  33. 'true',
  34. "\x0b",
  35. "\0",
  36. '\0',
  37. '\060',
  38. "\070",
  39. "0x55F",
  40. "055",
  41. "@#$#$%%$^^$%^%^$^&",
  42. $heredoc_string,
  43. $heredoc_numeric_string,
  44. $heredoc_empty_string,
  45. $heredoc_null_string
  46. );
  47. /* loop to check that is_string() recognizes different
  48. strings, expected output bool(true) */
  49. $loop_counter = 1;
  50. foreach ($strings as $string ) {
  51. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  52. var_dump( is_string($string) );
  53. }
  54. echo "\n*** Testing is_string() on non string values ***\n";
  55. // get a resource type variable
  56. $fp = fopen (__FILE__, "r");
  57. $dfp = opendir ( dirname(__FILE__) );
  58. // unset vars
  59. $unset_string1 = "string";
  60. $unset_string2 = 'string';
  61. $unset_heredoc = <<<EOT
  62. this is heredoc string
  63. EOT;
  64. // unset the vars
  65. unset($unset_string1, $unset_string2, $unset_heredoc);
  66. // other types in a array
  67. $not_strings = array (
  68. /* integers */
  69. 0,
  70. 1,
  71. -1,
  72. -0,
  73. 543915,
  74. -5322,
  75. 0x0,
  76. 0x1,
  77. 0x55F,
  78. -0xCCF,
  79. 0123,
  80. -0654,
  81. 00,
  82. 01,
  83. /* floats */
  84. 0.0,
  85. 1.0,
  86. -1.0,
  87. 10.0000000000000000005,
  88. .5e6,
  89. -.5E7,
  90. .5E+8,
  91. -.5e+90,
  92. 1e5,
  93. -1e5,
  94. 1E5,
  95. -1E7,
  96. /* objects */
  97. new stdclass,
  98. /* resources */
  99. $fp,
  100. $dfp,
  101. /* arrays */
  102. array(),
  103. array(0),
  104. array(1),
  105. array(NULL),
  106. array(null),
  107. array("string"),
  108. array(true),
  109. array(TRUE),
  110. array(false),
  111. array(FALSE),
  112. array(1,2,3,4),
  113. array(1 => "One", "two" => 2),
  114. /* undefined and unset vars */
  115. @$unset_string1,
  116. @$unset_string2,
  117. @$unset_heredoc,
  118. @$undefined_var
  119. );
  120. /* loop through the $not_strings to see working of
  121. is_string() on non string types, expected output bool(false) */
  122. $loop_counter = 1;
  123. foreach ($not_strings as $type ) {
  124. echo "-- Iteration $loop_counter --\n"; $loop_counter++;
  125. var_dump( is_string($type) );
  126. }
  127. echo "\n*** Testing error conditions ***\n";
  128. //Zero argument
  129. var_dump( is_string() );
  130. //arguments more than expected
  131. var_dump( is_string("string", "test") );
  132. echo "Done\n";
  133. // close the resources used
  134. fclose($fp);
  135. closedir($dfp);
  136. ?>