xref: /PHP-8.0/ext/reflection/tests/002.phpt (revision f8d79582)
1--TEST--
2Reflection properties are read only
3--FILE--
4<?php
5
6class ReflectionMethodEx extends ReflectionMethod
7{
8    public $foo = "xyz";
9
10    function __construct($c,$m)
11    {
12        echo __METHOD__ . "\n";
13        parent::__construct($c,$m);
14    }
15}
16
17$r = new ReflectionMethodEx('ReflectionMethodEx','getName');
18
19var_dump($r->class);
20var_dump($r->name);
21var_dump($r->foo);
22@var_dump($r->bar);
23
24try
25{
26    $r->class = 'bullshit';
27}
28catch(ReflectionException $e)
29{
30    echo $e->getMessage() . "\n";
31}
32try
33{
34$r->name = 'bullshit';
35}
36catch(ReflectionException $e)
37{
38    echo $e->getMessage() . "\n";
39}
40
41$r->foo = 'bar';
42$r->bar = 'baz';
43
44var_dump($r->class);
45var_dump($r->name);
46var_dump($r->foo);
47var_dump($r->bar);
48
49?>
50--EXPECT--
51ReflectionMethodEx::__construct
52string(26) "ReflectionFunctionAbstract"
53string(7) "getName"
54string(3) "xyz"
55NULL
56Cannot set read-only property ReflectionMethodEx::$class
57Cannot set read-only property ReflectionMethodEx::$name
58string(26) "ReflectionFunctionAbstract"
59string(7) "getName"
60string(3) "bar"
61string(3) "baz"
62