note 99661 added to class.reflectionproperty
| From: | james at digitaledgeit dot com dot au | Date: | Mon, 30 Aug 2010 03:22:45 +0000 |
| Subject: | note 99661 added to class.reflectionproperty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172150@lists.php.net to get a copy of this message | ||
You CAN reflect an object at runtime:
<?php
class Abc {
private $_abc = 123;
public function __construct($abc) {
$this->_abc = $abc;
}
}
$obj = new Abc('def');
$refl = new \ReflectionObject($obj);
$prop = $refl->getProperty('_abc');
$prop->setAccessible(true);
echo $prop->getValue($obj);
?>
This outputs 'def', the value of _abc set at runtime.
----
Server IP: 69.147.83.197
Probable Submitter: 220.253.76.40
----
Manual Page -- http://www.php.net/manual/en/class.reflectionproperty.php
Edit -- https://master.php.net/note/edit/99661
Del: integrated -- https://master.php.net/note/delete/99661/integrated
Del: useless -- https://master.php.net/note/delete/99661/useless
Del: bad code -- https://master.php.net/note/delete/99661/bad+code
Del: spam -- https://master.php.net/note/delete/99661/spam
Del: non-english -- https://master.php.net/note/delete/99661/non-english
Del: in docs -- https://master.php.net/note/delete/99661/in+docs
Del: other reasons-- https://master.php.net/note/delete/99661
Reject -- https://master.php.net/note/reject/99661
Search -- https://master.php.net/manage/user-notes.php