php register_shutdown_function 的一个问题

php register_shutdown_function 方法执行顺序是

1,调用 register_shutdown_function 注册方法
2,调用类析构方法
3,输出

因为是先调用 register_shutdown_function 注册的方法,后调用析构方法,所以类的析构操作都将在 register_shutdown_function完成之后才能执行。

// php7.0.6线上版本
// 代码路径:php-src/main/main.c
void php_request_shutdown(void *dummy)
{
……
    /* 1. Call all possible shutdown functions registered with register_shutdown_function() */
    if (PG(modules_activated)) zend_try {
        php_call_shutdown_functions();
    } zend_end_try();

    /* 2. Call all possible __destruct() functions */
    zend_try {
        zend_call_destructors();
    } zend_end_try();

    /* 3. Flush all output buffers */
    zend_try {
……
}

发表新评论