You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Getting value from any public property results in an error. Cannot initialize readonly property App\Entity\Customer::$firstName from scope App\Command\Command
--TEST--
Verifies that public readonly properties can be used
--FILE--
<?phprequire_once__DIR__ . '/init.php';
useProxyManager\Proxy\GhostObjectInterface;
classKitchen
{
public readonly string$sweets;
}
$factory = new \ProxyManager\Factory\LazyLoadingGhostFactory($configuration);
$proxy = $factory->createProxy(Kitchen::class, function (
GhostObjectInterface$ghostObject,
string$method,
array$parameters,
?Closure &$initializer,
array$properties,
) {
$properties['sweets'] = 'cookies';
});
echo$proxy->sweets;
?>
--EXPECTF--
cookies
The reason is that PublicScopeSimulator generates an accessor that returns by reference for __get().
Feel free to give a fix a try. Alternatively, you might want to wait for Symfony 6.2, which will provide another implementation of ghost objects that's free from this issue already. See https://symfony.com/blog/revisiting-lazy-loading-proxies-in-php
I have an issue when trying to read public readonly properties from the Proxy. I got an error:
Library version: 1.0.12
Preconditions:
We have a class only with public properties.
Steps to Reproduce:
Cannot initialize readonly property App\Entity\Customer::$firstName from scope App\Command\Command
After investigation, I see the
$class
and$scopeObject
variables equal to theApp\Command\Command
.Note
But if we will add a getter for the property all works without errors.
The text was updated successfully, but these errors were encountered: