Hello Zeev, hi Andi,

attached is my idea of finally fixing the destructor visibility. It simply
emits an E_ERROR on an illegal attempt to destruct an object during execution
and emits an E_WARNING with a slighlty longer message in shutdown (outside
execution). Patch attached.
  

-- 
Best regards,
 Marcus                          mailto:[EMAIL PROTECTED]
? tests/classes/lower_visibility.phpt.ignore
? tests/classes/type_hinting_002.phpt
Index: Zend/zend_objects.c
===================================================================
RCS file: /repository/ZendEngine2/zend_objects.c,v
retrieving revision 1.34
diff -u -p -r1.34 zend_objects.c
--- Zend/zend_objects.c 2 Jul 2003 23:58:47 -0000       1.34
+++ Zend/zend_objects.c 3 Jul 2003 13:04:07 -0000
@@ -46,17 +46,28 @@ ZEND_API void zend_objects_destroy_objec
                                /* Ensure that if we're calling a private function, 
we're allowed to do so.
                                 */
                                if (object->ce != EG(scope)) {
+                                       zend_class_entry *ce = object->ce;
+
                                        zend_nuke_object(object TSRMLS_CC); /* 
unfortunately we *must* destroy it now anyway */
-                                       /* this is a E_ERROR in real but we can't do 
that right now because of problems in shutdown */
-                                       zend_error(E_WARNING, "Call to private 
destructor from context '%s'", EG(scope) ? EG(scope)->name : "");
+                                       zend_error(EG(in_execution) ? E_ERROR : 
E_WARNING, 
+                                               "Call to private %s::__destruct from 
context '%s'%s", 
+                                               ce->name, 
+                                               EG(scope) ? EG(scope)->name : "", 
+                                               EG(in_execution) ? "" : " during 
shutdown ignored");
                                        return;
                                }
                        } else {
                                /* 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_class_entry *ce = object->ce;
+
                                        zend_nuke_object(object TSRMLS_CC); /* 
unfortunately we *must* destroy it now anyway */
-                                       zend_error(E_WARNING, "Call to protected 
destructor from context '%s'", EG(scope) ? EG(scope)->name : "");
+                                       zend_error(EG(in_execution) ? E_ERROR : 
E_WARNING, 
+                                               "Call to protected %s::__destruct from 
context '%s'%s", 
+                                               ce->name, 
+                                               EG(scope) ? EG(scope)->name : "", 
+                                               EG(in_execution) ? "" : " during 
shutdown ignored");
                                        return;
                                }
                        }
Index: tests/classes/factory_and_singleton_002.phpt
===================================================================
RCS file: /repository/php-src/tests/classes/factory_and_singleton_002.phpt,v
retrieving revision 1.3
diff -u -p -r1.3 factory_and_singleton_002.phpt
--- tests/classes/factory_and_singleton_002.phpt        3 Jul 2003 07:18:41 -0000      
 1.3
+++ tests/classes/factory_and_singleton_002.phpt        3 Jul 2003 13:04:07 -0000
@@ -19,7 +19,7 @@ class test {
     }
   }
 
-  function __construct($x) {
+  protected function __construct($x) {
     test::$cnt++;
     $this->x = $x;
   }
@@ -28,7 +28,7 @@ class test {
     test::$test = NULL;
   }
 
-  function __destruct() {
+  protected function __destruct() {
        test::$cnt--;
   }
 
@@ -96,3 +96,5 @@ Destruct y
 int(1)
 int(1)
 Done
+
+Warning: Call to protected test::__destruct from context '' during shutdown ignored 
in Unknown on line 0
Index: tests/classes/factory_and_singleton_005.phpt
===================================================================
RCS file: /repository/php-src/tests/classes/factory_and_singleton_005.phpt,v
retrieving revision 1.2
diff -u -p -r1.2 factory_and_singleton_005.phpt
--- tests/classes/factory_and_singleton_005.phpt        3 Jul 2003 07:18:41 -0000      
 1.2
+++ tests/classes/factory_and_singleton_005.phpt        3 Jul 2003 13:04:07 -0000
@@ -16,5 +16,4 @@ $obj = NULL;
 echo "Done\n";
 ?>
 --EXPECTF--
-Warning: Call to protected destructor from context '' in 
%sfactory_and_singleton_005.php on line %d
-Done
+Fatal error: Call to protected test::__destruct from context '' in 
%sfactory_and_singleton_005.php on line %d
Index: tests/classes/factory_and_singleton_006.phpt
===================================================================
RCS file: /repository/php-src/tests/classes/factory_and_singleton_006.phpt,v
retrieving revision 1.2
diff -u -p -r1.2 factory_and_singleton_006.phpt
--- tests/classes/factory_and_singleton_006.phpt        3 Jul 2003 07:18:41 -0000      
 1.2
+++ tests/classes/factory_and_singleton_006.phpt        3 Jul 2003 13:04:07 -0000
@@ -16,5 +16,5 @@ $obj = NULL;
 echo "Done\n";
 ?>
 --EXPECTF--
-Warning: Call to private destructor from context '' in 
%sfactory_and_singleton_006.php on line %d
-Done
+Fatal error: Call to private test::__destruct from context '' in 
%sfactory_and_singleton_006.php on line %d
+
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to