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

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

http://github.com/facebook/hiphop-php
PHP | 115 lines | 67 code | 24 blank | 24 comment | 2 complexity | 5f08de5c5a897adaa440c6f12533279f 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 : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]])
  3. * Description: Read the entire file into a string
  4. * Source code: ext/standard/file.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing file_get_contents() : 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 (if any)
  17. $filename = 'FileGetContentsVar5.tmp';
  18. $absFile = dirname(__FILE__).'/'.$filename;
  19. $h = fopen($absFile,"w");
  20. fwrite($h, b"contents read");
  21. fclose($h);
  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. // string data
  72. 'string DQ' => "string",
  73. 'string SQ' => 'string',
  74. 'mixed case string' => "sTrInG",
  75. 'heredoc' => $heredoc,
  76. // object data
  77. 'instance of classWithToString' => new classWithToString(),
  78. 'instance of classWithoutToString' => new classWithoutToString(),
  79. // undefined data
  80. 'undefined var' => @$undefined_var,
  81. // unset data
  82. 'unset var' => @$unset_var,
  83. );
  84. // loop through each element of the array for offset
  85. foreach($inputs as $key =>$value) {
  86. echo "\n--$key--\n";
  87. var_dump( file_get_contents($absFile, false, null, $value) );
  88. };
  89. unlink($absFile);
  90. ?>
  91. ===DONE===