note 126085 added to class.splqueue

From: Date: Tue, 18 May 2021 19:58:07 +0000
Subject: note 126085 added to class.splqueue
Groups: php.notes 
Request: Send a blank email to php-notes+get-216394@lists.php.net to get a copy of this message
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(). ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 188.146.102.227) ---- Manual Page -- https://php.net/manual/en/class.splqueue.php Edit -- https://main.php.net/note/edit/126085 Del: integrated -- https://main.php.net/note/delete/126085/integrated Del: useless -- https://main.php.net/note/delete/126085/useless Del: bad code -- https://main.php.net/note/delete/126085/bad+code Del: spam -- https://main.php.net/note/delete/126085/spam Del: non-english -- https://main.php.net/note/delete/126085/non-english Del: in docs -- https://main.php.net/note/delete/126085/in+docs Del: other reasons-- https://main.php.net/note/delete/126085 Reject -- https://main.php.net/note/reject/126085 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216394) next »