PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/hphp/test/zend/bad/ext/standard/tests/file/file_variation2.php

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