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

/hphp/test/zend/bad/ext/standard/tests/general_functions/intval_variation1.php

http://github.com/facebook/hiphop-php
PHP | 108 lines | 62 code | 22 blank | 24 comment | 2 complexity | 8930321e5f041201ec8ec13f6bd2953b 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 intval(mixed var [, int base])
  3. * Description: Get the integer value of a variable using the optional base for the conversion
  4. * Source code: ext/standard/type.c
  5. * Alias to functions:
  6. */
  7. echo "*** Testing intval() : 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. $base = 10;
  18. //get an unset variable
  19. $unset_var = 10;
  20. unset ($unset_var);
  21. // define some classes
  22. class classWithToString
  23. {
  24. public function __toString() {
  25. return "Class A object";
  26. }
  27. }
  28. class classWithoutToString
  29. {
  30. }
  31. // heredoc string
  32. $heredoc = <<<EOT
  33. hello world
  34. EOT;
  35. // add arrays
  36. $index_array = array (1, 2, 3);
  37. $assoc_array = array ('one' => 1, 'two' => 2);
  38. //array of values to iterate over
  39. $inputs = array(
  40. // int data
  41. 'int 0' => 0,
  42. 'int 1' => 1,
  43. 'int 12345' => 12345,
  44. 'int -12345' => -2345,
  45. // float data
  46. 'float 10.5' => 10.5,
  47. 'float -10.5' => -10.5,
  48. 'float 12.3456789e5' => 12.3456789e5,
  49. 'float -12.3456789e5' => -12.3456789e5,
  50. 'float .5' => .5,
  51. // array data
  52. 'empty array' => array(),
  53. 'int indexed array' => $index_array,
  54. 'associative array' => $assoc_array,
  55. 'nested arrays' => array('foo', $index_array, $assoc_array),
  56. // null data
  57. 'uppercase NULL' => NULL,
  58. 'lowercase null' => null,
  59. // boolean data
  60. 'lowercase true' => true,
  61. 'lowercase false' =>false,
  62. 'uppercase TRUE' =>TRUE,
  63. 'uppercase FALSE' =>FALSE,
  64. // empty data
  65. 'empty string DQ' => "",
  66. 'empty string SQ' => '',
  67. // string data
  68. 'string DQ' => "string",
  69. 'string SQ' => 'string',
  70. 'mixed case string' => "sTrInG",
  71. 'heredoc' => $heredoc,
  72. // object data
  73. 'instance of classWithToString' => new classWithToString(),
  74. 'instance of classWithoutToString' => new classWithoutToString(),
  75. // undefined data
  76. 'undefined var' => @$undefined_var,
  77. // unset data
  78. 'unset var' => @$unset_var,
  79. );
  80. // loop through each element of the array for var
  81. foreach($inputs as $key =>$value) {
  82. echo "\n--$key--\n";
  83. var_dump( intval($value, $base) );
  84. };
  85. ?>
  86. ===DONE===