@@ -124,48 +124,23 @@ ZEND_API void zend_objects_destroy_object(zend_object *object)
124124 const zend_op * old_opline_before_exception ;
125125
126126 if (destructor -> op_array .fn_flags & (ZEND_ACC_PRIVATE |ZEND_ACC_PROTECTED )) {
127- if (destructor -> op_array .fn_flags & ZEND_ACC_PRIVATE ) {
128- /* Ensure that if we're calling a private function, we're allowed to do so.
129- */
130- if (EG (current_execute_data )) {
131- zend_class_entry * scope = zend_get_executed_scope ();
132-
133- if (object -> ce != scope ) {
134- zend_throw_error (NULL ,
135- "Call to private %s::__destruct() from %s%s" ,
136- ZSTR_VAL (object -> ce -> name ),
137- scope ? "scope " : "global scope" ,
138- scope ? ZSTR_VAL (scope -> name ) : ""
139- );
140- return ;
141- }
142- } else {
143- zend_error (E_WARNING ,
144- "Call to private %s::__destruct() from global scope during shutdown ignored" ,
145- ZSTR_VAL (object -> ce -> name ));
127+ if (EG (current_execute_data )) {
128+ zend_class_entry * scope = zend_get_executed_scope ();
129+ /* Ensure that if we're calling a protected or private function, we're allowed to do so. */
130+ if (!zend_check_method_accessible (destructor , scope )) {
131+ zend_throw_error (NULL ,
132+ "Call to %s %s::__destruct() from %s%s" ,
133+ zend_visibility_string (destructor -> common .fn_flags ), ZSTR_VAL (object -> ce -> name ),
134+ scope ? "scope " : "global scope" ,
135+ scope ? ZSTR_VAL (scope -> name ) : ""
136+ );
146137 return ;
147138 }
148139 } else {
149- /* Ensure that if we're calling a protected function, we're allowed to do so.
150- */
151- if (EG (current_execute_data )) {
152- zend_class_entry * scope = zend_get_executed_scope ();
153-
154- if (!zend_check_protected (zend_get_function_root_class (destructor ), scope )) {
155- zend_throw_error (NULL ,
156- "Call to protected %s::__destruct() from %s%s" ,
157- ZSTR_VAL (object -> ce -> name ),
158- scope ? "scope " : "global scope" ,
159- scope ? ZSTR_VAL (scope -> name ) : ""
160- );
161- return ;
162- }
163- } else {
164- zend_error (E_WARNING ,
165- "Call to protected %s::__destruct() from global scope during shutdown ignored" ,
166- ZSTR_VAL (object -> ce -> name ));
167- return ;
168- }
140+ zend_error (E_WARNING ,
141+ "Call to %s %s::__destruct() from global scope during shutdown ignored" ,
142+ zend_visibility_string (destructor -> common .fn_flags ), ZSTR_VAL (object -> ce -> name ));
143+ return ;
169144 }
170145 }
171146
0 commit comments