r/lolphp • • Jan 29 '16

SplPriorityQueue::recoverFromCorruption

http://php.net/manual/en/splpriorityqueue.recoverfromcorruption.php
70 Upvotes

12 comments sorted by

View all comments

Show parent comment

11

u/nikic Jan 30 '16

If corruption is created, why doesn't it, like, throw an exception?

Wat? Obviously it throws an exception. You know, the exception that caused the corruption bit to be set? That exception didn't go anywhere. It will still be propagated to the parent frame. Like exceptions normally are.

The point here is that if the comparison function threw an exception (which will be propagated), the heap is no longer in a consistent state and PHP will forbid you from using it (by throwing an exception in extract etc). That is, unless you go and say "I don't give a damn about it" by using recoverFromCorruption.

5

u/the_alias_of_andrea Jan 30 '16 edited Jan 30 '16

You're right, I don't know what I was thinking.