Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooks reflection examples output #4435

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
16 changes: 13 additions & 3 deletions reference/reflection/reflectionproperty/getrawvalue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,24 @@ $rClass = new \ReflectionClass(Example::class);
$rProp = $rClass->getProperty('tag');

// These would go through the get hook, so would produce "php".
print $example->tag;
print $rProp->getValue($example);
echo $example->tag;
echo "\n";
echo $rProp->getValue($example);
echo "\n";

// But this would bypass the hook and produce "PHP".
print $rProp->setRawValue($example);
echo $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) {
echo "InvalidArgumentException for setting property to -2\n";
}
try {
$rProp->setValue($example, -2);
} catch (InvalidArgumentException) {
echo "InvalidArgumentException for using ReflectionProperty::setValue() with -2\n";
}

// But this would set the $age to -2 without error.
$rProp->setRawValue($example, -2);
echo $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
Loading