php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72063 SplQueue and SplStack outputs the same
Submitted: 2016-04-20 11:40 UTC Modified: 2016-04-20 20:34 UTC
From: zavalit at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.0.5 OS: Ubuntu 14.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zavalit at gmail dot com
New email:
PHP Version: OS:

 

 [2016-04-20 11:40 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-20 20:34 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-04-20 20:34 UTC] requinix@php.net
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).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 15:01:36 2025 UTC