@@ -1793,16 +1793,7 @@ ZEND_API void object_properties_load(zend_object *object, const HashTable *prope
17931793static zend_always_inline zend_result _object_and_properties_init (zval * arg , zend_class_entry * class_type , HashTable * properties ) /* {{{ */
17941794{
17951795 if (UNEXPECTED (class_type -> ce_flags & ZEND_ACC_UNINSTANTIABLE )) {
1796- if (class_type -> ce_flags & ZEND_ACC_INTERFACE ) {
1797- zend_throw_error (NULL , "Cannot instantiate interface %s" , ZSTR_VAL (class_type -> name ));
1798- } else if (class_type -> ce_flags & ZEND_ACC_TRAIT ) {
1799- zend_throw_error (NULL , "Cannot instantiate trait %s" , ZSTR_VAL (class_type -> name ));
1800- } else if (class_type -> ce_flags & ZEND_ACC_ENUM ) {
1801- zend_throw_error (NULL , "Cannot instantiate enum %s" , ZSTR_VAL (class_type -> name ));
1802- } else {
1803- ZEND_ASSERT (class_type -> ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS |ZEND_ACC_EXPLICIT_ABSTRACT_CLASS ));
1804- zend_throw_error (NULL , "Cannot instantiate abstract class %s" , ZSTR_VAL (class_type -> name ));
1805- }
1796+ zend_cannot_instantiate_class (class_type , NULL );
18061797 ZVAL_NULL (arg );
18071798 Z_OBJ_P (arg ) = NULL ;
18081799 return FAILURE ;
@@ -1846,25 +1837,7 @@ ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *class_type) /*
18461837
18471838ZEND_API zend_result object_init_with_constructor (zval * arg , zend_class_entry * class_type , uint32_t param_count , zval * params , HashTable * named_params ) /* {{{ */
18481839{
1849- zend_function * constructor = class_type -> constructor ;
1850- if (UNEXPECTED (constructor == NULL )) {
1851- const zend_attribute * non_instantiable_class = zend_get_attribute_str (class_type -> attributes , ZEND_STRL ("noninstantiableclass" ));
1852- ZEND_ASSERT (non_instantiable_class );
1853- zend_string * msg = Z_STR (non_instantiable_class -> args [0 ].value );
1854- zend_throw_error (NULL , "%s" , ZSTR_VAL (msg ));
1855- ZVAL_UNDEF (arg );
1856- return FAILURE ;
1857- }
1858-
1859- if (UNEXPECTED (!(constructor -> common .fn_flags & ZEND_ACC_PUBLIC ))) {
1860- /* Use zend_bad_constructor_call() somehow? */
1861- zend_throw_error (
1862- NULL ,
1863- "Call to %s %s::%s() from global scope" ,
1864- zend_visibility_string (class_type -> constructor -> common .fn_flags ),
1865- ZSTR_VAL (class_type -> constructor -> common .scope -> name ),
1866- ZSTR_VAL (class_type -> constructor -> common .function_name )
1867- );
1840+ if (UNEXPECTED (!zend_check_class_is_instantiable_or_throw (class_type , zend_get_executed_scope ()))) {
18681841 ZVAL_UNDEF (arg );
18691842 return FAILURE ;
18701843 }
@@ -1876,8 +1849,9 @@ ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *c
18761849 }
18771850 zend_object * obj = Z_OBJ_P (arg );
18781851
1879- /* Fake constructor means we don't need to call the constructor actually */
1880- if (zend_is_pass_function (constructor )) {
1852+ zend_function * constructor = class_type -> constructor ;
1853+ /* No constructor, so no need to call it */
1854+ if (constructor == NULL ) {
18811855 /* Surprisingly, this is the only case where internal classes will allow to pass extra arguments
18821856 * However, if there are named arguments (and it is not empty),
18831857 * an Error must be thrown to be consistent with new ClassName() */
@@ -3523,11 +3497,6 @@ static zend_class_entry *do_register_internal_class(const zend_class_entry *orig
35233497 if (class_entry -> info .internal .builtin_functions ) {
35243498 zend_register_functions (class_entry , class_entry -> info .internal .builtin_functions , & class_entry -> function_table , EG (current_module )-> type );
35253499 }
3526-
3527- /* Assign the pass function as a default constructor */
3528- if (class_entry -> constructor == NULL ) {
3529- class_entry -> constructor = (zend_function * ) & zend_pass_function ;
3530- }
35313500
35323501 lowercase_name = zend_string_tolower_ex (orig_class_entry -> name , EG (current_module )-> type == MODULE_PERSISTENT );
35333502 lowercase_name = zend_new_interned_string (lowercase_name );
0 commit comments