PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/spl/tests/class_uses_variation2.php

http://github.com/facebook/hiphop-php
PHP | 113 lines | 63 code | 25 blank | 25 comment | 2 complexity | 0013a3f9b4783e64c5cda5fecb50869f 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 : array class_uses(mixed what [, bool autoload ])
  3. * Description: Return all traits used by a class
  4. * Source code: ext/spl/php_spl.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing class_uses() : variation ***\n";
  8. trait foo {}
  9. class fooUser { use foo; }
  10. // Define error handler
  11. function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
  12. if (error_reporting() != 0) {
  13. // report non-silenced errors
  14. echo "Error: $err_no - $err_msg, $filename($linenum)\n";
  15. }
  16. }
  17. set_error_handler('test_error_handler');
  18. // Initialise function arguments not being substituted (if any)
  19. $class = 'fooUser';
  20. //resource
  21. $res = fopen(__FILE__,'r');
  22. //get an unset variable
  23. $unset_var = 10;
  24. unset ($unset_var);
  25. // define some classes
  26. class classWithToString
  27. {
  28. public function __toString() {
  29. return "Class A object";
  30. }
  31. }
  32. class classWithoutToString
  33. {
  34. }
  35. // heredoc string
  36. $heredoc = <<<EOT
  37. hello world
  38. EOT;
  39. // add arrays
  40. $index_array = array (1, 2, 3);
  41. $assoc_array = array ('one' => 1, 'two' => 2);
  42. //array of values to iterate over
  43. $inputs = array(
  44. // int data
  45. 'int 0' => 0,
  46. 'int 1' => 1,
  47. 'int 12345' => 12345,
  48. 'int -12345' => -2345,
  49. // float data
  50. 'float 10.5' => 10.5,
  51. 'float -10.5' => -10.5,
  52. 'float 12.3456789000e10' => 12.3456789000e10,
  53. 'float -12.3456789000e10' => -12.3456789000e10,
  54. 'float .5' => .5,
  55. // array data
  56. 'empty array' => array(),
  57. 'int indexed array' => $index_array,
  58. 'associative array' => $assoc_array,
  59. 'nested arrays' => array('foo', $index_array, $assoc_array),
  60. // null data
  61. 'uppercase NULL' => NULL,
  62. 'lowercase null' => null,
  63. // boolean data
  64. 'lowercase true' => true,
  65. 'lowercase false' =>false,
  66. 'uppercase TRUE' =>TRUE,
  67. 'uppercase FALSE' =>FALSE,
  68. // empty data
  69. 'empty string DQ' => "",
  70. 'empty string SQ' => '',
  71. // object data
  72. 'instance of classWithToString' => new classWithToString(),
  73. 'instance of classWithoutToString' => new classWithoutToString(),
  74. // undefined data
  75. 'undefined var' => @$undefined_var,
  76. // unset data
  77. 'unset var' => @$unset_var,
  78. //resource
  79. 'resource' => $res,
  80. );
  81. // loop through each element of the array for pattern
  82. foreach($inputs as $key =>$value) {
  83. echo "\n--$key--\n";
  84. var_dump( class_uses($class, $value) );
  85. };
  86. fclose($res);
  87. ?>
  88. ===DONE===