note 98643 added to reflectionproperty.getvalue

From: Date: Mon, 28 Jun 2010 22:48:31 +0000
Subject: note 98643 added to reflectionproperty.getvalue
Groups: php.notes 
Request: Send a blank email to php-notes+get-170532@lists.php.net to get a copy of this message
To allow protected and private properties to be accessed, you should use ReflectionProperty::setAccessible(bool $accessible): <?php /** Class Foo with protected and private members */ class Foo { protected $bar = 'barrr!'; private $baz = 'bazzz!'; } $reflFoo = new ReflectionClass('Foo'); $reflBar = $reflFoo->getProperty('bar'); $reflBaz = $reflFoo->getProperty('baz'); // Set private and protected members accessible for getValue/setValue $reflBar->setAccessible(true); $reflBaz->setAccessible(true); $foo = new Foo(); echo $reflBar->getValue($foo); // will output "barrr!" echo $reflBaz->getValue($foo); // will output "bazzz!" // You can also setValue $reflBar->setValue($foo, "new value"); echo $reflBar->getValue($foo); // will output "new value" ?> ---- Server IP: 213.186.192.247 Probable Submitter: 178.93.52.211 ---- Manual Page -- http://www.php.net/manual/en/reflectionproperty.getvalue.php Edit -- https://master.php.net/note/edit/98643 Del: integrated -- https://master.php.net/note/delete/98643/integrated Del: useless -- https://master.php.net/note/delete/98643/useless Del: bad code -- https://master.php.net/note/delete/98643/bad+code Del: spam -- https://master.php.net/note/delete/98643/spam Del: non-english -- https://master.php.net/note/delete/98643/non-english Del: in docs -- https://master.php.net/note/delete/98643/in+docs Del: other reasons-- https://master.php.net/note/delete/98643 Reject -- https://master.php.net/note/reject/98643 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170532) next »