Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #50960 [VarDumper] Fix dumping
ArrayObject
with `DumpDataCollec…
…tor` (lyrixx, HypeMC) This PR was merged into the 5.4 branch. Discussion ---------- [VarDumper] Fix dumping `ArrayObject` with `DumpDataCollector` | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50940 | License | MIT | Doc PR | - The main problem here is that the `ArrayObjectstorage` key in [the array returned by `__debugInfo()`](https://github.com/symfony/symfony/blob/de7ab4d85dcc94032b77f1a15d7a030714a1f734/src/Symfony/Component/VarDumper/Caster/SplCaster.php#L229-L229) seems to be a reference: https://3v4l.org/8rSFn (a bug in PHP perhaps?) Since the `DumpDataCollector` does the actual dumping in the `__destructor()` the `ArrayObjectstorage` is modified by then which messes with the object created by the `VarCloner`. Commits ------- b25f377 [VarDumper] Fix dumping `ArrayObject` with `DumpDataCollector` 1f2c6f7 [VarDumper] Add tests to demonstrate a bug when dumping ArrayObject with full stack fmk
- Loading branch information
Showing
6 changed files
with
78 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ymfony/Component/VarDumper/Tests/Dumper/functions/dump_data_collector_with_spl_array.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--TEST-- | ||
Test integration with Symfony's DumpDataCollector | ||
--FILE-- | ||
<?php | ||
putenv('NO_COLOR=1'); | ||
|
||
$vendor = __DIR__; | ||
while (!file_exists($vendor.'/vendor')) { | ||
$vendor = dirname($vendor); | ||
} | ||
require $vendor.'/vendor/autoload.php'; | ||
|
||
use Symfony\Component\HttpKernel\DataCollector\DumpDataCollector; | ||
use Symfony\Component\VarDumper\Cloner\VarCloner; | ||
use Symfony\Component\VarDumper\VarDumper; | ||
|
||
VarDumper::setHandler(function ($var, string $label = null) { | ||
$dumper = new DumpDataCollector(); | ||
$cloner = new VarCloner(); | ||
$handler = function ($var, string $label = null) use ($dumper, $cloner) { | ||
$var = $cloner->cloneVar($var); | ||
if (null !== $label) { | ||
$var = $var->withContext(['label' => $label]); | ||
} | ||
|
||
$dumper->dump($var); | ||
}; | ||
VarDumper::setHandler($handler); | ||
$handler($var, $label); | ||
}); | ||
|
||
$arrayObject = new \ArrayObject(); | ||
dump($arrayObject); | ||
$arrayObject['X'] = 'A'; | ||
$arrayObject['Y'] = new \ArrayObject(['type' => 'object']); | ||
$arrayObject['Y']['Z'] = 'B'; | ||
|
||
$arrayIterator = new \ArrayIterator(); | ||
dump($arrayIterator); | ||
$arrayIterator['X'] = 'A'; | ||
$arrayIterator['Y'] = new \ArrayIterator(['type' => 'object']); | ||
$arrayIterator['Y']['Z'] = 'B'; | ||
|
||
$recursiveArrayIterator = new \RecursiveArrayIterator(); | ||
dump($recursiveArrayIterator); | ||
$recursiveArrayIterator['X'] = 'A'; | ||
$recursiveArrayIterator['Y'] = new \RecursiveArrayIterator(['type' => 'object']); | ||
$recursiveArrayIterator['Y']['Z'] = 'B'; | ||
|
||
--EXPECTF-- | ||
%s on line %d: | ||
ArrayObject {#%d | ||
storage: [] | ||
flag::STD_PROP_LIST: false | ||
flag::ARRAY_AS_PROPS: false | ||
iteratorClass: "ArrayIterator" | ||
} | ||
%s on line %d: | ||
ArrayIterator {#%d | ||
storage: [] | ||
flag::STD_PROP_LIST: false | ||
flag::ARRAY_AS_PROPS: false | ||
} | ||
%s on line %d: | ||
RecursiveArrayIterator {#%d | ||
storage: [] | ||
flag::STD_PROP_LIST: false | ||
flag::ARRAY_AS_PROPS: false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters