current_variation2.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. --TEST--
  2. Test current() function : usage variations - arrays containing different data types
  3. --FILE--
  4. <?php
  5. /*
  6. * Pass arrays of different data types as $array_arg to current() to test behaviour
  7. */
  8. echo "*** Testing current() : usage variations ***\n";
  9. //get an unset variable
  10. $unset_var = 10;
  11. unset ($unset_var);
  12. // get a class
  13. class classA
  14. {
  15. public function __toString() {
  16. return "Class A object";
  17. }
  18. }
  19. // heredoc string
  20. $heredoc = <<<EOT
  21. hello world
  22. EOT;
  23. // get a resource variable
  24. $fp = fopen(__FILE__, "r");
  25. // arrays of different data types to be passed to $array_arg argument
  26. $inputs = array(
  27. // int data
  28. /*1*/ 'int' => array(
  29. 0,
  30. 1,
  31. 12345,
  32. -2345,
  33. ),
  34. // float data
  35. /*2*/ 'float' => array(
  36. 10.5,
  37. -10.5,
  38. 12.3456789000e10,
  39. 12.3456789000E-10,
  40. .5,
  41. ),
  42. // null data
  43. /*3*/ 'null' => array(
  44. NULL,
  45. null,
  46. ),
  47. // boolean data
  48. /*4*/ 'bool' => array(
  49. true,
  50. false,
  51. TRUE,
  52. FALSE,
  53. ),
  54. // empty data
  55. /*5*/ 'empty string' => array(
  56. "",
  57. '',
  58. ),
  59. /*6*/ 'empty array' => array(
  60. ),
  61. // string data
  62. /*7*/ 'string' => array(
  63. "string",
  64. 'string',
  65. $heredoc,
  66. ),
  67. // object data
  68. /*8*/ 'object' => array(
  69. new classA(),
  70. ),
  71. // undefined data
  72. /*9*/ 'undefined' => array(
  73. @$undefined_var,
  74. ),
  75. // unset data
  76. /*10*/ 'unset' => array(
  77. @$unset_var,
  78. ),
  79. // resource variable
  80. /*11*/ 'resource' => array(
  81. $fp
  82. ),
  83. );
  84. // loop through each element of $inputs to check the behavior of current()
  85. $iterator = 1;
  86. foreach($inputs as $key => $input) {
  87. echo "\n-- Iteration $iterator : $key data --\n";
  88. var_dump( current($input) );
  89. $iterator++;
  90. };
  91. fclose($fp);
  92. ?>
  93. --EXPECTF--
  94. *** Testing current() : usage variations ***
  95. -- Iteration 1 : int data --
  96. int(0)
  97. -- Iteration 2 : float data --
  98. float(10.5)
  99. -- Iteration 3 : null data --
  100. NULL
  101. -- Iteration 4 : bool data --
  102. bool(true)
  103. -- Iteration 5 : empty string data --
  104. string(0) ""
  105. -- Iteration 6 : empty array data --
  106. bool(false)
  107. -- Iteration 7 : string data --
  108. string(6) "string"
  109. -- Iteration 8 : object data --
  110. object(classA)#%d (0) {
  111. }
  112. -- Iteration 9 : undefined data --
  113. NULL
  114. -- Iteration 10 : unset data --
  115. NULL
  116. -- Iteration 11 : resource data --
  117. resource(%d) of type (stream)