Skip to content

Commit

Permalink
Fixed Bug #60173 (Wrong error message on reflective trait instantiation)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Marr committed Oct 31, 2011
1 parent c4eb5f2 commit 2e5d5e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Zend/tests/traits/bug60173.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Bug #60173 (Wrong error message on reflective trait instantiation)
--FILE--
<?php

trait foo { }

$rc = new ReflectionClass('foo');
$rc->newInstance();

--EXPECTF--
Fatal error: Cannot instantiate trait foo in %s on line %d
4 changes: 3 additions & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,9 @@ ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *class_type
zend_object *object;

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

Expand Down

0 comments on commit 2e5d5e5

Please sign in to comment.