From a16ad380e58039833f84dac4ad95893104868338 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 2 Feb 2025 08:32:47 +0000 Subject: [PATCH] Add output for examples of ReflectionProperty methods. --- .../reflection/reflectionproperty/gethook.xml | 12 +++++++++++ .../reflectionproperty/gethooks.xml | 16 ++++++++++++++ .../reflectionproperty/getrawvalue.xml | 12 ++++++++++- .../reflectionproperty/getsettabletype.xml | 12 +++++++++++ .../reflection/reflectionproperty/hashook.xml | 7 +++++++ .../reflectionproperty/hashooks.xml | 7 +++++++ .../reflection/reflectionproperty/isfinal.xml | 8 +++++++ .../reflectionproperty/isvirtual.xml | 8 +++++++ .../reflectionproperty/setrawvalue.xml | 21 +++++++++++++++++-- 9 files changed, 100 insertions(+), 3 deletions(-) diff --git a/reference/reflection/reflectionproperty/gethook.xml b/reference/reflection/reflectionproperty/gethook.xml index 21b9b237c976..6013bc095cbb 100644 --- a/reference/reflection/reflectionproperty/gethook.xml +++ b/reference/reflection/reflectionproperty/gethook.xml @@ -57,6 +57,18 @@ var_dump($rProp->getHook(PropertyHookType::Set)); ?> ]]> + &example.outputs; + + + string(10) "$name::get" + ["class"]=> + string(7) "Example" +} +NULL +]]> + diff --git a/reference/reflection/reflectionproperty/gethooks.xml b/reference/reflection/reflectionproperty/gethooks.xml index 6c920172962a..eb6f5c97910b 100644 --- a/reference/reflection/reflectionproperty/gethooks.xml +++ b/reference/reflection/reflectionproperty/gethooks.xml @@ -57,6 +57,22 @@ var_dump($rProp->getHooks()); ?> ]]> + &example.outputs; + + + object(ReflectionMethod)#3 (2) { + ["name"]=> + string(10) "$name::get" + ["class"]=> + string(7) "Example" + } +} +array(0) { +} +]]> + diff --git a/reference/reflection/reflectionproperty/getrawvalue.xml b/reference/reflection/reflectionproperty/getrawvalue.xml index bbec5fd539c7..a7710c67ce93 100644 --- a/reference/reflection/reflectionproperty/getrawvalue.xml +++ b/reference/reflection/reflectionproperty/getrawvalue.xml @@ -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); ?> ]]> + &example.outputs; + + + diff --git a/reference/reflection/reflectionproperty/getsettabletype.xml b/reference/reflection/reflectionproperty/getsettabletype.xml index da625a7d717c..078700ee54fa 100644 --- a/reference/reflection/reflectionproperty/getsettabletype.xml +++ b/reference/reflection/reflectionproperty/getsettabletype.xml @@ -78,6 +78,18 @@ var_dump($rClass->getProperty('untyped')->getSettableType()); ?> ]]> + &example.outputs; + + + diff --git a/reference/reflection/reflectionproperty/hashook.xml b/reference/reflection/reflectionproperty/hashook.xml index ed2ee56c3d22..948f41f1e994 100644 --- a/reference/reflection/reflectionproperty/hashook.xml +++ b/reference/reflection/reflectionproperty/hashook.xml @@ -56,6 +56,13 @@ var_dump($rProp->hasHook(PropertyHookType::Set)); ?> ]]> + &example.outputs; + + + diff --git a/reference/reflection/reflectionproperty/hashooks.xml b/reference/reflection/reflectionproperty/hashooks.xml index 0fbb37f42bda..3e5ac4e756fe 100644 --- a/reference/reflection/reflectionproperty/hashooks.xml +++ b/reference/reflection/reflectionproperty/hashooks.xml @@ -49,6 +49,13 @@ var_dump($rClass->getProperty('none')->hasHooks()); ?> ]]> + &example.outputs; + + + diff --git a/reference/reflection/reflectionproperty/isfinal.xml b/reference/reflection/reflectionproperty/isfinal.xml index d4612b7fd781..9b2990ee7576 100644 --- a/reference/reflection/reflectionproperty/isfinal.xml +++ b/reference/reflection/reflectionproperty/isfinal.xml @@ -58,6 +58,14 @@ var_dump($rClass->getProperty('job')->isFinal()); ?> ]]> + &example.outputs; + + + diff --git a/reference/reflection/reflectionproperty/isvirtual.xml b/reference/reflection/reflectionproperty/isvirtual.xml index 401663a6d859..03c64baa82f2 100644 --- a/reference/reflection/reflectionproperty/isvirtual.xml +++ b/reference/reflection/reflectionproperty/isvirtual.xml @@ -64,6 +64,14 @@ var_dump($rClass->getProperty('job')->isVirtual()); ?> ]]> + &example.outputs; + + + diff --git a/reference/reflection/reflectionproperty/setrawvalue.xml b/reference/reflection/reflectionproperty/setrawvalue.xml index 071f967488dc..8254b0d30a1e 100644 --- a/reference/reflection/reflectionproperty/setrawvalue.xml +++ b/reference/reflection/reflectionproperty/setrawvalue.xml @@ -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; ?> ]]> + &example.outputs; + + +