diff options
author | Steve Seear <stevseea@php.net> | 2007-12-18 17:21:55 +0000 |
---|---|---|
committer | Steve Seear <stevseea@php.net> | 2007-12-18 17:21:55 +0000 |
commit | f48e23c67f5c9f1940804a27644461e608dc5521 (patch) | |
tree | 1debcb34c3dfddee9a27219ced49009da1a5abf1 /ext | |
parent | d5d2b863038f2b11744f770e528430e63558161a (diff) | |
download | php-git-f48e23c67f5c9f1940804a27644461e608dc5521.tar.gz |
Adding PHPT tests for the ReflectionProperty class.
Diffstat (limited to 'ext')
13 files changed, 917 insertions, 0 deletions
diff --git a/ext/reflection/tests/reflectionProperty_basic1.phpt b/ext/reflection/tests/reflectionProperty_basic1.phpt new file mode 100644 index 0000000000..f7c1c8f10d --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_basic1.phpt @@ -0,0 +1,162 @@ +--TEST-- +Test usage of ReflectionProperty methods __toString(), export(), getName(), isPublic(), isPrivate(), isProtected(), isStatic(), getValue() and setValue(). +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +function reflectProperty($class, $property) { + $propInfo = new ReflectionProperty($class, $property); + echo "**********************************\n"; + echo "Reflecting on property $class::$property\n\n"; + echo "__toString():\n"; + var_dump($propInfo->__toString()); + echo "export():\n"; + var_dump(ReflectionProperty::export($class, $property, true)); + echo "export():\n"; + var_dump(ReflectionProperty::export($class, $property, false)); + echo "getName():\n"; + var_dump($propInfo->getName()); + echo "isPublic():\n"; + var_dump($propInfo->isPublic()); + echo "isPrivate():\n"; + var_dump($propInfo->isPrivate()); + echo "isProtected():\n"; + var_dump($propInfo->isProtected()); + echo "isStatic():\n"; + var_dump($propInfo->isStatic()); + $instance = new $class(); + if ($propInfo->isPublic()) { + echo "getValue():\n"; + var_dump($propInfo->getValue($instance)); + $propInfo->setValue($instance, "NewValue"); + echo "getValue() after a setValue():\n"; + var_dump($propInfo->getValue($instance)); + } + echo "\n**********************************\n"; +} + +class TestClass { + public $pub; + static public $stat = "static property"; + protected $prot = 4; + private $priv = "keepOut"; +} + +reflectProperty("TestClass", "pub"); +reflectProperty("TestClass", "stat"); +reflectProperty("TestClass", "prot"); +reflectProperty("TestClass", "priv"); + +?> +--EXPECT-- +********************************** +Reflecting on property TestClass::pub + +__toString(): +string(35) "Property [ <default> public $pub ] +" +export(): +string(35) "Property [ <default> public $pub ] +" +export(): +Property [ <default> public $pub ] + +NULL +getName(): +string(3) "pub" +isPublic(): +bool(true) +isPrivate(): +bool(false) +isProtected(): +bool(false) +isStatic(): +bool(false) +getValue(): +NULL +getValue() after a setValue(): +string(8) "NewValue" + +********************************** +********************************** +Reflecting on property TestClass::stat + +__toString(): +string(33) "Property [ public static $stat ] +" +export(): +string(33) "Property [ public static $stat ] +" +export(): +Property [ public static $stat ] + +NULL +getName(): +string(4) "stat" +isPublic(): +bool(true) +isPrivate(): +bool(false) +isProtected(): +bool(false) +isStatic(): +bool(true) +getValue(): +string(15) "static property" +getValue() after a setValue(): +string(8) "NewValue" + +********************************** +********************************** +Reflecting on property TestClass::prot + +__toString(): +string(39) "Property [ <default> protected $prot ] +" +export(): +string(39) "Property [ <default> protected $prot ] +" +export(): +Property [ <default> protected $prot ] + +NULL +getName(): +string(4) "prot" +isPublic(): +bool(false) +isPrivate(): +bool(false) +isProtected(): +bool(true) +isStatic(): +bool(false) + +********************************** +********************************** +Reflecting on property TestClass::priv + +__toString(): +string(37) "Property [ <default> private $priv ] +" +export(): +string(37) "Property [ <default> private $priv ] +" +export(): +Property [ <default> private $priv ] + +NULL +getName(): +string(4) "priv" +isPublic(): +bool(false) +isPrivate(): +bool(true) +isProtected(): +bool(false) +isStatic(): +bool(false) + +********************************** + + diff --git a/ext/reflection/tests/reflectionProperty_basic2.phpt b/ext/reflection/tests/reflectionProperty_basic2.phpt new file mode 100644 index 0000000000..f2b5ff4fb9 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test usage of ReflectionProperty methods isDefault(), getModifiers(), getDeclaringClass() and getDocComment(). +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +function reflectProperty($class, $property) { + $propInfo = new ReflectionProperty($class, $property); + echo "**********************************\n"; + echo "Reflecting on property $class::$property\n\n"; + echo "isDefault():\n"; + var_dump($propInfo->isDefault()); + echo "getModifiers():\n"; + var_dump($propInfo->getModifiers()); + echo "getDeclaringClass():\n"; + var_dump($propInfo->getDeclaringClass()); + echo "getDocComment():\n"; + var_dump($propInfo->getDocComment()); + echo "\n**********************************\n"; +} + +class TestClass { + public $pub; + static public $stat = "static property"; + /** + * This property has a comment. + */ + protected $prot = 4; + private $priv = "keepOut"; +} + +reflectProperty("TestClass", "pub"); +reflectProperty("TestClass", "stat"); +reflectProperty("TestClass", "prot"); +reflectProperty("TestClass", "priv"); + +?> +--EXPECTF-- +********************************** +Reflecting on property TestClass::pub + +isDefault(): +bool(true) +getModifiers(): +int(256) +getDeclaringClass(): +object(ReflectionClass)#%d (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +bool(false) + +********************************** +********************************** +Reflecting on property TestClass::stat + +isDefault(): +bool(true) +getModifiers(): +int(257) +getDeclaringClass(): +object(ReflectionClass)#%d (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +bool(false) + +********************************** +********************************** +Reflecting on property TestClass::prot + +isDefault(): +bool(true) +getModifiers(): +int(512) +getDeclaringClass(): +object(ReflectionClass)#%d (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +string(%d) "/** + * This property has a comment. + */" + +********************************** +********************************** +Reflecting on property TestClass::priv + +isDefault(): +bool(true) +getModifiers(): +int(1024) +getDeclaringClass(): +object(ReflectionClass)#%d (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +bool(false) + +********************************** diff --git a/ext/reflection/tests/reflectionProperty_constructor_error.phpt b/ext/reflection/tests/reflectionProperty_constructor_error.phpt new file mode 100644 index 0000000000..46cdc87ea9 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_constructor_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test ReflectionProperty class constructor errors. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class TestClass { +} + +$a = 5; + +echo "Non-existent class:\n"; +try { + $propInfo = new ReflectionProperty("NonExistentClass", "prop"); +} +catch(Exception $e) { + echo $e->getMessage(); +} + +echo "\n\nWrong property parameter type:\n"; +try { + $propInfo = new ReflectionProperty($a, 'TestClass'); +} +catch(ReflectionException $e) { + echo $e->getMessage(); +} + +echo "\n\nNon-existent property:\n"; +try { + $propInfo = new ReflectionProperty('TestClass', "nonExistentProperty"); +} +catch(Exception $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Non-existent class: +Class NonExistentClass does not exist + +Wrong property parameter type: +The parameter class is expected to be either a string or an object + +Non-existent property: +Property TestClass::$nonExistentProperty does not exist diff --git a/ext/reflection/tests/reflectionProperty_error.phpt b/ext/reflection/tests/reflectionProperty_error.phpt new file mode 100644 index 0000000000..bae255c232 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_error.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test ReflectionProperty class errors. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class C { + public static $p; +} + +var_dump(new ReflectionProperty()); +var_dump(new ReflectionProperty('C::p')); +var_dump(new ReflectionProperty('C', 'p', 'x')); +$rp = new ReflectionProperty('C', 'p'); +var_dump($rp->getName(1)); +var_dump($rp->isPrivate(1)); +var_dump($rp->isProtected(1)); +var_dump($rp->isPublic(1)); +var_dump($rp->isStatic(1)); +var_dump($rp->getModifiers(1)); +var_dump($rp->isDefault(1)); + +?> +--EXPECTF-- + +Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given in %s on line %d +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 1 given in %s on line %d +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 3 given in %s on line %d +object(ReflectionProperty)#%d (2) { + ["name"]=> + string(0) "" + ["class"]=> + string(0) "" +} + +Warning: Wrong parameter count for ReflectionProperty::getName() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::isPrivate() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::isProtected() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::isPublic() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::isStatic() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::getModifiers() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::isDefault() in %s on line %d +NULL diff --git a/ext/reflection/tests/reflectionProperty_export_basic.phpt b/ext/reflection/tests/reflectionProperty_export_basic.phpt new file mode 100644 index 0000000000..331fdb6a28 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_export_basic.phpt @@ -0,0 +1,18 @@ +--TEST-- +Test ReflectionProperty::export() usage. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class TestClass { + public $proper = 5; +} + +var_dump(ReflectionProperty::export('TestClass', 'proper')); + +?> +--EXPECT-- +Property [ <default> public $proper ] + +NULL diff --git a/ext/reflection/tests/reflectionProperty_export_error.phpt b/ext/reflection/tests/reflectionProperty_export_error.phpt new file mode 100644 index 0000000000..9351846f6b --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_export_error.phpt @@ -0,0 +1,56 @@ +--TEST-- +Test ReflectionProperty::export() errors. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class TestClass { +} + +$a = 5; + +echo "Non-existent class:\n"; +try { + ReflectionProperty::export("NonExistentClass", "prop", true); +} +catch(Exception $e) { + echo $e->getMessage(); +} + +echo "\n\nWrong property parameter type:\n"; +try { + ReflectionProperty::export($a, 'TestClass', false); +} +catch(ReflectionException $e) { + echo $e->getMessage(); +} + +echo "\n\nNon-existent property:\n"; +try { + ReflectionProperty::export('TestClass', "nonExistentProperty", true); +} +catch(Exception $e) { + echo $e->getMessage(); +} + +echo "\n\nIncorrect number of args:\n"; +ReflectionProperty::export(); +ReflectionProperty::export('TestClass', "nonExistentProperty", true, false); + +?> +--EXPECTF-- +Non-existent class: +Class NonExistentClass does not exist + +Wrong property parameter type: +The parameter class is expected to be either a string or an object + +Non-existent property: +Property TestClass::$nonExistentProperty does not exist + +Incorrect number of args: + +Warning: ReflectionProperty::export() expects at least 2 parameters, 0 given in %s on line %d + +Warning: ReflectionProperty::export() expects at most 3 parameters, 4 given in %s on line %d diff --git a/ext/reflection/tests/reflectionProperty_getDeclaringClass_variation1.phpt b/ext/reflection/tests/reflectionProperty_getDeclaringClass_variation1.phpt new file mode 100644 index 0000000000..3df3b26055 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_getDeclaringClass_variation1.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test ReflectionProperty::getDeclaringClass() with inherited properties. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class A { + public $prop; +} + +class B extends A { +} + +$propInfo = new ReflectionProperty('B', 'prop'); +var_dump($propInfo->getDeclaringClass()); + +echo "Wrong number of params:\n"; +$propInfo->getDeclaringClass(1); + +?> +--EXPECTF-- +object(ReflectionClass)#%d (1) { + ["name"]=> + string(1) "A" +} +Wrong number of params: + +Warning: Wrong parameter count for ReflectionProperty::getDeclaringClass() in %s on line %d diff --git a/ext/reflection/tests/reflectionProperty_getDocComment_basic.phpt b/ext/reflection/tests/reflectionProperty_getDocComment_basic.phpt new file mode 100644 index 0000000000..44416b7fcb --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_getDocComment_basic.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test ReflectionProperty::getDocComment() usage. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class A { + /** + * My Doc Comment for $a + * + */ + public $a = 2, $b, $c = 1; + /** + * My Doc Comment for $d + */ + var $d; + /**Not a doc comment */ + private $e; + /** + * Doc comment for $f + */ + static protected $f; +} + +class B extends A { + public $a = 2; + /** A doc comment for $b */ + var $b, $c = 1; + /** A doc comment for $e */ + var $e; +} + +foreach(array('A', 'B') as $class) { + $rc = new ReflectionClass($class); + $rps = $rc->getProperties(); + foreach($rps as $rp) { + echo "\n\n---> Doc comment for $class::$" . $rp->getName() . ":\n"; + var_dump($rp->getDocComment()); + } +} + +?> +--EXPECTF-- + +---> Doc comment for A::$a: +string(%d) "/** + * My Doc Comment for $a + * + */" + + +---> Doc comment for A::$b: +bool(false) + + +---> Doc comment for A::$c: +bool(false) + + +---> Doc comment for A::$d: +string(%d) "/** + * My Doc Comment for $d + */" + + +---> Doc comment for A::$e: +bool(false) + + +---> Doc comment for A::$f: +string(%d) "/** + * Doc comment for $f + */" + + +---> Doc comment for B::$a: +bool(false) + + +---> Doc comment for B::$b: +string(%d) "/** A doc comment for $b */" + + +---> Doc comment for B::$c: +bool(false) + + +---> Doc comment for B::$e: +string(%d) "/** A doc comment for $e */" + + +---> Doc comment for B::$d: +string(%d) "/** + * My Doc Comment for $d + */" + + +---> Doc comment for B::$f: +string(%d) "/** + * Doc comment for $f + */" diff --git a/ext/reflection/tests/reflectionProperty_getDocComment_error.phpt b/ext/reflection/tests/reflectionProperty_getDocComment_error.phpt new file mode 100644 index 0000000000..8c1b68e81f --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_getDocComment_error.phpt @@ -0,0 +1,31 @@ +--TEST-- +Test ReflectionProperty::getDocComment() errors. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class C { + public $a; +} + +$rc = new ReflectionProperty('C', 'a'); +var_dump($rc->getDocComment(null)); +var_dump($rc->getDocComment('X')); +var_dump($rc->getDocComment(true)); +var_dump($rc->getDocComment(array(1, 2, 3))); + +?> +--EXPECTF-- + +Warning: Wrong parameter count for ReflectionProperty::getDocComment() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::getDocComment() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::getDocComment() in %s on line %d +NULL + +Warning: Wrong parameter count for ReflectionProperty::getDocComment() in %s on line %d +NULL diff --git a/ext/reflection/tests/reflectionProperty_getModifiers_basic.phpt b/ext/reflection/tests/reflectionProperty_getModifiers_basic.phpt new file mode 100644 index 0000000000..907a7e7be2 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_getModifiers_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test ReflectionProperty::getModifiers() usage. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class C { + public $a1; + protected $a2; + private $a3; + static public $a4; + static protected $a5; + static private $a6; +} + +class D extends C { + public $a1; + protected $a2; + private $a3; + static public $a4; + static protected $a5; + static private $a6; +} + +for ($i = 1;$i <= 6;$i++) { + $rp = new ReflectionProperty("C", "a$i"); + echo "C::a$i: "; + var_dump($rp->getModifiers()); + $rp = new ReflectionProperty("D", "a$i"); + echo "D::a$i: "; + var_dump($rp->getModifiers()); +} + +?> +--EXPECTF-- +C::a1: int(256) +D::a1: int(256) +C::a2: int(512) +D::a2: int(512) +C::a3: int(1024) +D::a3: int(3072) +C::a4: int(257) +D::a4: int(257) +C::a5: int(513) +D::a5: int(513) +C::a6: int(1025) +D::a6: int(3073)
\ No newline at end of file diff --git a/ext/reflection/tests/reflectionProperty_getValue_error.phpt b/ext/reflection/tests/reflectionProperty_getValue_error.phpt new file mode 100644 index 0000000000..acfc3b0a09 --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_getValue_error.phpt @@ -0,0 +1,83 @@ +--TEST-- +Test ReflectionProperty::getValue() errors. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class TestClass { + public $pub; + public $pub2 = 5; + static public $stat = "static property"; + protected $prot = 4; + private $priv = "keepOut"; +} + +class AnotherClass { +} + +$instance = new TestClass(); +$instanceWithNoProperties = new AnotherClass(); +$propInfo = new ReflectionProperty('TestClass', 'pub2'); + +echo "Too few args:\n"; +var_dump($propInfo->getValue()); + +echo "\nToo many args:\n"; +var_dump($propInfo->getValue($instance, true)); + +echo "\nWrong type of arg:\n"; +var_dump($propInfo->getValue(true)); + +echo "\nInstance without property:\n"; +$propInfo = new ReflectionProperty('TestClass', 'stat'); + +echo "\nStatic property / too many args:\n"; +var_dump($propInfo->getValue($instance, true)); + +echo "\nStatic property / wrong type of arg:\n"; +var_dump($propInfo->getValue(true)); + +echo "\nProtected property:\n"; +try { + $propInfo = new ReflectionProperty('TestClass', 'prot'); + var_dump($propInfo->getValue($instance)); +} +catch(Exception $exc) { + echo $exc->getMessage(); +} + +echo "\n\nInstance without property:\n"; +$propInfo = new ReflectionProperty('TestClass', 'pub2'); +var_dump($propInfo->getValue($instanceWithNoProperties)); + +?> +--EXPECTF-- +Too few args: + +Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +Too many args: + +Warning: ReflectionProperty::getValue() expects exactly 1 parameter, 2 given in %s on line %d +NULL + +Wrong type of arg: + +Warning: ReflectionProperty::getValue() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Instance without property: + +Static property / too many args: +string(15) "static property" + +Static property / wrong type of arg: +string(15) "static property" + +Protected property: +Cannot access non-public member TestClass::prot + +Instance without property: +NULL diff --git a/ext/reflection/tests/reflectionProperty_isDefault_basic.phpt b/ext/reflection/tests/reflectionProperty_isDefault_basic.phpt new file mode 100644 index 0000000000..57c3d0f3cc --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_isDefault_basic.phpt @@ -0,0 +1,65 @@ +--TEST-- +Test ReflectionProperty::isDefault() usage. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +function reflectProperty($class, $property) { + $propInfo = new ReflectionProperty($class, $property); + echo "**********************************\n"; + echo "Reflecting on property $class::$property\n\n"; + echo "isDefault():\n"; + var_dump($propInfo->isDefault()); + echo "\n**********************************\n"; +} + +class TestClass { + public $pub; + static public $stat = "static property"; + protected $prot = 4; + private $priv = "keepOut"; +} + +reflectProperty("TestClass", "pub"); +reflectProperty("TestClass", "stat"); +reflectProperty("TestClass", "prot"); +reflectProperty("TestClass", "priv"); + +echo "Wrong number of params:\n"; +$propInfo = new ReflectionProperty('TestClass', 'pub'); +$propInfo->isDefault(1); + +?> +--EXPECTF-- +********************************** +Reflecting on property TestClass::pub + +isDefault(): +bool(true) + +********************************** +********************************** +Reflecting on property TestClass::stat + +isDefault(): +bool(true) + +********************************** +********************************** +Reflecting on property TestClass::prot + +isDefault(): +bool(true) + +********************************** +********************************** +Reflecting on property TestClass::priv + +isDefault(): +bool(true) + +********************************** +Wrong number of params: + +Warning: Wrong parameter count for ReflectionProperty::isDefault() in %s on line %d diff --git a/ext/reflection/tests/reflectionProperty_setValue_error.phpt b/ext/reflection/tests/reflectionProperty_setValue_error.phpt new file mode 100644 index 0000000000..960778235c --- /dev/null +++ b/ext/reflection/tests/reflectionProperty_setValue_error.phpt @@ -0,0 +1,102 @@ +--TEST-- +Test ReflectionProperty::setValue() error cases. +--SKIPIF-- +<?php extension_loaded('reflection') or die('skip'); ?> +--FILE-- +<?php + +class TestClass { + public $pub; + public $pub2 = 5; + static public $stat = "static property"; + protected $prot = 4; + private $priv = "keepOut"; +} + +class AnotherClass { +} + +$instance = new TestClass(); +$instanceWithNoProperties = new AnotherClass(); +$propInfo = new ReflectionProperty('TestClass', 'pub2'); + +echo "Too few args:\n"; +var_dump($propInfo->setValue()); +var_dump($propInfo->setValue($instance)); + +echo "\nToo many args:\n"; +var_dump($propInfo->setValue($instance, "NewValue", true)); + +echo "\nWrong type of arg:\n"; +var_dump($propInfo->setValue(true, "NewValue")); +$propInfo = new ReflectionProperty('TestClass', 'stat'); + +echo "\nStatic property / too many args:\n"; +var_dump($propInfo->setValue($instance, "NewValue", true)); + +echo "\nStatic property / too few args:\n"; +var_dump($propInfo->setValue("A new value")); +var_dump(TestClass::$stat); +var_dump($propInfo->setValue()); +var_dump(TestClass::$stat); + +echo "\nStatic property / wrong type of arg:\n"; +var_dump($propInfo->setValue(true, "Another new value")); +var_dump(TestClass::$stat); + +echo "\nProtected property:\n"; +try { + $propInfo = new ReflectionProperty('TestClass', 'prot'); + var_dump($propInfo->setValue($instance, "NewValue")); +} +catch(Exception $exc) { + echo $exc->getMessage(); +} + +echo "\n\nInstance without property:\n"; +$propInfo = new ReflectionProperty('TestClass', 'pub2'); +var_dump($propInfo->setValue($instanceWithNoProperties, "NewValue")); +var_dump($instanceWithNoProperties->pub2); +?> +--EXPECTF-- +Too few args: + +Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 0 given in %s on line %d +NULL + +Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 1 given in %s on line %d +NULL + +Too many args: + +Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +Wrong type of arg: + +Warning: ReflectionProperty::setValue() expects parameter 1 to be object, boolean given in %s on line %d +NULL + +Static property / too many args: + +Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 3 given in %s on line %d +NULL + +Static property / too few args: +NULL +string(11) "A new value" + +Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 0 given in %s on line %d +NULL +string(11) "A new value" + +Static property / wrong type of arg: +NULL +string(17) "Another new value" + +Protected property: +Cannot access non-public member TestClass::prot + +Instance without property: +NULL +string(8) "NewValue" |