From 69017a0bfcbbc8d7c3ec90ea5d2f9f39498ba014 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Thu, 13 Apr 2023 23:17:35 +0300 Subject: [PATCH] delay module unloading Taking advantage of the ["reschedule" logic of `register_shutdown_function`](http://php.net/register_shutdown_function), specifically: > Shutdown functions may also call register_shutdown_function() themselves to add a shutdown function to the end of the queue. This avoids errors like: > Uncaught TypeError: uv_ffi(): Return value must be of type FFI, null returned --- zend/StandardModule.php | 6 +++--- zend/ThreadsModule.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/zend/StandardModule.php b/zend/StandardModule.php index 2047e4e..0d2d3e9 100644 --- a/zend/StandardModule.php +++ b/zend/StandardModule.php @@ -579,9 +579,9 @@ public function startup(): void } if ($this->r_shutdown) - \register_shutdown_function( - \closure_from($this, 'module_destructor') - ); + \register_shutdown_function(function () { + \register_shutdown_function(\closure_from($this, 'module_destructor')); + }); if ($this->restart_sapi) { diff --git a/zend/ThreadsModule.php b/zend/ThreadsModule.php index 4220a5f..7b0e772 100644 --- a/zend/ThreadsModule.php +++ b/zend/ThreadsModule.php @@ -116,9 +116,9 @@ public function startup(): void } if ($this->r_shutdown) - \register_shutdown_function( - \closure_from($this, 'module_destructor') - ); + \register_shutdown_function(function () { + \register_shutdown_function(\closure_from($this, 'module_destructor')); + }); $result = \IS_PHP82 ? \ze_ffi()->php_module_startup(\FFI::addr(\ze_ffi()->sapi_module), null)