Skip to content

Commit 2a0220f

Browse files
Fix for extensions support PHP < 8.5
1 parent f78fd03 commit 2a0220f

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

build/gen_stub.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,8 +2784,13 @@ private function getGlobalConstDeclaration(EvaluatedValue $value): string
27842784

27852785
$code = "\t";
27862786
if ($this->attributes !== []) {
2787-
$constVarName = 'const_' . $constName;
2788-
$code .= "zend_constant *$constVarName = ";
2787+
if ($this->phpVersionIdMinimumCompatibility === null || $this->phpVersionIdMinimumCompatibility >= PHP_85_VERSION_ID) {
2788+
// Registration only returned the constant since PHP 8.5, its
2789+
// not worth the bloat to add two different registration blocks
2790+
// with conditions for the PHP version
2791+
$constVarName = 'const_' . $constName;
2792+
$code .= "zend_constant *$constVarName = ";
2793+
}
27892794
}
27902795

27912796
if ($value->type->isNull()) {
@@ -5314,12 +5319,11 @@ function generateGlobalConstantAttributeInitialization(
53145319
$isConditional = false;
53155320
if ($phpVersionIdMinimumCompatibility !== null && $phpVersionIdMinimumCompatibility < PHP_85_VERSION_ID) {
53165321
$isConditional = true;
5317-
$phpVersionIdMinimumCompatibility = PHP_85_VERSION_ID;
53185322
}
53195323
$code = generateCodeWithConditions(
53205324
$constInfos,
53215325
"",
5322-
static function (ConstInfo $constInfo) use ($allConstInfos, $phpVersionIdMinimumCompatibility) {
5326+
static function (ConstInfo $constInfo) use ($allConstInfos, $isConditional) {
53235327
$code = "";
53245328

53255329
if ($constInfo->attributes === []) {
@@ -5328,12 +5332,18 @@ static function (ConstInfo $constInfo) use ($allConstInfos, $phpVersionIdMinimum
53285332
$constName = str_replace('\\', '\\\\', $constInfo->name->__toString());
53295333
$constVarName = 'const_' . $constName;
53305334

5335+
// The entire attribute block will be conditional if PHP < 8.5 is
5336+
// supported, but also if PHP < 8.5 is supported we need to search
5337+
// for the constant; see GH-19029
5338+
if ($isConditional) {
5339+
$code .= "\tzend_constant *$constVarName = zend_hash_str_find_ptr(EG(zend_constants), \"" . $constName . "\", sizeof(\"" . $constName . "\") - 1);\n";
5340+
}
53315341
foreach ($constInfo->attributes as $key => $attribute) {
53325342
$code .= $attribute->generateCode(
53335343
"zend_add_global_constant_attribute($constVarName",
53345344
$constVarName . "_$key",
53355345
$allConstInfos,
5336-
$phpVersionIdMinimumCompatibility
5346+
PHP_85_VERSION_ID
53375347
);
53385348
}
53395349

ext/zend_test/test_arginfo.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)