PHP 8.5.0 Alpha 4 available for testing

Voting

: four plus three?
(Example: nine)

The Note You're Voting On

temirkhan.nasukhov
2 years ago
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

<< Back to user notes page

To Top