Skip to content

Commit d891b5f

Browse files
committed
Fixed bug #78410
1 parent b0394ba commit d891b5f

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ PHP NEWS
1717
. Fixed bug #78391 (Assertion failure in openssl_random_pseudo_bytes).
1818
(Nikita)
1919

20+
- Reflection:
21+
. Fixed bug #78410 (Cannot "manually" unserialize class that is final and
22+
extends an internal one). (Nikita)
23+
2024
08 Aug 2019, PHP 7.4.0beta2
2125

2226
- Core:

ext/reflection/php_reflection.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4589,7 +4589,7 @@ ZEND_METHOD(reflection_class, isInstance)
45894589
}
45904590
/* }}} */
45914591

4592-
/* {{{ proto public stdclass ReflectionClass::newInstance(mixed* args, ...)
4592+
/* {{{ proto public object ReflectionClass::newInstance(mixed* args, ...)
45934593
Returns an instance of this class */
45944594
ZEND_METHOD(reflection_class, newInstance)
45954595
{
@@ -4663,7 +4663,7 @@ ZEND_METHOD(reflection_class, newInstance)
46634663
}
46644664
/* }}} */
46654665

4666-
/* {{{ proto public stdclass ReflectionClass::newInstanceWithoutConstructor()
4666+
/* {{{ proto public object ReflectionClass::newInstanceWithoutConstructor()
46674667
Returns an instance of this class without invoking its constructor */
46684668
ZEND_METHOD(reflection_class, newInstanceWithoutConstructor)
46694669
{
@@ -4672,7 +4672,8 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor)
46724672

46734673
GET_REFLECTION_OBJECT_PTR(ce);
46744674

4675-
if (ce->create_object != NULL && ce->ce_flags & ZEND_ACC_FINAL) {
4675+
if (ce->type == ZEND_INTERNAL_CLASS
4676+
&& ce->create_object != NULL && (ce->ce_flags & ZEND_ACC_FINAL)) {
46764677
zend_throw_exception_ex(reflection_exception_ptr, 0, "Class %s is an internal class marked as final that cannot be instantiated without invoking its constructor", ZSTR_VAL(ce->name));
46774678
return;
46784679
}
@@ -4681,7 +4682,7 @@ ZEND_METHOD(reflection_class, newInstanceWithoutConstructor)
46814682
}
46824683
/* }}} */
46834684

4684-
/* {{{ proto public stdclass ReflectionClass::newInstanceArgs([array args])
4685+
/* {{{ proto public object ReflectionClass::newInstanceArgs([array args])
46854686
Returns an instance of this class */
46864687
ZEND_METHOD(reflection_class, newInstanceArgs)
46874688
{

ext/reflection/tests/ReflectionClass_newInstanceWithoutConstructor.phpt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,29 @@ $class = new ReflectionClass('DateTime');
2222
var_dump($class->newInstanceWithoutConstructor());
2323

2424
$class = new ReflectionClass('Generator');
25+
try {
26+
var_dump($class->newInstanceWithoutConstructor());
27+
} catch (ReflectionException $e) {
28+
echo $e->getMessage(), "\n";
29+
}
30+
31+
final class Bar extends ArrayObject {
32+
}
33+
34+
$class = new ReflectionClass('Bar');
2535
var_dump($class->newInstanceWithoutConstructor());
36+
37+
?>
2638
--EXPECTF--
2739
object(Foo)#%d (0) {
2840
}
2941
object(stdClass)#%d (0) {
3042
}
3143
object(DateTime)#%d (0) {
3244
}
33-
34-
Fatal error: Uncaught ReflectionException: Class Generator is an internal class marked as final that cannot be instantiated without invoking its constructor in %sReflectionClass_newInstanceWithoutConstructor.php:%d
35-
Stack trace:
36-
#0 %sReflectionClass_newInstanceWithoutConstructor.php(%d): ReflectionClass->newInstanceWithoutConstructor()
37-
#1 {main}
38-
thrown in %sReflectionClass_newInstanceWithoutConstructor.php on line %d
45+
Class Generator is an internal class marked as final that cannot be instantiated without invoking its constructor
46+
object(Bar)#%d (1) {
47+
["storage":"ArrayObject":private]=>
48+
array(0) {
49+
}
50+
}

0 commit comments

Comments
 (0)