@@ -53,14 +53,22 @@ static zend_object_handlers default_exception_handlers;
53
53
/* {{{ zend_implement_throwable */
54
54
static int zend_implement_throwable (zend_class_entry * interface , zend_class_entry * class_type )
55
55
{
56
- if (instanceof_function (class_type , zend_ce_exception ) || instanceof_function (class_type , zend_ce_error )) {
56
+ /* During the registration of Exception/Error themselves, this may be called before
57
+ * zend_ce_exception and zend_ce_error have been initialized, so handle these explicitly. */
58
+ if (zend_ce_exception && instanceof_function (class_type , zend_ce_exception )) {
57
59
return SUCCESS ;
58
60
}
59
- zend_error_noreturn (E_ERROR , "Class %s cannot implement interface %s, extend %s or %s instead" ,
61
+ if (zend_ce_error && instanceof_function (class_type , zend_ce_error )) {
62
+ return SUCCESS ;
63
+ }
64
+ if (zend_string_equals_literal (class_type -> name , "Exception" )
65
+ || zend_string_equals_literal (class_type -> name , "Error" )) {
66
+ return SUCCESS ;
67
+ }
68
+ zend_error_noreturn (E_ERROR ,
69
+ "Class %s cannot implement interface %s, extend Exception or Error instead" ,
60
70
ZSTR_VAL (class_type -> name ),
61
- ZSTR_VAL (interface -> name ),
62
- ZSTR_VAL (zend_ce_exception -> name ),
63
- ZSTR_VAL (zend_ce_error -> name ));
71
+ ZSTR_VAL (interface -> name ));
64
72
return FAILURE ;
65
73
}
66
74
/* }}} */
@@ -740,52 +748,24 @@ ZEND_METHOD(Exception, __toString)
740
748
}
741
749
/* }}} */
742
750
743
- static void declare_exception_properties (zend_class_entry * ce )
744
- {
745
- zval val ;
746
-
747
- zend_declare_property_string (ce , "message" , sizeof ("message" )- 1 , "" , ZEND_ACC_PROTECTED );
748
- zend_declare_property_string (ce , "string" , sizeof ("string" )- 1 , "" , ZEND_ACC_PRIVATE );
749
- zend_declare_property_long (ce , "code" , sizeof ("code" )- 1 , 0 , ZEND_ACC_PROTECTED );
750
- zend_declare_property_null (ce , "file" , sizeof ("file" )- 1 , ZEND_ACC_PROTECTED );
751
- zend_declare_property_null (ce , "line" , sizeof ("line" )- 1 , ZEND_ACC_PROTECTED );
752
-
753
- ZVAL_EMPTY_ARRAY (& val );
754
- zend_declare_typed_property (
755
- ce , ZSTR_KNOWN (ZEND_STR_TRACE ), & val , ZEND_ACC_PRIVATE , NULL ,
756
- (zend_type ) ZEND_TYPE_INIT_MASK (MAY_BE_ARRAY ));
757
-
758
- ZVAL_NULL (& val );
759
- zend_declare_typed_property (
760
- ce , ZSTR_KNOWN (ZEND_STR_PREVIOUS ), & val , ZEND_ACC_PRIVATE , NULL ,
761
- (zend_type ) ZEND_TYPE_INIT_CE (zend_ce_throwable , /* allow_null */ 1 , 0 ));
762
- }
763
-
764
751
void zend_register_default_exception (void ) /* {{{ */
765
752
{
766
- zend_class_entry ce ;
767
-
768
753
zend_ce_throwable = register_class_Throwable (zend_ce_stringable );
769
754
zend_ce_throwable -> interface_gets_implemented = zend_implement_throwable ;
770
755
771
756
memcpy (& default_exception_handlers , & std_object_handlers , sizeof (zend_object_handlers ));
772
757
default_exception_handlers .clone_obj = NULL ;
773
758
774
- INIT_CLASS_ENTRY (ce , "Exception" , class_Exception_methods );
775
- zend_ce_exception = zend_register_internal_class_ex (& ce , NULL );
759
+ zend_ce_exception = register_class_Exception (zend_ce_throwable );
776
760
zend_ce_exception -> create_object = zend_default_exception_new ;
777
- zend_class_implements (zend_ce_exception , 1 , zend_ce_throwable );
778
- declare_exception_properties (zend_ce_exception );
779
761
780
762
zend_ce_error_exception = register_class_ErrorException (zend_ce_exception );
781
763
zend_ce_error_exception -> create_object = zend_error_exception_new ;
764
+ /* Declared manually because it uses constant E_ERROR. */
782
765
zend_declare_property_long (zend_ce_error_exception , "severity" , sizeof ("severity" )- 1 , E_ERROR , ZEND_ACC_PROTECTED );
783
766
784
- INIT_CLASS_ENTRY (ce , "Error" , class_Error_methods );
785
- zend_ce_error = zend_register_internal_class_ex (& ce , NULL );
767
+ zend_ce_error = register_class_Error (zend_ce_throwable );
786
768
zend_ce_error -> create_object = zend_default_exception_new ;
787
- zend_class_implements (zend_ce_error , 1 , zend_ce_throwable );
788
- declare_exception_properties (zend_ce_error );
789
769
790
770
zend_ce_compile_error = register_class_CompileError (zend_ce_error );
791
771
zend_ce_compile_error -> create_object = zend_default_exception_new ;
0 commit comments