File tree Expand file tree Collapse file tree 9 files changed +100
-3
lines changed
reference/reflection/reflectionproperty Expand file tree Collapse file tree 9 files changed +100
-3
lines changed Original file line number Diff line number Diff line change @@ -57,6 +57,18 @@ var_dump($rProp->getHook(PropertyHookType::Set));
57
57
?>
58
58
]]>
59
59
</programlisting >
60
+ &example.outputs;
61
+ <screen >
62
+ <![CDATA[
63
+ object(ReflectionMethod)#4 (2) {
64
+ ["name"]=>
65
+ string(10) "$name::get"
66
+ ["class"]=>
67
+ string(7) "Example"
68
+ }
69
+ NULL
70
+ ]]>
71
+ </screen >
60
72
</example >
61
73
</refsect1 >
62
74
Original file line number Diff line number Diff line change @@ -57,6 +57,22 @@ var_dump($rProp->getHooks());
57
57
?>
58
58
]]>
59
59
</programlisting >
60
+ &example.outputs;
61
+ <screen >
62
+ <![CDATA[
63
+ array(1) {
64
+ ["get"]=>
65
+ object(ReflectionMethod)#3 (2) {
66
+ ["name"]=>
67
+ string(10) "$name::get"
68
+ ["class"]=>
69
+ string(7) "Example"
70
+ }
71
+ }
72
+ array(0) {
73
+ }
74
+ ]]>
75
+ </screen >
60
76
</example >
61
77
</refsect1 >
62
78
Original file line number Diff line number Diff line change @@ -68,13 +68,23 @@ $rProp = $rClass->getProperty('tag');
68
68
69
69
// These would go through the get hook, so would produce "php".
70
70
print $example->tag;
71
+ print "\n";
71
72
print $rProp->getValue($example);
73
+ print "\n";
72
74
73
75
// But this would bypass the hook and produce "PHP".
74
- print $rProp->setRawValue ($example);
76
+ print $rProp->getRawValue ($example);
75
77
?>
76
78
]]>
77
79
</programlisting >
80
+ &example.outputs;
81
+ <screen >
82
+ <![CDATA[
83
+ php
84
+ php
85
+ PHP
86
+ ]]>
87
+ </screen >
78
88
</example >
79
89
</refsect1 >
80
90
Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ var_dump($rClass->getProperty('untyped')->getSettableType());
78
78
?>
79
79
]]>
80
80
</programlisting >
81
+ &example.outputs;
82
+ <screen >
83
+ <![CDATA[
84
+ object(ReflectionNamedType)#3 (0) {
85
+ }
86
+ object(ReflectionUnionType)#2 (0) {
87
+ }
88
+ object(ReflectionNamedType)#3 (0) {
89
+ }
90
+ NULL
91
+ ]]>
92
+ </screen >
81
93
</example >
82
94
</refsect1 >
83
95
Original file line number Diff line number Diff line change @@ -56,6 +56,13 @@ var_dump($rProp->hasHook(PropertyHookType::Set));
56
56
?>
57
57
]]>
58
58
</programlisting >
59
+ &example.outputs;
60
+ <screen >
61
+ <![CDATA[
62
+ bool(true)
63
+ bool(false)
64
+ ]]>
65
+ </screen >
59
66
</example >
60
67
</refsect1 >
61
68
Original file line number Diff line number Diff line change @@ -49,6 +49,13 @@ var_dump($rClass->getProperty('none')->hasHooks());
49
49
?>
50
50
]]>
51
51
</programlisting >
52
+ &example.outputs;
53
+ <screen >
54
+ <![CDATA[
55
+ bool(true)
56
+ bool(false)
57
+ ]]>
58
+ </screen >
52
59
</example >
53
60
</refsect1 >
54
61
Original file line number Diff line number Diff line change @@ -58,6 +58,14 @@ var_dump($rClass->getProperty('job')->isFinal());
58
58
?>
59
59
]]>
60
60
</programlisting >
61
+ &example.outputs;
62
+ <screen >
63
+ <![CDATA[
64
+ bool(false)
65
+ bool(true)
66
+ bool(true)
67
+ ]]>
68
+ </screen >
61
69
</example >
62
70
</refsect1 >
63
71
Original file line number Diff line number Diff line change @@ -64,6 +64,14 @@ var_dump($rClass->getProperty('job')->isVirtual());
64
64
?>
65
65
]]>
66
66
</programlisting >
67
+ &example.outputs;
68
+ <screen >
69
+ <![CDATA[
70
+ bool(true)
71
+ bool(false)
72
+ bool(false)
73
+ ]]>
74
+ </screen >
67
75
</example >
68
76
</refsect1 >
69
77
Original file line number Diff line number Diff line change @@ -79,14 +79,31 @@ $rClass = new \ReflectionClass(Example::class);
79
79
$rProp = $rClass->getProperty('age');
80
80
81
81
// These would go through the set hook, and throw an exception.
82
- $example->age = -2;
83
- $rProp->setValue($example, -2);
82
+ try {
83
+ $example->age = -2;
84
+ } catch (InvalidArgumentException) {
85
+ print "InvalidArgumentException for setting property to -2\n";
86
+ }
87
+ try {
88
+ $rProp->setValue($example, -2);
89
+ } catch (InvalidArgumentException) {
90
+ print "InvalidArgumentException for using ReflectionProperty::setValue() with -2\n";
91
+ }
84
92
85
93
// But this would set the $age to -2 without error.
86
94
$rProp->setRawValue($example, -2);
95
+ print $example->age;
87
96
?>
88
97
]]>
89
98
</programlisting >
99
+ &example.outputs;
100
+ <screen >
101
+ <![CDATA[
102
+ InvalidArgumentException for setting property to -2
103
+ InvalidArgumentException for using ReflectionProperty::setValue() with -2
104
+ -2
105
+ ]]>
106
+ </screen >
90
107
</example >
91
108
</refsect1 >
92
109
You can’t perform that action at this time.
0 commit comments