From 9908f9f310aeadb129b41d14d40de9f2163ffa24 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Thu, 29 Sep 2022 13:13:52 +1300 Subject: [PATCH] [php] Fix testcase segfaults with PHP 8.0 These testcases were segfaulting: prefix director_using_member_scopes virtual_poly The fix here is admittedly a hack - we perform the initialisation of EG(class_table) from CG(class_table) which PHP will do, but hasn't yet. PHP doesn't seem to clearly document which API calls are actually valid in minit or other initialisation contexts, but the code we're generating works with all PHP 7.x and PHP 8.x versions aside from PHP 8.0 so it seems this is a bug in PHP 8.0 rather than that we're doing something invalid, and we need to work with existing PHP 8.0 releases so this hack seems a necessary evil. It will at least have a limited life as PHP 8.0 is only in active support until 2022-11-26, with security support ending a year later. Fixes #2383. --- Lib/php/phpinit.swg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/php/phpinit.swg b/Lib/php/phpinit.swg index 40f7b0766..ae72a10ae 100644 --- a/Lib/php/phpinit.swg +++ b/Lib/php/phpinit.swg @@ -9,4 +9,8 @@ SWIG_php_minit { zend_class_entry SWIGUNUSED internal_ce; SWIG_InitializeModule((void*)&module_number); +#if PHP_MAJOR_VERSION == 8 && PHP_MINOR_VERSION == 0 + /* This hack is needed to avoid segfaults. */ + EG(class_table) = CG(class_table); +#endif %}