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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 14:01:35 2024 UTC