note 127707 added to reflectionproperty.setvalue
| From: | temirkhan dot nasukhov at main dot php dot net | Date: | Mon, 10 Oct 2022 17:41:02 +0000 |
| Subject: | note 127707 added to reflectionproperty.setvalue | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219658@lists.php.net to get a copy of this message | ||
Keep in mind that setValue won't work for readonly properties.
<?php
class Person
{
public function __construct(private readonly int $age) {}
}
$someOldPerson = new Person(80);
$reflection = new ReflectionProperty($someOldPerson, 'age');
$reflection->setValue($someOldPerson, 10); // Fatal error: Uncaught Error: Cannot modify readonly
property Person::$age
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.161 (proxied: 2a01:598:b1a3:a87a:c94d:e4af:3f7d:1054)
----
Manual Page -- https://php.net/manual/en/reflectionproperty.setvalue.php
Edit -- https://main.php.net/note/edit/127707
Del: integrated -- https://main.php.net/note/delete/127707/integrated
Del: useless -- https://main.php.net/note/delete/127707/useless
Del: bad code -- https://main.php.net/note/delete/127707/bad+code
Del: spam -- https://main.php.net/note/delete/127707/spam
Del: non-english -- https://main.php.net/note/delete/127707/non-english
Del: in docs -- https://main.php.net/note/delete/127707/in+docs
Del: other reasons-- https://main.php.net/note/delete/127707
Reject -- https://main.php.net/note/reject/127707
Search -- https://main.php.net/manage/user-notes.php