current_variation2.phpt 2.6 KB

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