array_shift_variation5.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. Test array_shift() function : usage variations - call recursively
  3. --FILE--
  4. <?php
  5. /* Prototype : mixed array_shift(array &$stack)
  6. * Description: Pops an element off the beginning of the array
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Use the result of one call to array_shift
  11. * as the $stack argument of another call to array_shift()
  12. * When done in one statement causes strict error messages.
  13. */
  14. echo "*** Testing array_shift() : usage variations ***\n";
  15. $stack = array ( array ( array ('zero', 'one', 'two'), 'un', 'deux'), 'eins', 'zwei');
  16. // not following strict standards
  17. echo "\n-- Incorrect Method: --\n";
  18. var_dump(array_shift(array_shift(array_shift($stack))));
  19. $stack = array (array( array('zero', 'one', 'two'), 'un', 'deux'), 'eins', 'zwei');
  20. // correct way of doing above:
  21. echo "\n-- Correct Method: --\n";
  22. $result1 = array_shift($stack);
  23. $result2 = array_shift($result1);
  24. var_dump(array_shift($result2));
  25. echo "Done";
  26. ?>
  27. --EXPECTF--
  28. *** Testing array_shift() : usage variations ***
  29. -- Incorrect Method: --
  30. Strict Standards: Only variables should be passed by reference in %s on line %d
  31. Strict Standards: Only variables should be passed by reference in %s on line %d
  32. string(4) "zero"
  33. -- Correct Method: --
  34. string(4) "zero"
  35. Done