Skip to content
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

[HttpKernel] Fix datacollector caster for reference object property #54072

Merged
merged 1 commit into from
Apr 12, 2024

Conversation

ebuildy
Copy link
Contributor

@ebuildy ebuildy commented Feb 26, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #49091
License MIT

As discussed on #49091:

Unit tests FAIL "Error: KO src/Symfony/Component/HttpKernel" --> normal

@ebuildy ebuildy marked this pull request as ready for review February 26, 2024 22:43
@carsonbot carsonbot added this to the 5.4 milestone Feb 26, 2024
@OskarStark OskarStark changed the title [HttpKernel] fix datacollector caster for reference object property [HttpKernel] Fix datacollector caster for reference object property Feb 29, 2024
@symfony symfony deleted a comment from carsonbot Feb 29, 2024
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the test cases.
Here is the correct patch that fixes both aspect of the issue:

--- a/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
+++ b/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php
@@ -70,16 +70,21 @@ abstract class DataCollector implements DataCollectorInterface
         $casters = [
             '*' => function ($v, array $a, Stub $s, $isNested) {
                 if (!$v instanceof Stub) {
+                    $b = $a;
                     foreach ($a as $k => $v) {
                         if (!\is_object($v) || $v instanceof \DateTimeInterface || $v instanceof Stub) {
                             continue;
                         }
 
                         try {
-                            $a[$k] = new CutStub($v);
+                            $a[$k] = $s = new CutStub($v);
+
+                            if ($b[$k] === $s) {
+                                // we've hit a non-typed reference
+                                $a[$k] = $v;
+                            }
                         } catch (\TypeError $e) {
-                            $a[$k] = &$v;
-                            unset($v);
+                            // we've hit a typed reference
                         }
                     }
                 }

@nicolas-grekas
Copy link
Member

Can you please make the necessary changes to fix the CI on PHP 7.2+? (that could involve using @requires PHP 8.0 on test cases of course)

@nicolas-grekas
Copy link
Member

Thank you @ebuildy.

@nicolas-grekas nicolas-grekas merged commit 8004c14 into symfony:5.4 Apr 12, 2024
5 of 12 checks passed
@ebuildy ebuildy deleted the fix_httpkernel_clone_caster branch April 12, 2024 13:18
xabbuh added a commit that referenced this pull request Apr 12, 2024
This PR was merged into the 5.4 branch.

Discussion
----------

[HttpKernel] fix low deps tests

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        |
| License       | MIT

after #54072 we need #43171

Commits
-------

c78255d fix low deps tests
This was referenced Apr 29, 2024
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.

None yet

3 participants