bug #26999 [VarDumper] Fix dumping of SplObjectStorage (corphi)

This PR was squashed before being merged into the 2.7 branch (closes #26999).

Discussion
----------

[VarDumper] Fix dumping of SplObjectStorage

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This is a bug fix for dumping instances of `SplObjectStorage`. The bug was introduced in #23176, by fixing that the internal pointer was changed upon dumping. I added tests for both issues.

Commits
-------

b2ac6b6fbf [VarDumper] Fix dumping of SplObjectStorage
This commit is contained in:
Fabien Potencier 2018-04-22 07:46:01 +02:00
commit 3d44c7f982
2 changed files with 22 additions and 2 deletions

View File

@ -86,10 +86,11 @@ class SplCaster
$storage = array();
unset($a[Caster::PREFIX_DYNAMIC."\0gcdata"]); // Don't hit https://bugs.php.net/65967
foreach (clone $c as $obj) {
$clone = clone $c;
foreach ($clone as $obj) {
$storage[spl_object_hash($obj)] = array(
'object' => $obj,
'info' => $c->getInfo(),
'info' => $clone->getInfo(),
);
}

View File

@ -40,4 +40,23 @@ EOTXT;
array(\SplDoublyLinkedList::IT_MODE_LIFO | \SplDoublyLinkedList::IT_MODE_DELETE, 'IT_MODE_LIFO | IT_MODE_DELETE'),
);
}
public function testCastObjectStorageIsntModified()
{
$var = new \SplObjectStorage();
$var->attach(new \stdClass());
$var->rewind();
$current = $var->current();
$this->assertDumpMatchesFormat('%A', $var);
$this->assertSame($current, $var->current());
}
public function testCastObjectStorageDumpsInfo()
{
$var = new \SplObjectStorage();
$var->attach(new \stdClass(), new \DateTime());
$this->assertDumpMatchesFormat('%ADateTime%A', $var);
}
}