note 119413 added to class.reflectionproperty
| From: | madridserginho at hotmail dot com | Date: | Wed, 01 Jun 2016 15:37:14 +0000 |
| Subject: | note 119413 added to class.reflectionproperty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205629@lists.php.net to get a copy of this message | ||
I can't override ReflectionProperty methods.
Example:
<?php
class ReflectionPropertyExtended extends ReflectionProperty
{
/**
* Set value even if the property is private or protected
* @param object $object Instance
* @param $value Value
*/
public function setValue($object, $value = null)
{
if ($this->isPrivate() || $this->isProtected()) {
$this->setAccessible(true);
$this->setValue($object, $value);
$this->setAccessible(false);
} else {
$this->setValue($object, $value);
}
}
}
?>
When a test is executed like:
<?php
$test1 = new TestClass('foo');
$metadata = new ReflectionPropertyExtended(get_class($test1), 'attr1');
$metadata->setValue($test1, 'bar');
$this->assertEquals('bar', $test1->getAttr1());
?>
I get an exception like this:
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes)
in /home/travelflag3/php-utils/src/Reflection/ReflectionPropertyExtended.php on line 16
If the method is not overrided and change the name to... for example... setPrivateValue, everything
works.
----
Server IP: 72.52.91.14
Probable Submitter: 212.183.203.5
----
Manual Page -- http://php.net/manual/en/class.reflectionproperty.php
Edit -- https://master.php.net/note/edit/119413
Del: integrated -- https://master.php.net/note/delete/119413/integrated
Del: useless -- https://master.php.net/note/delete/119413/useless
Del: bad code -- https://master.php.net/note/delete/119413/bad+code
Del: spam -- https://master.php.net/note/delete/119413/spam
Del: non-english -- https://master.php.net/note/delete/119413/non-english
Del: in docs -- https://master.php.net/note/delete/119413/in+docs
Del: other reasons-- https://master.php.net/note/delete/119413
Reject -- https://master.php.net/note/reject/119413
Search -- https://master.php.net/manage/user-notes.php