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