diff --git a/ext-src/stubs/php_swoole_thread.stub.php b/ext-src/stubs/php_swoole_thread.stub.php index a6617fb67b..88df2d46c4 100644 --- a/ext-src/stubs/php_swoole_thread.stub.php +++ b/ext-src/stubs/php_swoole_thread.stub.php @@ -8,7 +8,7 @@ public function join(): bool {} public function joinable(): bool {} public function detach(): bool {} - public static function getArguments(): array {} + public static function getArguments(): ?array {} public static function getId(): int {} public static function getTsrmInfo(): array {} } diff --git a/ext-src/stubs/php_swoole_thread_arginfo.h b/ext-src/stubs/php_swoole_thread_arginfo.h index 02f0a7c4a0..12e7e6d326 100644 --- a/ext-src/stubs/php_swoole_thread_arginfo.h +++ b/ext-src/stubs/php_swoole_thread_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 234aeadaab2ab31facf1909f0e3027e433f2a88f */ + * Stub hash: 261ac9fd29d4f2f37118ff3b96428a0b2f85223a */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Swoole_Thread___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, script_file, IS_STRING, 0) @@ -13,10 +13,11 @@ ZEND_END_ARG_INFO() #define arginfo_class_Swoole_Thread_detach arginfo_class_Swoole_Thread_join -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getArguments, 0, 0, IS_ARRAY, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getArguments, 0, 0, IS_ARRAY, 1) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getId, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() -#define arginfo_class_Swoole_Thread_getTsrmInfo arginfo_class_Swoole_Thread_getArguments +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Swoole_Thread_getTsrmInfo, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() diff --git a/ext-src/swoole_thread.cc b/ext-src/swoole_thread.cc index 656a927999..1cd9d51ef0 100644 --- a/ext-src/swoole_thread.cc +++ b/ext-src/swoole_thread.cc @@ -55,7 +55,7 @@ struct ThreadObject { static void php_swoole_thread_join(zend_object *object); static void php_swoole_thread_register_stdio_file_handles(bool no_close); -static thread_local zval thread_argv; +static thread_local zval thread_argv = {}; static thread_local JMP_BUF *thread_bailout = nullptr; static sw_inline ThreadObject *thread_fetch_object(zend_object *obj) { @@ -189,7 +189,9 @@ static PHP_METHOD(swoole_thread, detach) { } static PHP_METHOD(swoole_thread, getArguments) { - RETURN_ZVAL(&thread_argv, 1, 0); + if (Z_TYPE(thread_argv) == IS_ARRAY) { + RETURN_ZVAL(&thread_argv, 1, 0); + } } static PHP_METHOD(swoole_thread, getId) { diff --git a/tests/swoole_thread/empty_args.phpt b/tests/swoole_thread/empty_args.phpt new file mode 100644 index 0000000000..8733dbfc04 --- /dev/null +++ b/tests/swoole_thread/empty_args.phpt @@ -0,0 +1,17 @@ +--TEST-- +swoole_thread: info +--SKIPIF-- + +--FILE-- + +--EXPECTF--