zendframework / zend-stdlib

Stdlib component from Zend Framework
BSD 3-Clause "New" or "Revised" License
384 stars 76 forks source link

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

Closed azjezz closed 6 years ago

azjezz commented 6 years ago

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

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 commented 6 years ago

Thanks, @azjezz!