Bug #75673 [PATCH]: SplStack::unserialize() behavior

From: Date: Thu, 05 Mar 2020 14:01:27 +0000
Subject: Bug #75673 [PATCH]: SplStack::unserialize() behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225910@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75673&edit=1 ID: 75673 Patch added by: cmb@php.net Reported by: wolfsoft at mail dot ru Summary: SplStack::unserialize() behavior Status: Open Type: Bug Package: SPL related Operating System: Linux PHP Version: 7.0.26 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2020-03-05 13:42:47] 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> ------------------------------------------------------------------------ [2017-12-13 00:57:21] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75673&edit=1

« previous php.bugs (#225910) next »