1--TEST-- 2Test ReflectionProperty::setValue() error cases. 3--FILE-- 4<?php 5 6class TestClass { 7 public $pub; 8 public $pub2 = 5; 9 static public $stat = "static property"; 10 protected $prot = 4; 11 private $priv = "keepOut"; 12} 13 14class AnotherClass { 15} 16 17$instance = new TestClass(); 18$instanceWithNoProperties = new AnotherClass(); 19$propInfo = new ReflectionProperty('TestClass', 'pub2'); 20 21echo "Too few args:\n"; 22var_dump($propInfo->setValue()); 23var_dump($propInfo->setValue($instance)); 24 25echo "\nToo many args:\n"; 26var_dump($propInfo->setValue($instance, "NewValue", true)); 27 28echo "\nWrong type of arg:\n"; 29var_dump($propInfo->setValue(true, "NewValue")); 30$propInfo = new ReflectionProperty('TestClass', 'stat'); 31 32echo "\nStatic property / too many args:\n"; 33var_dump($propInfo->setValue($instance, "NewValue", true)); 34 35echo "\nStatic property / too few args:\n"; 36var_dump($propInfo->setValue("A new value")); 37var_dump(TestClass::$stat); 38var_dump($propInfo->setValue()); 39var_dump(TestClass::$stat); 40 41echo "\nStatic property / wrong type of arg:\n"; 42var_dump($propInfo->setValue(true, "Another new value")); 43var_dump(TestClass::$stat); 44 45echo "\nProtected property:\n"; 46try { 47 $propInfo = new ReflectionProperty('TestClass', 'prot'); 48 var_dump($propInfo->setValue($instance, "NewValue")); 49} 50catch(Exception $exc) { 51 echo $exc->getMessage(); 52} 53 54echo "\n\nInstance without property:\n"; 55$propInfo = new ReflectionProperty('TestClass', 'pub2'); 56var_dump($propInfo->setValue($instanceWithNoProperties, "NewValue")); 57var_dump($instanceWithNoProperties->pub2); 58?> 59--EXPECTF-- 60Too few args: 61 62Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 0 given in %s on line %d 63NULL 64 65Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 1 given in %s on line %d 66NULL 67 68Too many args: 69 70Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 3 given in %s on line %d 71NULL 72 73Wrong type of arg: 74 75Warning: ReflectionProperty::setValue() expects parameter 1 to be object, boolean given in %s on line %d 76NULL 77 78Static property / too many args: 79 80Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 3 given in %s on line %d 81NULL 82 83Static property / too few args: 84NULL 85string(11) "A new value" 86 87Warning: ReflectionProperty::setValue() expects exactly 2 parameters, 0 given in %s on line %d 88NULL 89string(11) "A new value" 90 91Static property / wrong type of arg: 92NULL 93string(17) "Another new value" 94 95Protected property: 96Cannot access non-public member TestClass::prot 97 98Instance without property: 99NULL 100string(8) "NewValue" 101