Bug #75673 [Opn->Csd]: SplStack::unserialize() behavior

From: Date: Fri, 06 Mar 2020 08:12:40 +0000
Subject: Bug #75673 [Opn->Csd]: SplStack::unserialize() behavior
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225917@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 Updated by: cmb@php.net Reported by: wolfsoft at mail dot ru Summary: SplStack::unserialize() behavior -Status: Open +Status: Closed Type: Bug Package: SPL related Operating System: Linux PHP Version: 7.0.26 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2020-03-05 14:01:27] 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-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 (#225917) next »