Skip to content

Commit c1b6b73

Browse files
committed
Add tests from ilutov
1 parent 07ea9f5 commit c1b6b73

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Can override readonly property with attributes
3+
--FILE--
4+
<?php
5+
6+
#[Attribute]
7+
class FooAttribute {}
8+
9+
class A {
10+
public readonly int $prop;
11+
12+
public function __construct() {
13+
$this->prop = 42;
14+
}
15+
}
16+
class B extends A {
17+
#[FooAttribute]
18+
public readonly int $prop;
19+
}
20+
21+
var_dump((new ReflectionProperty(B::class, 'prop'))->getAttributes()[0]->newInstance());
22+
23+
?>
24+
--EXPECT--
25+
object(FooAttribute)#1 (0) {
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Visibility can change in readonly property
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
protected readonly int $prop;
8+
9+
public function __construct() {
10+
$this->prop = 42;
11+
}
12+
}
13+
class B extends A {
14+
public readonly int $prop;
15+
}
16+
17+
$a = new A();
18+
try {
19+
var_dump($a->prop);
20+
} catch (Error $error) {
21+
echo $error->getMessage() . "\n";
22+
}
23+
24+
$b = new B();
25+
var_dump($b->prop);
26+
27+
?>
28+
--EXPECT--
29+
Cannot access protected property A::$prop
30+
int(42)

0 commit comments

Comments
 (0)