Zeev Suraski wrote:
If there are no (ultra last) objections, I'll roll 5.0.5 tomorrow morning (.il/Europe time) and post it in the evening.

Zeev

I'm still objecting to a patch by Jani made in April to move destructor before shutdown functions. It was in response to the following report, http://bugs.php.net/bug.php?id=30578

The problem being other than the fact that it's broken some BC is that when it comes around to using the shutdown function any objects you might actually have wished to use have since had their destructor called closing connections and finalising data.

All I am proposing is that the shutdown function is run prior to destruct functions being called as I don't expect to still be able to access objects after the destructor is called which is still the case. Changing the order doesn't effect bug 30578 which it was fixing.

The attached code demonstrates the problem, I'd expect to get the following output

__construct
execution
execution
__destruct

the shutdown function checking the last step run, unfortunately I get

__construct
execution
__destruct
__destruct

Even though the destructor has been called I can still access the object and fetch the value of the step variable.

Scott
<?php 

error_reporting(E_ALL);

class example
{
        var $step;
        function __construct()
        {
                echo "__construct\n";
                $this->step = '__construct';
        }
        function execution()
        {
                echo "execution\n";
                $this->step = 'execution';
        }
        function __destruct()
        {
                echo "__destruct\n";
                $this->step = '__destruct';
        }
}
echo "<pre>";
$obj = new example();
$obj->execution();

function shutdown()
{
        global $obj;
        echo $obj->step . "\n";
}
register_shutdown_function('shutdown');
?>
Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.648
diff -u -r1.648 main.c
--- main/main.c 2 Sep 2005 14:08:09 -0000       1.648
+++ main/main.c 6 Sep 2005 13:12:22 -0000
@@ -1319,16 +1319,16 @@
        EG(opline_ptr) = NULL;
        EG(active_op_array) = NULL;
 
-       /* 1. Call all possible __destruct() functions */
+       /* 1. Call all possible shutdown functions registered with 
register_shutdown_function() */
+       if (PG(modules_activated)) zend_try {
+               php_call_shutdown_functions(TSRMLS_C);
+       } zend_end_try();
+
+       /* 2. Call all possible __destruct() functions */
        zend_try {
                zend_call_destructors(TSRMLS_C);
        } zend_end_try();
 
-       /* 2. Call all possible shutdown functions registered with 
register_shutdown_function() */
-       if (PG(modules_activated)) zend_try {
-               php_call_shutdown_functions(TSRMLS_C);
-       } zend_end_try();
-       
        /* 3. Flush all output buffers */
        zend_try {
                
php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1) TSRMLS_CC);
Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.604.2.22
diff -u -r1.604.2.22 main.c
--- main/main.c 16 Aug 2005 18:11:34 -0000      1.604.2.22
+++ main/main.c 6 Sep 2005 13:34:15 -0000
@@ -1194,14 +1194,14 @@
                sapi_send_headers(TSRMLS_C);
        } zend_end_try();
 
+       if (PG(modules_activated)) zend_try {
+               php_call_shutdown_functions(TSRMLS_C);
+       } zend_end_try();
+
        zend_try {
                zend_call_destructors(TSRMLS_C);
        } zend_end_try();
 
-       if (PG(modules_activated)) zend_try {
-               php_call_shutdown_functions(TSRMLS_C);
-       } zend_end_try();
-       
        if (PG(modules_activated)) {
                zend_deactivate_modules(TSRMLS_C);
                php_free_shutdown_functions(TSRMLS_C);
Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.640.2.4
diff -u -r1.640.2.4 main.c
--- main/main.c 2 Sep 2005 14:05:45 -0000       1.640.2.4
+++ main/main.c 6 Sep 2005 13:17:14 -0000
@@ -1200,16 +1200,16 @@
        EG(opline_ptr) = NULL;
        EG(active_op_array) = NULL;
 
-       /* 1. Call all possible __destruct() functions */
+       /* 1. Call all possible shutdown functions registered with 
register_shutdown_function() */
+       if (PG(modules_activated)) zend_try {
+               php_call_shutdown_functions(TSRMLS_C);
+       } zend_end_try();
+
+       /* 2. Call all possible __destruct() functions */
        zend_try {
                zend_call_destructors(TSRMLS_C);
        } zend_end_try();
 
-       /* 2. Call all possible shutdown functions registered with 
register_shutdown_function() */
-       if (PG(modules_activated)) zend_try {
-               php_call_shutdown_functions(TSRMLS_C);
-       } zend_end_try();
-       
        /* 3. Flush all output buffers */
        zend_try {
                
php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1) TSRMLS_CC);

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to