Skip to content

Commit 1ac484d

Browse files
committed
- Fixed bug #53366 (Reflection doesnt get dynamic property value from getProperty())
1 parent 78f1048 commit 1ac484d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
EXTR_OVERWRITE. (jorto at redhat dot com)
88
- Fixed crashes on invalid parameters in intl extension (Stas, Maksymilian
99
Arciemowicz)
10+
- Fixed bug #53366 (Reflection doesnt get dynamic property value from
11+
getProperty()). (Felipe)
1012
- Fixed bug #53362 (Segmentation fault when extending SplFixedArray). (Felipe)
1113
- Fixed bug #50987 (unaligned memory access in phar.c).
1214
(geissert at debian dot org, Ilia)

ext/reflection/php_reflection.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ typedef enum {
190190
REF_TYPE_OTHER, /* Must be 0 */
191191
REF_TYPE_FUNCTION,
192192
REF_TYPE_PARAMETER,
193-
REF_TYPE_PROPERTY
193+
REF_TYPE_PROPERTY,
194+
REF_TYPE_DYNAMIC_PROPERTY
194195
} reflection_type_t;
195196

196197
/* Struct for reflection objects */
@@ -272,6 +273,7 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC)
272273
{
273274
reflection_object *intern = (reflection_object *) object;
274275
parameter_reference *reference;
276+
property_reference *prop_reference;
275277

276278
if (intern->ptr) {
277279
switch (intern->ref_type) {
@@ -286,6 +288,11 @@ static void reflection_free_objects_storage(void *object TSRMLS_DC)
286288
case REF_TYPE_PROPERTY:
287289
efree(intern->ptr);
288290
break;
291+
case REF_TYPE_DYNAMIC_PROPERTY:
292+
prop_reference = (property_reference*)intern->ptr;
293+
efree(prop_reference->prop.name);
294+
efree(intern->ptr);
295+
break;
289296
case REF_TYPE_OTHER:
290297
break;
291298
}
@@ -3583,13 +3590,15 @@ ZEND_METHOD(reflection_class, getProperty)
35833590
if (zend_hash_exists(Z_OBJ_HT_P(intern->obj)->get_properties(intern->obj TSRMLS_CC), name, name_len+1)) {
35843591
zend_property_info property_info_tmp;
35853592
property_info_tmp.flags = ZEND_ACC_IMPLICIT_PUBLIC;
3586-
property_info_tmp.name = name;
3593+
property_info_tmp.name = estrndup(name, name_len);
35873594
property_info_tmp.name_length = name_len;
35883595
property_info_tmp.h = zend_get_hash_value(name, name_len+1);
35893596
property_info_tmp.doc_comment = NULL;
35903597
property_info_tmp.ce = ce;
35913598

35923599
reflection_property_factory(ce, &property_info_tmp, return_value TSRMLS_CC);
3600+
intern = (reflection_object *) zend_object_store_get_object(return_value TSRMLS_CC);
3601+
intern->ref_type = REF_TYPE_DYNAMIC_PROPERTY;
35933602
return;
35943603
}
35953604
}

ext/reflection/tests/bug53366.phpt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #53366 (Reflection doesnt get dynamic property value from getProperty())
3+
--FILE--
4+
<?php
5+
6+
class UserClass {
7+
}
8+
9+
$myClass = new UserClass;
10+
$myClass->id = 1000;
11+
12+
$reflect = new ReflectionObject($myClass);
13+
14+
var_dump($reflect->getProperty('id'));
15+
var_dump($reflect->getProperty('id')->getValue($myClass));
16+
17+
?>
18+
--EXPECTF--
19+
object(ReflectionProperty)#%d (2) {
20+
["name"]=>
21+
string(2) "id"
22+
["class"]=>
23+
string(9) "UserClass"
24+
}
25+
int(1000)

0 commit comments

Comments
 (0)