Bug #72063 [Opn->Nab]: SplQueue and SplStack outputs the same

From: Date: Wed, 20 Apr 2016 20:34:40 +0000
Subject: Bug #72063 [Opn->Nab]: SplQueue and SplStack outputs the same
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200669@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72063&edit=1 ID: 72063 Updated by: requinix@php.net Reported by: zavalit at gmail dot com Summary: SplQueue and SplStack outputs the same -Status: Open +Status: Not a bug Type: Bug Package: *General Issues Operating System: Ubuntu 14.04 PHP Version: 7.0.5 Block user comment: N Private report: N New Comment: That's right: both classes implement the push/pop/shift/unshift methods (by inheritance from SplDoublyLinkedList) while only SplQueue implements enqueue and dequeue. If you want a stack then use SplStack and push/pop (or shift/unshift). If you want to use a queue then use SplQueue and enqueue/dequeue (or push/shift or pop/unshift). Previous Comments: ------------------------------------------------------------------------ [2016-04-20 11:40:41] zavalit at gmail dot com Description: ------------ class MyStorage extends SplStack{} $closure = function($elem){ $this->push($elem); return $this; }; $stack = $closure->call(new MyStorage(), 1); $stack = $closure->call($stack, 2); echo $stack->pop(); // return 2 ------------------------------------ ------------------------------------ class MyStorage extends SplQueue{} $closure = function($elem){ $this->push($elem); return $this; }; $stack = $closure->call(new MyStorage(), 1); $stack = $closure->call($stack, 2); echo $stack->pop(); // return 2 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72063&edit=1

« previous php.bugs (#200669) next »