Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Fix SplPriorityQueue::$serial not being reset after serialization #92

Merged
merged 5 commits into from
Aug 28, 2018
Merged

Conversation

azjezz
Copy link
Contributor

@azjezz azjezz commented Aug 25, 2018

Provide a narrative description of what you are trying to accomplish:

  • Are you fixing a bug?
    • Detail how the bug is invoked currently.
    • Detail the original, incorrect behavior.
    • Detail the new, expected behavior.
    • Base your feature on the master branch, and submit against that branch.
    • Add a regression test that demonstrates the bug, and proves the fix.
    • Add a CHANGELOG.md entry for the fix.

The current SplPriorityQueue doesn't reset the serial property after serialization which makes it not equal to the original PriorityQueue.

<?php
    use Zend\Stdlib\SplPriorityQueue as Queue;

    $queue = new Queue();
    $queue->insert('foo', 3);
    $queue->insert('bar', 4);
    $queue->insert('baz', 2);
    $queue->insert('bat', 1);
   
    $serialized = serialize($queue);
    $unserialized = unserialize($serialized);

    $serial = new ReflectionProperty(Queue::class, 'serial');
    $serial->setAccessible(true);

    if ($serial->getValue($queue) === $serial->getValue($unserialized)) {
       print 'cool !';
    } else {
       print 'oh ?';
    }
    

original, incorrect behavior :
prints oh ?
new, correct behavior :
prints cool !

@weierophinney weierophinney merged commit 7035b4e into zendframework:master Aug 28, 2018
weierophinney added a commit that referenced this pull request Aug 28, 2018
Fix SplPriorityQueue::$serial not being reset after serialization

Conflicts:
	CHANGELOG.md
weierophinney added a commit that referenced this pull request Aug 28, 2018
weierophinney added a commit that referenced this pull request Aug 28, 2018
@weierophinney
Copy link
Member

Thanks, @azjezz!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants