Skip to content

Commit 7f9e739

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #78774
2 parents 7d96dca + c9abfae commit 7f9e739

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

ext/reflection/php_reflection.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,14 @@ static void reflection_free_objects_storage(zend_object *object) /* {{{ */
223223
efree(intern->ptr);
224224
break;
225225
case REF_TYPE_TYPE:
226-
efree(intern->ptr);
226+
{
227+
type_reference *type_ref = intern->ptr;
228+
if (ZEND_TYPE_IS_NAME(type_ref->type)) {
229+
zend_string_release(ZEND_TYPE_NAME(type_ref->type));
230+
}
231+
efree(type_ref);
227232
break;
233+
}
228234
case REF_TYPE_FUNCTION:
229235
_free_function(intern->ptr);
230236
break;
@@ -1137,6 +1143,12 @@ static void reflection_type_factory(zend_type type, zval *object)
11371143
reference->type = type;
11381144
intern->ptr = reference;
11391145
intern->ref_type = REF_TYPE_TYPE;
1146+
1147+
/* Property types may be resolved during the lifetime of the ReflectionType,
1148+
* so we need to make sure that the strings we reference are not released. */
1149+
if (ZEND_TYPE_IS_NAME(type)) {
1150+
zend_string_addref(ZEND_TYPE_NAME(type));
1151+
}
11401152
}
11411153
/* }}} */
11421154

ext/reflection/tests/bug78774.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #78774: ReflectionNamedType on Typed Properties Crash
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public stdClass $prop;
8+
}
9+
10+
$rc = new ReflectionClass(Test::class);
11+
$rp = $rc->getProperty('prop');
12+
$rt = $rp->getType();
13+
14+
// Force a resolution of the property type
15+
$test = new Test;
16+
$test->prop = new stdClass;
17+
18+
var_dump($rt->getName());
19+
20+
?>
21+
--EXPECT--
22+
string(8) "stdClass"

0 commit comments

Comments
 (0)