Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5d39dd

Browse filesBrowse files
committed
bug #60258 [VarExporter] Fix: Use correct closure call for property-specific logic in $notByRef (Hakayashii, denjas)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [VarExporter] Fix: Use correct closure call for property-specific logic in $notByRef | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #... | License | MIT Previously, $notByRef was treated as a callable instead of an array of closures. Now, the closure is correctly invoked with $notByRef[$name]($object, $value) if it's not true. Encountered the following error after loading an entity from the database using Doctrine, which held a reference to another entity. The error occurred when modifying this lazily-loaded reference. ``` [critical] Uncaught Error: Array callback must have exactly two elements In Hydrator.php line 163: [Error] Array callback must have exactly two elements Exception trace: at C:\Users\hakayashii\repos\test\vendor\symfony\var-exporter\Internal\Hydrator.php:163 Proxies\__CG__\App\Entity\Subscription->{closure:Symfony\Component\VarExporter\Internal\Hydrator::getSimpleHydrator():155}() at C:\Users\hakayashii\repos\test\vendor\symfony\var-exporter\Hydrator.php:72 Symfony\Component\VarExporter\Hydrator::hydrate() at C:\Users\hakayashii\repos\test\vendor\symfony\var-exporter\Internal\LazyObjectState.php:56 Symfony\Component\VarExporter\Internal\LazyObjectState->initialize() at C:\Users\hakayashii\repos\test\vendor\symfony\var-exporter\LazyGhostTrait.php:146 Proxies\__CG__\App\Entity\Subscription->__get() at C:\Users\hakayashii\repos\test\src\Service\OrderBuilder.php:45 [...] ``` Commits ------- b1f0602 [VarExporter] Fix: Use correct closure call for property-specific logic in $notByRef
2 parents 06cccc5 + b1f0602 commit c5d39dd
Copy full SHA for c5d39dd

File tree

Expand file treeCollapse file tree

3 files changed

+35
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+35
-1
lines changed

‎src/Symfony/Component/VarExporter/Internal/Hydrator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Internal/Hydrator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static function getSimpleHydrator($class)
166166
$object->$name = $value;
167167
$object->$name = &$value;
168168
} elseif (true !== $noRef) {
169-
$notByRef($object, $value);
169+
$noRef($object, $value);
170170
} else {
171171
$object->$name = $value;
172172
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy;
4+
5+
class HookedWithDefaultValue
6+
{
7+
public int $backedWithDefault = 321 {
8+
get => $this->backedWithDefault;
9+
set => $this->backedWithDefault = $value;
10+
}
11+
}

‎src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Component\VarExporter\Tests\Fixtures\LazyGhost\TestClass;
2828
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\AsymmetricVisibility;
2929
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\Hooked;
30+
use Symfony\Component\VarExporter\Tests\Fixtures\LazyProxy\HookedWithDefaultValue;
3031
use Symfony\Component\VarExporter\Tests\Fixtures\SimpleObject;
3132

3233
class LazyGhostTraitTest extends TestCase
@@ -505,6 +506,28 @@ public function testPropertyHooks()
505506
$this->assertSame(345, $object->backed);
506507
}
507508

509+
/**
510+
* @requires PHP 8.4
511+
*/
512+
public function testPropertyHooksWithDefaultValue()
513+
{
514+
$initialized = false;
515+
$object = $this->createLazyGhost(HookedWithDefaultValue::class, function ($instance) use (&$initialized) {
516+
$initialized = true;
517+
});
518+
519+
$this->assertSame(321, $object->backedWithDefault);
520+
$this->assertTrue($initialized);
521+
522+
$initialized = false;
523+
$object = $this->createLazyGhost(HookedWithDefaultValue::class, function ($instance) use (&$initialized) {
524+
$initialized = true;
525+
});
526+
$object->backedWithDefault = 654;
527+
$this->assertTrue($initialized);
528+
$this->assertSame(654, $object->backedWithDefault);
529+
}
530+
508531
/**
509532
* @requires PHP 8.4
510533
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.