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

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

http://github.com/facebook/hiphop-php
PHP | 123 lines | 70 code | 27 blank | 26 comment | 2 complexity | 3a908184abfab77c341307a6fd8cae64 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 : int file_put_contents(string file, mixed data [, int flags [, resource context]])
  3. * Description: Write/Create a file with contents data and return the number of bytes written
  4. * Source code: ext/standard/file.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing file_put_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 = 'FilePutContentsVar4.tmp';
  18. $absFile = dirname(__FILE__).'/'.$filename;
  19. $fileRes = fopen(__FILE__,'r');
  20. $strContext = stream_context_create();
  21. $data = "data to write";
  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. //non context resource
  84. 'file resource' => $fileRes,
  85. //valid stream context
  86. 'stream context' => $strContext,
  87. );
  88. // loop through each element of the array for context
  89. foreach($inputs as $key =>$value) {
  90. echo "\n--$key--\n";
  91. var_dump( file_put_contents($absFile, $data, null, $value) );
  92. };
  93. unlink($absFile);
  94. fclose($fileRes);
  95. ?>
  96. ===DONE===