Answer to Manu Manjunath post (#114336).
IMO, pop() works as expected.
There are 2 main groups of methods:
1) pop() & push() are inherited from SplDoublyLinkedList and can be applied to SplStack as well as SplQueue (ie are "faceless"). It isn't about stack or queue; it's just about deleting / adding element to the end of the list;
2) the same situation with shift() & unshift(): it is just about adding an element to the beginning of the list, and doesn't matter, if we use it on SplStack or SplQueue.
So, yes, $q->pop(); will remove *last* element from SplQueue $q.
But enqueue() & dequeue() *are about* SplQueue. FIFO principle is realized by these methods, which were implemented *exactly* for queue purpose:
- enqueue() adds an element to the end of the queue and is alias for "faceless" push() (FI...);
- dequeue() removes element from the beginning of the queue and is alias for "faceless" shift() (...FO).
If you want to delete *next in line* element from *queue*, use dequeue().
If you want to delete *last* element from the list (doesn't matter, if it's queue or stack), use pop().