Set value on an attribute of a class that doesn't have setter
Dec 6, 2022 PHP
Useful to set the id of a doctrine entity for example in a test for example
$a = new A();
$reflection = new \ReflectionClass($a);
$property = $reflection->getProperty('privateProperty');
$property->setAccessible(true);
$property->setValue($a, 'new-value');
symfony
php
short
Categories
Recent posts
Create a custom attribute/annotation and understand @security annotation behind the scene [Symfony]
Create a ssl certificate using let's encrypt [System]
Usual Makefile commands on symfony project [Symfony]
Symfony create a custom logger file and understand behind the scene [Symfony]
Démarrer un nouveau projet symfony 6 comme un sénior sous docker [Symfony]