php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40460 Segfault when calling reflection methods of a dynamic property
Submitted: 2007-02-13 09:54 UTC Modified: 2007-02-13 10:36 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: alexiev at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexiev at gmail dot com
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-13 09:58 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2007-02-13 10:32 UTC] alexiev at gmail dot com
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
 [2007-02-13 10:36 UTC] tony2001@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Duplicate of bug #40431.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 20:01:33 2025 UTC