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

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

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