From 5bfe58c0f8c8c5e3eaaa1c24da07614a50017079 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 21 Sep 2026 09:31:18 +0800 Subject: [PATCH] fix(build): select opcode decoder from build PHP CLI version --- src/Translator.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Translator.php b/src/Translator.php index ccde96be..b2bbf813 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -2218,19 +2218,15 @@ CODE; $sourceFiles[] = $this->getPhpxDir() . '/src/misc/typephp_main.cc'; if ($this->bundledFiles !== [] || $this->embeddedOpcodeFiles !== []) { $sourceFiles[] = $this->getPhpxDir() . '/src/misc/typephp_opcode_table.cc'; - $versionHeader = $this->isWindows() - ? $this->getPhpDir() . '/SDK/include/main/php_version.h' - : $this->getPhpDir() . '/include/php/main/php_version.h'; - $versionText = is_file($versionHeader) ? file_get_contents($versionHeader) : ''; - if (!preg_match('/#define PHP_VERSION_ID\s+(\d+)/', $versionText, $versionMatch)) { - throw new \RuntimeException("Cannot determine the target PHP version from {$versionHeader}"); - } - $targetPhpVersion = (int) $versionMatch[1]; - $decoder = match (true) { - $targetPhpVersion >= 80400 && $targetPhpVersion < 80500 => 'opcode_unserialize_84.c', - $targetPhpVersion >= 80500 && $targetPhpVersion < 80600 => 'opcode_unserialize_85.c', - default => throw new \RuntimeException("Unsupported opcode decoder PHP version: {$targetPhpVersion}"), - }; + // Select the decoder for the PHP CLI that generated the blobs. + // Distribution PHP headers need not live under the PHP prefix. + $this->getOpcodeBuildExtensionArgs(); + if (!preg_match('/^8\.(4|5)\./', $this->opcodeBuildPhpVersion, $versionMatch)) { + throw new \RuntimeException( + "Unsupported opcode decoder PHP version: {$this->opcodeBuildPhpVersion}", + ); + } + $decoder = 'opcode_unserialize_8' . $versionMatch[1] . '.c'; $sourceFiles[] = $this->getPhpxDir() . '/thirdparty/opcache/' . $decoder; } }