count_variation3.phpt 850 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Test count() function : usage variations - Infinitely recursive array
  3. --FILE--
  4. <?php
  5. /* Prototype : int count(mixed $var [, int $mode])
  6. * Description: Count the number of elements in a variable (usually an array)
  7. * Source code: ext/standard/array.c
  8. */
  9. /*
  10. * Pass count() an infinitely recursive array as $var argument
  11. * This will stop the script before it reaches the end.
  12. */
  13. echo "*** Testing count() : usage variations ***\n";
  14. $array1 = array (1, 2, 'three');
  15. // get an infinitely recursive array
  16. $array1[] = &$array1;
  17. echo "\n-- \$mode not set: --\n";
  18. var_dump(count ($array1));
  19. echo "\n-- \$mode = 1: --\n";
  20. var_dump(count ($array1, 1));
  21. echo "Done";
  22. ?>
  23. --EXPECTF--
  24. *** Testing count() : usage variations ***
  25. -- $mode not set: --
  26. int(4)
  27. -- $mode = 1: --
  28. Warning: count(): recursion detected in %s on line %d
  29. int(12)
  30. Done