Skip to content

Commit 2e5d5e5

Browse files
author
Stefan Marr
committed
Fixed Bug #60173 (Wrong error message on reflective trait instantiation)
1 parent c4eb5f2 commit 2e5d5e5

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Zend/tests/traits/bug60173.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Bug #60173 (Wrong error message on reflective trait instantiation)
3+
--FILE--
4+
<?php
5+
6+
trait foo { }
7+
8+
$rc = new ReflectionClass('foo');
9+
$rc->newInstance();
10+
11+
--EXPECTF--
12+
Fatal error: Cannot instantiate trait foo in %s on line %d

Zend/zend_API.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,7 +1107,9 @@ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type
11071107
zend_object *object;
11081108

11091109
if (class_type->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
1110-
char *what = class_type->ce_flags & ZEND_ACC_INTERFACE ? "interface" : "abstract class";
1110+
char *what = (class_type->ce_flags & ZEND_ACC_INTERFACE) ? "interface"
1111+
:((class_type->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) ? "trait"
1112+
: "abstract class";
11111113
zend_error(E_ERROR, "Cannot instantiate %s %s", what, class_type->name);
11121114
}
11131115

0 commit comments

Comments
 (0)