PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 107 lines | 62 code | 22 blank | 23 comment | 2 complexity | 0b0a34a1f1bd9288fcbee98e64f038a5 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 parse_ini_file(string filename [, bool process_sections])
  3. * Description: Parse configuration file
  4. * Source code: ext/standard/basic_functions.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing parse_ini_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 (if any)
  17. $filename = __FILE__."ParseIniFileVar5.ini";
  18. $contents = "a=test";
  19. @unlink($filename);
  20. file_put_contents($filename, $contents);
  21. //get an unset variable
  22. $unset_var = 10;
  23. unset ($unset_var);
  24. // define some classes
  25. class classWithToString
  26. {
  27. public function __toString() {
  28. return "Class A object";
  29. }
  30. }
  31. class classWithoutToString
  32. {
  33. }
  34. // heredoc string
  35. $heredoc = <<<EOT
  36. hello world
  37. EOT;
  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. // int data
  44. 'int 0' => 0,
  45. 'int 1' => 1,
  46. 'int 12345' => 12345,
  47. 'int -12345' => -2345,
  48. // float data
  49. 'float 10.5' => 10.5,
  50. 'float -10.5' => -10.5,
  51. 'float 12.3456789000e10' => 12.3456789000e10,
  52. 'float -12.3456789000e10' => -12.3456789000e10,
  53. 'float .5' => .5,
  54. // array data
  55. 'empty array' => array(),
  56. 'int indexed array' => $index_array,
  57. 'associative array' => $assoc_array,
  58. 'nested arrays' => array('foo', $index_array, $assoc_array),
  59. // null data
  60. 'uppercase NULL' => NULL,
  61. 'lowercase null' => null,
  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. );
  78. // loop through each element of the array for process_sections
  79. foreach($inputs as $key =>$value) {
  80. echo "\n--$key--\n";
  81. var_dump( parse_ini_file($filename, $value) );
  82. };
  83. unlink($filename);
  84. ?>
  85. ===DONE===