]> granicus.if.org Git - php/commitdiff
- Fixed bug #53366 (Reflection doesnt get dynamic property value from getProperty())
authorFelipe Pena <felipe@php.net>
Sat, 20 Nov 2010 22:53:55 +0000 (22:53 +0000)
committerFelipe Pena <felipe@php.net>
Sat, 20 Nov 2010 22:53:55 +0000 (22:53 +0000)
NEWS
ext/reflection/php_reflection.c
ext/reflection/tests/bug53366.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 20dc231c8121bed3293bfcfe98fd3e4f69353693..ed83ed21ec98b03c254900a20d65c408275e975a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@
   EXTR_OVERWRITE. (jorto at redhat dot com)
 - Fixed crashes on invalid parameters in intl extension (Stas, Maksymilian
   Arciemowicz)
+- Fixed bug #53366 (Reflection doesnt get dynamic property value from
+  getProperty()). (Felipe)
 - Fixed bug #53362 (Segmentation fault when extending SplFixedArray). (Felipe)
 - Fixed bug #50987 (unaligned memory access in phar.c).
   (geissert at debian dot org, Ilia)
index 7b130f8fd3b3772271d7feda1755322f81491d6f..46e49ccd0c2055f6a7838fa352ecaa17fa572577 100644 (file)
@@ -190,7 +190,8 @@ typedef enum {
        REF_TYPE_OTHER,      /* Must be 0 */
        REF_TYPE_FUNCTION,
        REF_TYPE_PARAMETER,
-       REF_TYPE_PROPERTY
+       REF_TYPE_PROPERTY,
+       REF_TYPE_DYNAMIC_PROPERTY
 } reflection_type_t;
 
 /* Struct for reflection objects */
@@ -272,6 +273,7 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC)
 {
        reflection_object *intern = (reflection_object *) object;
        parameter_reference *reference;
+       property_reference *prop_reference;
 
        if (intern->ptr) {
                switch (intern->ref_type) {
@@ -286,6 +288,11 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC)
                case REF_TYPE_PROPERTY:
                        efree(intern->ptr);
                        break;
+               case REF_TYPE_DYNAMIC_PROPERTY:
+                       prop_reference = (property_reference*)intern->ptr;
+                       efree(prop_reference->prop.name);
+                       efree(intern->ptr);
+                       break;
                case REF_TYPE_OTHER:
                        break;
                }
@@ -3583,13 +3590,15 @@ ZEND_METHOD(reflection_class, getProperty)
                if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) {
                        zend_property_info property_info_tmp;
                        property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC;
-                       property_info_tmp.name = name;
+                       property_info_tmp.name = estrndup(name, name_len);
                        property_info_tmp.name_length = name_len;
                        property_info_tmp.h = zend_get_hash_value(name, name_len+1);
                        property_info_tmp.doc_comment = NULL;
                        property_info_tmp.ce = ce;
 
                        reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC);
+                       intern = (reflection_object *) zend_object_store_get_object(return_value TSRMLS_CC);
+                       intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY;
                        return;
                }
        }
diff --git a/ext/reflection/tests/bug53366.phpt b/ext/reflection/tests/bug53366.phpt
new file mode 100644 (file)
index 0000000..5fb119d
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #53366 (Reflection doesnt get dynamic property value from getProperty())
+--FILE--
+<?php
+
+class UserClass {
+}
+
+$myClass = new UserClass;
+$myClass->id = 1000;
+
+$reflect = new ReflectionObject($myClass);
+
+var_dump($reflect->getProperty('id'));
+var_dump($reflect->getProperty('id')->getValue($myClass));
+
+?>
+--EXPECTF--
+object(ReflectionProperty)#%d (2) {
+  ["name"]=>
+  string(2) "id"
+  ["class"]=>
+  string(9) "UserClass"
+}
+int(1000)