note 119413 rejected from class.reflectionproperty by cmb
| From: | cmb@php.net | Date: | Wed, 01 Jun 2016 16:49:08 +0000 |
| Subject: | note 119413 rejected from class.reflectionproperty by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-205630@lists.php.net to get a copy of this message | ||
Note Submitter: madridserginho at hotmail dot com
----
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.