Skip to content

[VarDumper] Add tests to demonstrate a bug when dumping ArrayObject with full stack fmk #50940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

lyrixx
Copy link
Member

@lyrixx lyrixx commented Jul 11, 2023

Q A
Branch? 5.4
Bug fix? not yet
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

I had hard time to find a very minimal reproducer!
I think the issue is here, where we update the stub:

foreach ($item as $stub->class => $stub->position) {

I spent a bit too much time on this one, so I cannot go further. Sorry, this is the best I can dot ATM

Current errors

PHPUnit 9.6.9 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Tests/Integration
FF                                                                  2 / 2 (100%)

Time: 00:00.094, Memory: 10.00 MB

There were 2 failures:

1) /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Tests/Integration/dump_data_collector.phpt
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-ArrayObject {#%d
-  -storage: []
-  flag::STD_PROP_LIST: false
-  flag::ARRAY_AS_PROPS: false
-  iteratorClass: "ArrayIterator"
-}
+tandard input code on line 31:
+ArrayObject {#24
+
+Fatal error: Uncaught TypeError: Illegal offset type in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php:464
+Stack trace:
+#0 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(340): Symfony\Component\VarDumper\Cloner\Data->getStub()
+#1 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(440): Symfony\Component\VarDumper\Cloner\Data->dumpItem()
+#2 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(402): Symfony\Component\VarDumper\Cloner\Data->dumpChildren()
+#3 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(321): Symfony\Component\VarDumper\Cloner\Data->dumpItem()
+#4 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php(135): Symfony\Component\VarDumper\Cloner\Data->dump()
+#5 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php(290): Symfony\Component\VarDumper\Dumper\AbstractDumper->dump()
+#6 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php(253): Symfony\Component\HttpKernel\DataCollector\DumpDataCollector->doDump()
+#7 [internal function]: Symfony\Component\HttpKernel\DataCollector\DumpDataCollector->__destruct()
+#8 {main}
+  thrown in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php on line 464

/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Tests/Integration/dump_data_collector.phpt:38

2) /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Tests/Integration/dump_data_collector2.phpt
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
-ArrayObject {#%d
-  -storage: []
-  flag::STD_PROP_LIST: false
-  flag::ARRAY_AS_PROPS: false
-  iteratorClass: "ArrayIterator"
-}
+tandard input code on line 31:
+ArrayObject {#24
+
+Warning: Undefined array key "A" in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php on line 464
+
+Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php:464
+Stack trace:
+#0 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(340): Symfony\Component\VarDumper\Cloner\Data->getStub()
+#1 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(440): Symfony\Component\VarDumper\Cloner\Data->dumpItem()
+#2 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(402): Symfony\Component\VarDumper\Cloner\Data->dumpChildren()
+#3 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php(321): Symfony\Component\VarDumper\Cloner\Data->dumpItem()
+#4 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Dumper/AbstractDumper.php(135): Symfony\Component\VarDumper\Cloner\Data->dump()
+#5 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php(290): Symfony\Component\VarDumper\Dumper\AbstractDumper->dump()
+#6 /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php(253): Symfony\Component\HttpKernel\DataCollector\DumpDataCollector->doDump()
+#7 [internal function]: Symfony\Component\HttpKernel\DataCollector\DumpDataCollector->__destruct()
+#8 {main}
+  thrown in /home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Cloner/Data.php on line 464

/home/gregoire/dev/github.com/lyrixx/symfony/src/Symfony/Component/VarDumper/Tests/Integration/dump_data_collector2.phpt:38

FAILURES!
Tests: 2, Assertions: 2, Failures: 2.

@carsonbot carsonbot added this to the 5.4 milestone Jul 11, 2023
nicolas-grekas added a commit that referenced this pull request Jul 13, 2023
…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
@lyrixx lyrixx deleted the var-dump-bim-bam-boom branch July 13, 2023 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants