Skip to content

Commit

Permalink
Add output for examples of ReflectionProperty methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Feb 2, 2025
1 parent a204b11 commit b08932f
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 3 deletions.
12 changes: 12 additions & 0 deletions reference/reflection/reflectionproperty/gethook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ var_dump($rProp->getHook(PropertyHookType::Set));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(ReflectionMethod)#4 (2) {
["name"]=>
string(10) "$name::get"
["class"]=>
string(7) "Example"
}
NULL
]]>
</screen>
</example>
</refsect1>

Expand Down
16 changes: 16 additions & 0 deletions reference/reflection/reflectionproperty/gethooks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ var_dump($rProp->getHooks());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
array(1) {
["get"]=>
object(ReflectionMethod)#3 (2) {
["name"]=>
string(10) "$name::get"
["class"]=>
string(7) "Example"
}
}
array(0) {
}
]]>
</screen>
</example>
</refsect1>

Expand Down
12 changes: 11 additions & 1 deletion reference/reflection/reflectionproperty/getrawvalue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,23 @@ $rProp = $rClass->getProperty('tag');
// These would go through the get hook, so would produce "php".
print $example->tag;
print "\n";
print $rProp->getValue($example);
print "\n";
// But this would bypass the hook and produce "PHP".
print $rProp->setRawValue($example);
print $rProp->getRawValue($example);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
php
php
PHP
]]>
</screen>
</example>
</refsect1>

Expand Down
12 changes: 12 additions & 0 deletions reference/reflection/reflectionproperty/getsettabletype.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ var_dump($rClass->getProperty('untyped')->getSettableType());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
object(ReflectionNamedType)#3 (0) {
}
object(ReflectionUnionType)#2 (0) {
}
object(ReflectionNamedType)#3 (0) {
}
NULL
]]>
</screen>
</example>
</refsect1>

Expand Down
7 changes: 7 additions & 0 deletions reference/reflection/reflectionproperty/hashook.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ var_dump($rProp->hasHook(PropertyHookType::Set));
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(true)
bool(false)
]]>
</screen>
</example>
</refsect1>

Expand Down
7 changes: 7 additions & 0 deletions reference/reflection/reflectionproperty/hashooks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ var_dump($rClass->getProperty('none')->hasHooks());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(true)
bool(false)
]]>
</screen>
</example>
</refsect1>

Expand Down
8 changes: 8 additions & 0 deletions reference/reflection/reflectionproperty/isfinal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ var_dump($rClass->getProperty('job')->isFinal());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(false)
bool(true)
bool(true)
]]>
</screen>
</example>
</refsect1>

Expand Down
8 changes: 8 additions & 0 deletions reference/reflection/reflectionproperty/isvirtual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ var_dump($rClass->getProperty('job')->isVirtual());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(true)
bool(false)
bool(false)
]]>
</screen>
</example>
</refsect1>

Expand Down
21 changes: 19 additions & 2 deletions reference/reflection/reflectionproperty/setrawvalue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,31 @@ $rClass = new \ReflectionClass(Example::class);
$rProp = $rClass->getProperty('age');
// These would go through the set hook, and throw an exception.
$example->age = -2;
$rProp->setValue($example, -2);
try {
$example->age = -2;
} catch (InvalidArgumentException) {
print "InvalidArgumentException for setting property to -2\n";
}
try {
$rProp->setValue($example, -2);
} catch (InvalidArgumentException) {
print "InvalidArgumentException for using ReflectionProperty::setValue() with -2\n";
}
// But this would set the $age to -2 without error.
$rProp->setRawValue($example, -2);
print $example->age;
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
InvalidArgumentException for setting property to -2
InvalidArgumentException for using ReflectionProperty::setValue() with -2
-2
]]>
</screen>
</example>
</refsect1>

Expand Down

0 comments on commit b08932f

Please sign in to comment.