|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2011-04-28 12:45 UTC] jeroen at asystance dot nl
 Description: ------------ --- From manual page: http://www.php.net/reflectionclass.setstaticpropertyvalue#Description --- ReflectionClass::getProperties() shows public, protected and private members, but ReflectionClass::setStaticPropertyValue throws a fatal error if a protected or private member is set. The error message says that "Class Tehst does not have a property named prot", which is plain wrong. Test script: --------------- <?php class Tehst { public static $pub = 'pub'; protected static $prot = 'prot'; private static $priv = 'priv'; } $rT = new ReflectionClass( 'Tehst' ); var_export( $rT->getProperties() ); $rT->setStaticPropertyValue( 'pub', 'myPub' ); $rT->setStaticPropertyValue( 'prot', 'myProt' ); $rT->setStaticPropertyValue( 'priv', 'myPriv' ); ?> Expected result: ---------------- array ( 0 => ReflectionProperty::__set_state(array( 'name' => 'pub', 'class' => 'Tehst', )), 1 => ReflectionProperty::__set_state(array( 'name' => 'prot', 'class' => 'Tehst', )), 2 => ReflectionProperty::__set_state(array( 'name' => 'priv', 'class' => 'Tehst', )), )pub: myPub Actual result: -------------- array ( 0 => ReflectionProperty::__set_state(array( 'name' => 'pub', 'class' => 'Tehst', )), 1 => ReflectionProperty::__set_state(array( 'name' => 'prot', 'class' => 'Tehst', )), 2 => ReflectionProperty::__set_state(array( 'name' => 'priv', 'class' => 'Tehst', )), )pub: myPub PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Class Tehst does not have a property named prot' in /home/jay/public_html/alis/newfile.php:14 Stack trace: #0 /home/jay/public_html/alis/newfile.php(14): ReflectionClass->setStaticPropertyValue('prot', 'myProt') #1 {main} thrown in /home/jay/public_html/alis/newfile.php on line 14 Fatal error: Uncaught exception 'ReflectionException' with message 'Class Tehst does not have a property named prot' in /home/jay/public_html/alis/newfile.php:14 Stack trace: #0 /home/jay/public_html/alis/newfile.php(14): ReflectionClass->setStaticPropertyValue('prot', 'myProt') #1 {main} thrown in /home/jay/public_html/alis/newfile.php on line 14 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 22:00:01 2025 UTC | 
I can reproduce this, still I think that in this case, protecting the private and protected resources is the correct behavior. You might want to check this: $rT = new ReflectionClass( 'Tehst' ); var_dump( $s = $rT->getProperty('prot') ); var_dump( $s->isStatic() ); $s->setAccessible(1); $s->setValue("myProt"); var_dump( $s->getValue() );