|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-02-13 09:54 UTC] alexiev at gmail dot com
Description:
------------
The dynamic properties are introduced in php 5.2 The problem I found was when you try to call most of the methods of the ReflectionProperty instance for a dynamic object property, returned with ReflectionObject::getProperties.
Additionally when you use ReflectionObject:;getProperty($property_name) for a dynamic property, an exception is thrown! The metter is duscussed in #37682
Look at the code for more info.
I was able to test only on php 5.2.0! I don't know if the problem still exists in php 5.2.1!
Reproduce code:
---------------
<?php
$i = new stdClass;
$i->dynamic_member = 'value';
$r = new ReflectionObject($i);
// $r->getProperty('dynamic_member'); throws an exception - there is no 'dynamic_member' property?
$properties = $r->getProperties();
var_dump($properties[0]); // Looks OK
var_dump($properties[0]->getName()); // Also OK
echo $properties[0]->isPublic() ? 'public' : 'notpublic'; // Causes Segmentation fault
$properties[0]->isPrivate(); // Causes Segmentation fault
$properties[0]->isProtected(); // Causes Segmentation fault
$properties[0]->isStatic(); // Causes Segmentation fault
$properties[0]->isDefault(); // Causes Segmentation fault
$properties[0]->isPrivate(); // Causes Segmentation fault
?>
Expected result:
----------------
object(ReflectionProperty)#3 (2) {
["name"]=>
string(14) "dynamic_member"
["class"]=>
string(8) "stdClass"
}
string(14) "dynamic_member"
public
Actual result:
--------------
object(ReflectionProperty)#3 (2) {
["name"]=>
string(14) "dynamic_member"
["class"]=>
string(8) "stdClass"
}
string(14) "dynamic_member"
Segmentation fault
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Dec 11 20:00:01 2025 UTC |
Here are the test results: Windows XP PHP 5.2.0 ----- object(ReflectionProperty)#3 (2) { ["name"]=> string(14) "dynamic_member" ["class"]=> string(8) "stdClass" } string(14) "dynamic_member" notpublic Windows XP PHP 5.2.2-dev (cli) (built: Feb 13 2007 08:23:31) ----- object(ReflectionProperty)#3 (2) { ["name"]=> string(14) "dynamic_member" ["class"]=> string(8) "stdClass" } string(14) "dynamic_member" public Linux PHP 5.2.2-dev (cli) (built: Feb 13 2007 12:14:28) ----- object(ReflectionProperty)#3 (2) { ["name"]=> string(14) "dynamic_member" ["class"]=> string(8) "stdClass" } string(14) "dynamic_member" public With Win and PHP 5.2.0 there is no segfault, but the isPublic returned FALSE! If you try the getProperty method on the 'dynamic_member', an exception is still thrown in the snapshot! ---- Fatal error: Uncaught exception 'ReflectionException' with message 'Property dynamic_member does not exist' in /tmp/test.php:5 Stack trace: #0 /tmp/test.php(5): ReflectionClass->getProperty('dynamic_member') #1 {main} thrown in /tmp/test.php on line 5