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

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

http://github.com/facebook/hiphop-php
PHP | 112 lines | 65 code | 23 blank | 24 comment | 2 complexity | 22d890ba2d326c7de9d882a221ff4655 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, "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 .5' => .5,
  53. // array data
  54. 'empty array' => array(),
  55. 'int indexed array' => $index_array,
  56. 'associative array' => $assoc_array,
  57. 'nested arrays' => array('foo', $index_array, $assoc_array),
  58. // null data
  59. 'uppercase NULL' => NULL,
  60. 'lowercase null' => null,
  61. // boolean data
  62. 'lowercase true' => true,
  63. 'lowercase false' =>false,
  64. 'uppercase TRUE' =>TRUE,
  65. 'uppercase FALSE' =>FALSE,
  66. // empty data
  67. 'empty string DQ' => "",
  68. 'empty string SQ' => '',
  69. // string data
  70. 'string DQ' => "string",
  71. 'string SQ' => 'string',
  72. 'mixed case string' => "sTrInG",
  73. 'heredoc' => $heredoc,
  74. // object data
  75. 'instance of classWithToString' => new classWithToString(),
  76. 'instance of classWithoutToString' => new classWithoutToString(),
  77. // undefined data
  78. 'undefined var' => @$undefined_var,
  79. // unset data
  80. 'unset var' => @$unset_var,
  81. );
  82. // loop through each element of the array for maxlen
  83. foreach($inputs as $key =>$value) {
  84. echo "\n--$key--\n";
  85. var_dump( file_get_contents($absFile, false, null, 0, $value) );
  86. };
  87. unlink($absFile);
  88. ?>
  89. ===DONE===