heap_009.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --TEST--
  2. SPL: SplHeap and friends, throw: An iterator cannot be used with foreach by reference
  3. --CREDITS--
  4. Thomas Koch <thomas@koch.ro>
  5. #Hackday Webtuesday 2008-05-24
  6. --FILE--
  7. <?php
  8. function testForException( $heap )
  9. {
  10. try
  11. {
  12. foreach( $heap as &$item );
  13. }
  14. catch( \Error $e )
  15. {
  16. echo $e->getMessage(),"\n";
  17. }
  18. }
  19. // 1. SplMinHeap empty
  20. $heap = new SplMinHeap;
  21. testForException( $heap );
  22. // 2. SplMinHeap non-empty
  23. $heap = new SplMinHeap;
  24. $heap->insert( 1 );
  25. testForException( $heap );
  26. // 3. SplMaxHeap empty
  27. $heap = new SplMaxHeap;
  28. testForException( $heap );
  29. // 4. SplMaxHeap non-empty
  30. $heap = new SplMaxHeap;
  31. $heap->insert( 1 );
  32. testForException( $heap );
  33. // 5. SplPriorityQueue empty
  34. $heap = new SplPriorityQueue;
  35. testForException( $heap );
  36. // 6. SplPriorityQueue non-empty
  37. $heap = new SplPriorityQueue;
  38. $heap->insert( 1, 2 );
  39. testForException( $heap );
  40. ?>
  41. --EXPECT--
  42. An iterator cannot be used with foreach by reference
  43. An iterator cannot be used with foreach by reference
  44. An iterator cannot be used with foreach by reference
  45. An iterator cannot be used with foreach by reference
  46. An iterator cannot be used with foreach by reference
  47. An iterator cannot be used with foreach by reference