spl_heap_count_basic.phpt 782 B

1234567891011121314151617181920212223242526272829303132333435
  1. --TEST--
  2. SPL: SplHeap, Test spl_heap_object_count_elements (spl_heap.c:490) for returning count() failure for Heaps
  3. --CREDITS--
  4. Chris Scott chris.scott@nstein.com
  5. #testfest London 2009-05-09
  6. --FILE--
  7. <?php
  8. class MyHeap extends SplHeap
  9. {
  10. public function compare($a,$b)
  11. {
  12. return ($a < $b);
  13. }
  14. public function count() // override count to force failure
  15. {
  16. throw new Exception('Cause count to fail');
  17. return parent::count();
  18. }
  19. }
  20. $heap = new MyHeap();
  21. $heap->insert(1);
  22. count($heap);// refers to MyHeap->count() method
  23. ?>
  24. --EXPECTF--
  25. Fatal error: Uncaught exception 'Exception' with message 'Cause count to fail' in %s
  26. Stack trace:
  27. #0 [internal function]: MyHeap->count()
  28. #1 %s count(Object(MyHeap))
  29. #2 {main}
  30. thrown in %s on line %d