php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75673 SplStack::unserialize() behavior
Submitted: 2017-12-13 00:57 UTC Modified: 2020-03-06 08:13 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: wolfsoft at mail dot ru Assigned: cmb (profile)
Status: Closed Package: SPL related
PHP Version: 7.0.26 OS: Linux
Private report: No CVE-ID: None
 [2017-12-13 00:57 UTC] wolfsoft at mail dot ru
Description:
------------
The SplStack::unserialize() method adds elements to current object from serialized one instead of replacing

Test script:
---------------
<?php

$stack = new SplStack();
$stack->push("one");
$stack->push("two");

$serialized = $stack->serialize();
echo $stack->count(), "\n";
$stack->unserialize($serialized);
echo $stack->count(), "\n";
$stack->unserialize($serialized);
echo $stack->count(), "\n";


Expected result:
----------------
2
2
2

Actual result:
--------------
2
4
6

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-18 12:22 UTC] cmb@php.net
-Package: SPL_Types +Package: SPL related
 [2020-03-05 13:42 UTC] cmb@php.net
Indeed, it still behaves that way: <https://3v4l.org/liV5Z>.

However, these methods are inherited from SplDoublyLinkedList, and
actually implement the Serializable interface (the documentation
has just been fixed in this regard[1]), and as such unserialize()
is not supposed to be called on an already constructed instance.

Usually, you do something like

<?php
$stack = new SplStack();
$stack->push("one");
$stack->push("two");

$serialized = serialize($stack);
var_dump(unserialize($serialized));
?>

Still, something that might be improveable.

[1] <http://svn.php.net/viewvc?view=revision&revision=349321>
 [2020-03-05 14:01 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #75673: SplStack::unserialize() behavior
On GitHub:  https://github.com/php/php-src/pull/5238
Patch:      https://github.com/php/php-src/pull/5238.patch
 [2020-03-06 08:12 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b84277297ae18f11055a5731a881a347df8d76b9
Log: Fix #75673: SplStack::unserialize() behavior
 [2020-03-06 08:12 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2020-03-06 08:13 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC