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

/hphp/test/zend/good/ext/standard/tests/strings/strtr_variation8.php

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