PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/general_functions/var_export-locale.php

http://github.com/facebook/hiphop-php
PHP | 302 lines | 253 code | 22 blank | 27 comment | 7 complexity | 954a0e46640ceb063db81526b845cd51 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. setlocale(LC_ALL, "german", "de","de_DE","de_DE.ISO8859-1","de_DE.ISO_8859-1","de_DE.UTF-8");
  3. /* Prototype: mixed var_export( mixed expression [, bool return]);
  4. * Description: Returns the variable representation when the return parameter is used and evaluates to TRUE. Otherwise, this function will return NULL.
  5. */
  6. echo "*** Testing var_export() with integer values ***\n";
  7. // different integer vlaues
  8. $valid_ints = array(
  9. '0',
  10. '1',
  11. '-1',
  12. '-2147483648', // max negative integer value
  13. '-2147483647',
  14. 2147483647, // max positive integer value
  15. 2147483640,
  16. 0x123B, // integer as hexadecimal
  17. '0x12ab',
  18. '0Xfff',
  19. '0XFA',
  20. -0x80000000, // max negative integer as hexadecimal
  21. '0x7fffffff', // max postive integer as hexadecimal
  22. 0x7FFFFFFF, // max postive integer as hexadecimal
  23. '0123', // integer as octal
  24. 01912, // should be quivalent to octal 1
  25. -020000000000, // max negative integer as octal
  26. 017777777777, // max positive integer as octal
  27. );
  28. $counter = 1;
  29. /* Loop to check for above integer values with var_export() */
  30. echo "\n*** Output for integer values ***\n";
  31. foreach($valid_ints as $int_value) {
  32. echo "\nIteration ".$counter."\n";
  33. var_export( $int_value );
  34. echo "\n";
  35. var_export( $int_value, FALSE);
  36. echo "\n";
  37. var_dump( var_export( $int_value, TRUE) );
  38. echo "\n";
  39. $counter++;
  40. }
  41. echo "*** Testing var_export() with valid boolean values ***\n";
  42. // different valid boolean vlaues
  43. $valid_bool = array(
  44. 1,
  45. TRUE,
  46. true,
  47. 0,
  48. FALSE,
  49. false
  50. );
  51. $counter = 1;
  52. /* Loop to check for above boolean values with var_export() */
  53. echo "\n*** Output for boolean values ***\n";
  54. foreach($valid_bool as $bool_value) {
  55. echo "\nIteration ".$counter."\n";
  56. var_export( $bool_value );
  57. echo "\n";
  58. var_export( $bool_value, FALSE);
  59. echo "\n";
  60. var_dump( var_export( $bool_value, TRUE) );
  61. echo "\n";
  62. $counter++;
  63. }
  64. echo "*** Testing var_export() with valid float values ***\n";
  65. // different valid float vlaues
  66. $valid_floats = array(
  67. -2147483649, // float value
  68. 2147483648, // float value
  69. -0x80000001, // float value, beyond max negative int
  70. 0x800000001, // float value, beyond max positive int
  71. 020000000001, // float value, beyond max positive int
  72. -020000000001, // float value, beyond max negative int
  73. 0.0,
  74. -0.1,
  75. 10.0000000000000000005,
  76. 10.5e+5,
  77. 1e5,
  78. 1e-5,
  79. 1e+5,
  80. 1E5,
  81. 1E+5,
  82. 1E-5,
  83. .5e+7,
  84. .6e-19,
  85. .05E+44,
  86. .0034E-30
  87. );
  88. $counter = 1;
  89. /* Loop to check for above float values with var_export() */
  90. echo "\n*** Output for float values ***\n";
  91. foreach($valid_bool as $float_value) {
  92. echo "\nIteration ".$counter."\n";
  93. var_export( $float_value );
  94. echo "\n";
  95. var_export( $float_value, FALSE);
  96. echo "\n";
  97. var_dump( var_export( $float_value, TRUE) );
  98. echo "\n";
  99. $counter++;
  100. }
  101. echo "*** Testing var_export() with valid strings ***\n";
  102. // different valid string
  103. $valid_strings = array(
  104. "",
  105. " ",
  106. '',
  107. ' ',
  108. "string",
  109. 'string',
  110. "NULL",
  111. 'null',
  112. "FALSE",
  113. 'false',
  114. "\x0b",
  115. "\0",
  116. '\0',
  117. '\060',
  118. "\070"
  119. );
  120. $counter = 1;
  121. /* Loop to check for above strings with var_export() */
  122. echo "\n*** Output for strings ***\n";
  123. foreach($valid_strings as $str) {
  124. echo "\nIteration ".$counter."\n";
  125. var_export( $str );
  126. echo "\n";
  127. var_export( $str, FALSE);
  128. echo "\n";
  129. var_dump( var_export( $str, TRUE) );
  130. echo "\n";
  131. $counter++;
  132. }
  133. echo "*** Testing var_export() with valid arrays ***\n";
  134. // different valid arrays
  135. $valid_arrays = array(
  136. array(),
  137. array(NULL),
  138. array(null),
  139. array(true),
  140. array(""),
  141. array(''),
  142. array(array(), array()),
  143. array(array(1, 2), array('a', 'b')),
  144. array(1 => 'One'),
  145. array("test" => "is_array"),
  146. array(0),
  147. array(-1),
  148. array(10.5, 5.6),
  149. array("string", "test"),
  150. array('string', 'test')
  151. );
  152. $counter = 1;
  153. /* Loop to check for above arrays with var_export() */
  154. echo "\n*** Output for arrays ***\n";
  155. foreach($valid_arrays as $arr) {
  156. echo "\nIteration ".$counter."\n";
  157. var_export( $arr );
  158. echo "\n";
  159. var_export( $arr, FALSE);
  160. echo "\n";
  161. var_dump( var_export( $arr, TRUE) );
  162. echo "\n";
  163. $counter++;
  164. }
  165. echo "*** Testing var_export() with valid objects ***\n";
  166. // class with no members
  167. class foo
  168. {
  169. // no members
  170. }
  171. // abstract class
  172. abstract class abstractClass
  173. {
  174. abstract protected function getClassName();
  175. public function printClassName () {
  176. echo $this->getClassName() . "\n";
  177. }
  178. }
  179. // implement abstract class
  180. class concreteClass extends abstractClass
  181. {
  182. protected function getClassName() {
  183. return "concreteClass";
  184. }
  185. }
  186. // interface class
  187. interface iValue
  188. {
  189. public function setVal ($name, $val);
  190. public function dumpVal ();
  191. }
  192. // implement the interface
  193. class Value implements iValue
  194. {
  195. private $vars = array ();
  196. public function setVal ( $name, $val ) {
  197. $this->vars[$name] = $val;
  198. }
  199. public function dumpVal () {
  200. var_export ( $vars );
  201. }
  202. }
  203. // a gereral class
  204. class myClass
  205. {
  206. var $foo_object;
  207. public $public_var;
  208. public $public_var1;
  209. private $private_var;
  210. protected $protected_var;
  211. function myClass ( ) {
  212. $this->foo_object = new foo();
  213. $this->public_var = 10;
  214. $this->public_var1 = new foo();
  215. $this->private_var = new foo();
  216. $this->proected_var = new foo();
  217. }
  218. }
  219. // create a object of each class defined above
  220. $myClass_object = new myClass();
  221. $foo_object = new foo();
  222. $Value_object = new Value();
  223. $concreteClass_object = new concreteClass();
  224. $valid_objects = array(
  225. new stdclass,
  226. new foo,
  227. new concreteClass,
  228. new Value,
  229. new myClass,
  230. $myClass_object,
  231. $myClass_object->foo_object,
  232. $myClass_object->public_var1,
  233. $foo_object,
  234. $Value_object,
  235. $concreteClass_object
  236. );
  237. $counter = 1;
  238. /* Loop to check for above objects with var_export() */
  239. echo "\n*** Output for objects ***\n";
  240. foreach($valid_objects as $obj) {
  241. echo "\nIteration ".$counter."\n";
  242. var_export( $obj );
  243. echo "\n";
  244. var_export( $obj, FALSE);
  245. echo "\n";
  246. var_dump( var_export( $obj, TRUE) );
  247. echo "\n";
  248. $counter++;
  249. }
  250. echo "*** Testing var_export() with valid null values ***\n";
  251. // different valid null vlaues
  252. $unset_var = array();
  253. unset ($unset_var); // now a null
  254. $null_var = NULL;
  255. $valid_nulls = array(
  256. NULL,
  257. null,
  258. $null_var,
  259. );
  260. $counter = 1;
  261. /* Loop to check for above null values with var_export() */
  262. echo "\n*** Output for null values ***\n";
  263. foreach($valid_nulls as $null_value) {
  264. echo "\nIteration ".$counter."\n";
  265. var_export( $null_value );
  266. echo "\n";
  267. var_export( $null_value, FALSE);
  268. echo "\n";
  269. var_dump( var_export( $null_value, true) );
  270. echo "\n";
  271. $counter++;
  272. }
  273. echo "\n*** Testing error conditions ***\n";
  274. //Zero argument
  275. var_export( var_export() );
  276. //arguments more than expected
  277. var_export( var_export(TRUE, FALSE, TRUE) );
  278. echo "\n\nDone";
  279. ?>