PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/facebook/hiphop-php
PHP | 81 lines | 43 code | 18 blank | 20 comment | 2 complexity | 5607056efbede767d2b862fa123a18d5 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', 'from', 'to' & 'replace_pairs' arguments */
  8. echo "*** Testing strtr() function: with unexpected inputs for all arguments ***\n";
  9. //get an unset variable
  10. $unset_var = 'string_val';
  11. unset($unset_var);
  12. //defining a class
  13. class sample {
  14. public function __toString() {
  15. return "sample object";
  16. }
  17. }
  18. //getting the resource
  19. $file_handle = fopen(__FILE__, "r");
  20. // array with different values
  21. $values = array (
  22. // integer values
  23. /*1*/ 0,
  24. 1,
  25. -2,
  26. // float values
  27. /*4*/ 10.5,
  28. -20.5,
  29. 10.1234567e10,
  30. // array values
  31. /*7*/ array(),
  32. array(0),
  33. array(1),
  34. array(1, 2),
  35. array('color' => 'red', 'item' => 'pen'),
  36. // boolean values
  37. /*12*/ true,
  38. false,
  39. TRUE,
  40. FALSE,
  41. // null vlaues
  42. /*16*/ NULL,
  43. null,
  44. // objects
  45. /*18*/ new sample(),
  46. // resource
  47. /*19*/ $file_handle,
  48. // undefined variable
  49. /*20*/ @$undefined_var,
  50. // unset variable
  51. /*21*/ @$unset_var
  52. );
  53. // loop through with each element of the $values array to test strtr() function
  54. $count = 1;
  55. for($index = 0; $index < count($values); $index++) {
  56. echo "\n-- Iteration $count --\n";
  57. var_dump( strtr($values[$index], $values[$index], $values[$index]) ); //fn call with three args
  58. var_dump( strtr($values[$index], $values[$index]) ); //fn call with two args
  59. $count ++;
  60. }
  61. fclose($file_handle); //closing the file handle
  62. ?>
  63. ===DONE===