@@ -6010,6 +6010,25 @@ static void zend_check_magic_method_attr(uint32_t attr, const char* method, zend
6010
6010
}
6011
6011
/* }}} */
6012
6012
6013
+ static void add_stringable_interface (zend_class_entry * ce ) {
6014
+ for (uint32_t i = 0 ; i < ce -> num_interfaces ; i ++ ) {
6015
+ if (zend_string_equals_literal (ce -> interface_names [i ].lc_name , "stringable" )) {
6016
+ /* Interface already explicitly implemented */
6017
+ return ;
6018
+ }
6019
+ }
6020
+
6021
+ ce -> ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES ;
6022
+ ce -> num_interfaces ++ ;
6023
+ ce -> interface_names =
6024
+ erealloc (ce -> interface_names , sizeof (zend_class_name ) * ce -> num_interfaces );
6025
+ // TODO: Add known interned strings instead?
6026
+ ce -> interface_names [ce -> num_interfaces - 1 ].name =
6027
+ zend_string_init ("Stringable" , sizeof ("Stringable" ) - 1 , 0 );
6028
+ ce -> interface_names [ce -> num_interfaces - 1 ].lc_name =
6029
+ zend_string_init ("stringable" , sizeof ("stringable" ) - 1 , 0 );
6030
+ }
6031
+
6013
6032
void zend_begin_method_decl (zend_op_array * op_array , zend_string * name , zend_bool has_body ) /* {{{ */
6014
6033
{
6015
6034
zend_class_entry * ce = CG (active_class_entry );
@@ -6091,6 +6110,7 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
6091
6110
} else if (zend_string_equals_literal (lcname , ZEND_TOSTRING_FUNC_NAME )) {
6092
6111
zend_check_magic_method_attr (fn_flags , "__toString" , 0 );
6093
6112
ce -> __tostring = (zend_function * ) op_array ;
6113
+ add_stringable_interface (ce );
6094
6114
} else if (zend_string_equals_literal (lcname , ZEND_INVOKE_FUNC_NAME )) {
6095
6115
zend_check_magic_method_attr (fn_flags , "__invoke" , 0 );
6096
6116
} else if (zend_string_equals_literal (lcname , ZEND_DEBUGINFO_FUNC_NAME )) {
@@ -6616,6 +6636,10 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6616
6636
6617
6637
CG (active_class_entry ) = ce ;
6618
6638
6639
+ if (implements_ast ) {
6640
+ zend_compile_implements (implements_ast );
6641
+ }
6642
+
6619
6643
zend_compile_stmt (stmt_ast );
6620
6644
6621
6645
/* Reset lineno for final opcodes and errors */
@@ -6655,10 +6679,6 @@ zend_op *zend_compile_class_decl(zend_ast *ast, zend_bool toplevel) /* {{{ */
6655
6679
}
6656
6680
}
6657
6681
6658
- if (implements_ast ) {
6659
- zend_compile_implements (implements_ast );
6660
- }
6661
-
6662
6682
if ((ce -> ce_flags & (ZEND_ACC_IMPLICIT_ABSTRACT_CLASS |ZEND_ACC_INTERFACE |ZEND_ACC_TRAIT |ZEND_ACC_EXPLICIT_ABSTRACT_CLASS )) == ZEND_ACC_IMPLICIT_ABSTRACT_CLASS ) {
6663
6683
zend_verify_abstract_class (ce );
6664
6684
}
0 commit comments