I am implementing a SplPriorityQueue within this class. The class contains methods to essentially put PDOStatement objects along with the correct priority. I then have a method that executes all PDOStatement objects in the queue.
When testing this class, I have pushed one PDOStatement object into the queue and then I print the results from $this->queries_to_run->extract()
. Upon doing this I get my expected result, but also a RuntimeExeption
with the message "Can't extract from an empty heap." I am aware that the SplPriorityQueue is essentially a heap under the hood, but I do not know why I am getting both my expected result and the exception.
Here is the subset of the bothersome PHP code (I have the extract flags set to 'both' upon initialization of the PriorityQueue):
$top = $this->queries_to_run->top();
//print_r($top); // Debug
while($top['priority'] === self::$UPDATE_PRIORITY || $top['priority'] === self::$REMOVAL_PRIORITY) {
print("This is the extracted node
"); // Debug
print_r($this->queries_to_run->extract()); // Debug
}
This is my output:
This is the extracted node Array ( [data] => PDOStatement Object ( [queryString] => [--omitted--] ) [priority] => 4 ) This is the extracted node
Fatal error: Uncaught exception 'RuntimeException' with message 'Can't extract from an empty heap' in ... on line 943
I hope I have provided enough information. I am a student, so I hope this problem isn't extremely obvious