xref: /PHP-7.2/ext/reflection/tests/006.phpt (revision 17ccbeec)
1--TEST--
2ReflectionClass::[gs]etStaticPropertyValue
3--FILE--
4<?php
5
6/* ReflectionClass cannot touch protected or private static properties */
7
8/* ReflectionClass cannot create or delete static properties */
9
10Class Test
11{
12	static public    $pub = 'pub';
13	static protected $pro = 'pro';
14	static private   $pri = 'pri';
15
16	static function testing()
17	{
18		$ref = new ReflectionClass('Test');
19
20		foreach(array('pub', 'pro', 'pri') as $name)
21		{
22			try
23			{
24				var_dump($ref->getStaticPropertyValue($name));
25				var_dump($ref->getStaticPropertyValue($name));
26				$ref->setStaticPropertyValue($name, 'updated');
27				var_dump($ref->getStaticPropertyValue($name));
28			}
29			catch(Exception $e)
30			{
31				echo "EXCEPTION\n";
32			}
33		}
34	}
35}
36
37Class TestDerived extends Test
38{
39//	static public    $pub = 'pub';
40//	static protected $pro = 'pro';
41	static private   $pri = 'pri';
42
43	static function testing()
44	{
45		$ref = new ReflectionClass('Test');
46
47		foreach(array('pub', 'pro', 'pri') as $name)
48		{
49			try
50			{
51				var_dump($ref->getStaticPropertyValue($name));
52				var_dump($ref->getStaticPropertyValue($name));
53				$ref->setStaticPropertyValue($name, 'updated');
54				var_dump($ref->getStaticPropertyValue($name));
55			}
56			catch(Exception $e)
57			{
58				echo "EXCEPTION\n";
59			}
60		}
61	}
62}
63
64$ref = new ReflectionClass('Test');
65
66foreach(array('pub', 'pro', 'pri') as $name)
67{
68	try
69	{
70		var_dump($ref->getStaticPropertyValue($name));
71		var_dump($ref->getStaticPropertyValue($name));
72		$ref->setStaticPropertyValue($name, 'updated');
73		var_dump($ref->getStaticPropertyValue($name));
74	}
75	catch(Exception $e)
76	{
77		echo "EXCEPTION\n";
78	}
79}
80
81Test::testing();
82TestDerived::testing();
83
84?>
85===DONE===
86<?php exit(0); ?>
87--EXPECT--
88string(3) "pub"
89string(3) "pub"
90string(7) "updated"
91EXCEPTION
92EXCEPTION
93string(7) "updated"
94string(7) "updated"
95string(7) "updated"
96EXCEPTION
97EXCEPTION
98string(7) "updated"
99string(7) "updated"
100string(7) "updated"
101EXCEPTION
102EXCEPTION
103===DONE===
104