PageRenderTime 49ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/bad/ext/standard/tests/strings/strtr_variation7.php

http://github.com/facebook/hiphop-php
PHP | 87 lines | 43 code | 20 blank | 24 comment | 2 complexity | e0807c02e2ff29f76b11b9c9bfba752f 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 strtr(string $str, string $from[, string $to]);
  3. string strtr(string $str, array $replace_pairs);
  4. * Description: Translates characters in str using given translation tables
  5. * Source code: ext/standard/string.c
  6. */
  7. /* Test strtr() function: with unexpected inputs for 'to'
  8. * and expected types for 'str' & 'from' arguments
  9. */
  10. echo "*** Testing strtr() function: with unexpected inputs for 'to' ***\n";
  11. //get an unset variable
  12. $unset_var = 'string_val';
  13. unset($unset_var);
  14. //defining a class
  15. class sample {
  16. public function __toString() {
  17. return "sample object";
  18. }
  19. }
  20. //getting the resource
  21. $file_handle = fopen(__FILE__, "r");
  22. //defining 'str' argument
  23. $str = "012atm";
  24. //defining 'from' argument
  25. $from = "atm012";
  26. // array of values for 'to' argument
  27. $to_arr = array (
  28. // integer values
  29. /*1*/ 0,
  30. 1,
  31. -2,
  32. // float values
  33. /*4*/ 10.5,
  34. -20.5,
  35. 10.12345675e10,
  36. // array values
  37. /*7*/ array(),
  38. array(0),
  39. array(1, 2),
  40. // boolean values
  41. /*10*/ true,
  42. false,
  43. TRUE,
  44. FALSE,
  45. // null vlaues
  46. /*14*/ NULL,
  47. null,
  48. // objects
  49. /*16*/ new sample(),
  50. // resource
  51. /*17*/ $file_handle,
  52. // undefined variable
  53. /*18*/ @$undefined_var,
  54. // unset variable
  55. /*19*/ @$unset_var
  56. );
  57. // loop through with each element of the $to array to test strtr() function
  58. $count = 1;
  59. for($index = 0; $index < count($to_arr); $index++) {
  60. echo "\n-- Iteration $count --\n";
  61. $to = $to_arr[$index];
  62. var_dump( strtr($str, $from, $to) );
  63. $count ++;
  64. }
  65. fclose($file_handle); //closing the file handle
  66. ?>
  67. ===DONE===