xref: /PHP-7.3/ext/reflection/tests/002.phpt (revision 782352c5)
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===DONE===
51--EXPECT--
52ReflectionMethodEx::__construct
53string(26) "ReflectionFunctionAbstract"
54string(7) "getName"
55string(3) "xyz"
56NULL
57Cannot set read-only property ReflectionMethodEx::$class
58Cannot set read-only property ReflectionMethodEx::$name
59string(26) "ReflectionFunctionAbstract"
60string(7) "getName"
61string(3) "bar"
62string(3) "baz"
63===DONE===
64