readonly properties
| From: | Marc | Date: | Thu, 12 Aug 2021 19:16:06 +0000 |
| Subject: | readonly properties | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-115699@lists.php.net to get a copy of this message | ||
Hi,
As 8.1 adds readonly properties I wonder which build-in properties should be defined readonly.
Currently I could find build-in readonly properties only on PDO and DOM.
Very incomplete list where readonly properties could make sense:
1. Enum properties:
enum Test:string {
case TEST = 'test';} $case = TEST::TEST; $refl = (new ReflectionObject($case))->getProperty('value'); var_dump($refl->isReadOnly()); // false var_dump($refl->isPublic()); // true $case->value = 'foo'; // Fatal error: Uncaught Error: Enum properties are immutable 2. DateInterval->days $interval = (new DateTime())->diff(new DateTime()); var_dump($interval->days); // 0 $refl = (new ReflectionObject($interval))->getProperty('days'); var_dump($refl->isReadOnly()); // false var_dump($refl->isPublic()); // true $interval->days = 2; var_dump($interval->days); // 0 3. Exception properties Exception properties are protected but does it really make sense to be able to modify an exception property after initialization? I know this would be a BC break :( Thanks for all the excellent work - Can't wait for 8.1 :) Marc