Skip to content

Navigation Menu

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

[VarExporter] Fixed lazy-loading ghost objects generation with property hooks #60421

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

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/VarExporter/ProxyHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function generateLazyGhost(\ReflectionClass $class): string
.($p->isProtected() ? 'protected' : 'public')
.($p->isProtectedSet() ? ' protected(set)' : '')
." {$type} \${$name}"
.($p->hasDefaultValue() ? ' = '.$p->getDefaultValue() : '')
.($p->hasDefaultValue() ? ' = '.VarExporter::export($p->getDefaultValue()) : '')
Copy link
Member

Choose a reason for hiding this comment

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

actually this should use the exportDefault helper
and the PR should target branch 6.4

Copy link
Member

Choose a reason for hiding this comment

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

let's keep as is, I don't think my suggestion is valid for properties

." {\n";

foreach ($p->getHooks() as $hook => $method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@

class HookedWithDefaultValue
{
public int $backedWithDefault = 321 {
get => $this->backedWithDefault;
set => $this->backedWithDefault = $value;
public int $backedIntWithDefault = 321 {
get => $this->backedIntWithDefault;
set => $this->backedIntWithDefault = $value;
}

public string $backedStringWithDefault = '321' {
get => $this->backedStringWithDefault;
set => $this->backedStringWithDefault = $value;
}

public bool $backedBoolWithDefault = false {
get => $this->backedBoolWithDefault;
set => $this->backedBoolWithDefault = $value;
}
}
12 changes: 9 additions & 3 deletions 12 src/Symfony/Component/VarExporter/Tests/LazyGhostTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,22 @@ public function testPropertyHooksWithDefaultValue()
$initialized = true;
});

$this->assertSame(321, $object->backedWithDefault);
$this->assertSame(321, $object->backedIntWithDefault);
$this->assertSame('321', $object->backedStringWithDefault);
$this->assertSame(false, $object->backedBoolWithDefault);
$this->assertTrue($initialized);

$initialized = false;
$object = $this->createLazyGhost(HookedWithDefaultValue::class, function ($instance) use (&$initialized) {
$initialized = true;
});
$object->backedWithDefault = 654;
$object->backedIntWithDefault = 654;
$object->backedStringWithDefault = '654';
$object->backedBoolWithDefault = true;
$this->assertTrue($initialized);
$this->assertSame(654, $object->backedWithDefault);
$this->assertSame(654, $object->backedIntWithDefault);
$this->assertSame('654', $object->backedStringWithDefault);
$this->assertSame(true, $object->backedBoolWithDefault);
}

/**
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.