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

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

http://github.com/facebook/hiphop-php
PHP | 87 lines | 43 code | 20 blank | 24 comment | 2 complexity | c5191f5d6968a2de245d294ab01aac97 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 'str'
  8. * and expected type for 'from' & 'to' arguments
  9. */
  10. echo "*** Testing strtr() function: with unexpected inputs for 'str' ***\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. // array with different values
  23. $strings = array (
  24. // integer values
  25. /*1*/ 0,
  26. 1,
  27. -2,
  28. // float values
  29. /*4*/ 10.5,
  30. -20.5,
  31. 10.1234567e10,
  32. // array values
  33. /*7*/ array(),
  34. array(0),
  35. array(1, 2),
  36. // boolean values
  37. /*10*/ true,
  38. false,
  39. TRUE,
  40. FALSE,
  41. // null vlaues
  42. /*14*/ NULL,
  43. null,
  44. // objects
  45. /*16*/ new sample(),
  46. // resource
  47. /*17*/ $file_handle,
  48. // undefined variable
  49. /*18*/ @$undefined_var,
  50. // unset variable
  51. /*19*/ @$unset_var
  52. );
  53. //defining 'from' argument
  54. $from = "012atm";
  55. //defining 'to' argument
  56. $to = "atm012";
  57. // loop through with each element of the $strings array to test strtr() function
  58. $count = 1;
  59. for($index = 0; $index < count($strings); $index++) {
  60. echo "-- Iteration $count --\n";
  61. $str = $strings[$index];
  62. var_dump( strtr($str, $from, $to) );
  63. $count ++;
  64. }
  65. fclose($file_handle); //closing the file handle
  66. ?>
  67. ===DONE===