PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/zlib/tests/gzopen_variation3.php

http://github.com/facebook/hiphop-php
PHP | 115 lines | 66 code | 24 blank | 25 comment | 3 complexity | dac7aeb5c35fc360af2b2f867aad9cd4 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 : resource gzopen(string filename, string mode [, int use_include_path])
  3. * Description: Open a .gz-file and return a .gz-file pointer
  4. * Source code: ext/zlib/zlib.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing gzopen() : 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 = dirname(__FILE__)."/004.txt.gz";
  18. $mode = 'r';
  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. // get a resource variable
  37. $fp = fopen(__FILE__, "r");
  38. // add arrays
  39. $index_array = array (1, 2, 3);
  40. $assoc_array = array ('one' => 1, 'two' => 2);
  41. //array of values to iterate over
  42. $inputs = array(
  43. // float data
  44. 'float 10.5' => 10.5,
  45. 'float -10.5' => -10.5,
  46. 'float 12.3456789000e10' => 12.3456789000e10,
  47. 'float -12.3456789000e10' => -12.3456789000e10,
  48. 'float .5' => .5,
  49. // array data
  50. 'empty array' => array(),
  51. 'int indexed array' => $index_array,
  52. 'associative array' => $assoc_array,
  53. 'nested arrays' => array('foo', $index_array, $assoc_array),
  54. // null data
  55. 'uppercase NULL' => NULL,
  56. 'lowercase null' => null,
  57. // boolean data
  58. 'lowercase true' => true,
  59. 'lowercase false' =>false,
  60. 'uppercase TRUE' =>TRUE,
  61. 'uppercase FALSE' =>FALSE,
  62. // empty data
  63. 'empty string DQ' => "",
  64. 'empty string SQ' => '',
  65. // string data
  66. 'string DQ' => "string",
  67. 'string SQ' => 'string',
  68. 'mixed case string' => "sTrInG",
  69. 'heredoc' => $heredoc,
  70. // object data
  71. 'instance of classWithToString' => new classWithToString(),
  72. 'instance of classWithoutToString' => new classWithoutToString(),
  73. // undefined data
  74. 'undefined var' => @$undefined_var,
  75. // unset data
  76. 'unset var' => @$unset_var,
  77. // resource variable
  78. 'resource' => $fp
  79. );
  80. // loop through each element of the array for use_include_path
  81. foreach($inputs as $key =>$value) {
  82. echo "\n--$key--\n";
  83. $res = gzopen($filename, $mode, $value);
  84. var_dump($res);
  85. if ($res === true) {
  86. gzclose($res);
  87. }
  88. };
  89. fclose($fp);
  90. ?>
  91. ===DONE===