]> granicus.if.org Git - php/commitdiff
Fix destructor visibility
authorMarcus Boerger <helly@php.net>
Tue, 1 Jul 2003 19:13:50 +0000 (19:13 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 1 Jul 2003 19:13:50 +0000 (19:13 +0000)
Zend/zend_object_handlers.c
Zend/zend_object_handlers.h
Zend/zend_objects.c

index 0181a0cc4b2f7a5c8385b2ba1c83db57651cff42..20f0450b062093291fe2929358be6e4489699197 100644 (file)
@@ -516,7 +516,7 @@ inline zend_function *zend_check_private(zend_function *fbc, zend_class_entry *c
 
 /* Ensures that we're allowed to call a protected method.
  */
-inline int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope)
+int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope)
 {
        zend_class_entry *fbc_scope = ce;
 
index 4bf801719c901b73ec15536926b5e753d6707b62..7cd01bf4013734b4e74d9803e511f2b4f39597d1 100644 (file)
@@ -104,6 +104,8 @@ zend_bool zend_std_unset_static_property(zend_class_entry *ce, char *property_na
 #define IS_ZEND_STD_OBJECT(z)  ((z).type == IS_OBJECT && (Z_OBJ_HT((z))->get_class_entry != NULL))
 #define HAS_CLASS_ENTRY(z) (Z_OBJ_HT(z)->get_class_entry != NULL)
 
+int zend_check_protected(zend_class_entry *ce, zend_class_entry *scope);
+
 #endif
 
 /*
index 911fc700e52b8a2f8ec81177cb3081b1a5f56f18..e998263626402bf49ca923cab9a116ff86f5c728 100644 (file)
@@ -26,7 +26,9 @@
 
 static inline void zend_objects_call_destructor(zend_object *object, zend_object_handle handle TSRMLS_DC)
 {
-       if (object->ce->destructor) {
+       zend_function *destructor = object->ce->destructor;
+
+       if (destructor) {
                zval *obj;
                zval *destructor_func_name;
                zval *retval_ptr;
@@ -38,13 +40,26 @@ static inline void zend_objects_call_destructor(zend_object *object, zend_object
                obj->value.obj.handlers = &std_object_handlers;
                zval_copy_ctor(obj);
 
-
                /* FIXME: Optimize this so that we use the old_object->ce->destructor function pointer instead of the name */
                MAKE_STD_ZVAL(destructor_func_name);
                destructor_func_name->type = IS_STRING;
                destructor_func_name->value.str.val = estrndup("__destruct", sizeof("__destruct")-1);
                destructor_func_name->value.str.len = sizeof("__destruct")-1;
 
+               if (destructor->op_array.fn_flags & ZEND_ACC_PRIVATE) {
+                       /* Ensure that if we're calling a private function, we're allowed to do so.
+                        */
+                       if (object->ce != EG(scope)) {
+                               zend_error(E_ERROR, "Call to private destructor from context '%s'", EG(scope) ? EG(scope)->name : "");
+                       }
+               } else if ((destructor->common.fn_flags & ZEND_ACC_PROTECTED)) {
+                       /* Ensure that if we're calling a protected function, we're allowed to do so.
+                        */
+                       if (!zend_check_protected(destructor->common.scope, EG(scope))) {
+                               zend_error(E_ERROR, "Call to protected destructor from context '%s'", EG(scope) ? EG(scope)->name : "");
+                       }
+               }
+
                ZEND_INIT_SYMTABLE(&symbol_table);
                
                call_user_function_ex(NULL, &obj, destructor_func_name, &retval_ptr, 0, NULL, 0, &symbol_table TSRMLS_CC);