mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
RFC: https://wiki.php.net/rfc/isreadable-iswriteable Fixes GH-15309 Fixes GH-16175 Closes GH-16209
40 lines
709 B
PHP
40 lines
709 B
PHP
--TEST--
|
|
Test ReflectionProperty::isWritable() readonly
|
|
--FILE--
|
|
<?php
|
|
|
|
class A {
|
|
public readonly int $a;
|
|
public readonly int $b;
|
|
|
|
public function __construct() {
|
|
$this->a = 42;
|
|
}
|
|
|
|
public function __clone() {
|
|
test($this);
|
|
$this->a = 43;
|
|
test($this);
|
|
}
|
|
}
|
|
|
|
function test($instance) {
|
|
$rc = new ReflectionClass($instance);
|
|
foreach ($rc->getProperties() as $rp) {
|
|
echo $rp->getName() . ' from A: ';
|
|
var_dump($rp->isWritable($instance::class, $instance));
|
|
}
|
|
}
|
|
|
|
test(new A);
|
|
clone new A;
|
|
|
|
?>
|
|
--EXPECT--
|
|
a from A: bool(false)
|
|
b from A: bool(true)
|
|
a from A: bool(true)
|
|
b from A: bool(true)
|
|
a from A: bool(false)
|
|
b from A: bool(true)
|