@@ -3282,26 +3282,13 @@ public function getRegistration(array $allConstInfos): string
3282
3282
3283
3283
$code .= "{\n";
3284
3284
3285
- $flagCodes = generateVersionDependentFlagCode("%s", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
3286
- if (count($flagCodes) > 1) {
3287
- // If we have more than one entry, there will be preprocessor conditions,
3288
- // thus we need to start with a newline.
3289
- $flags = "\n" . implode("\n", $flagCodes);
3290
- } else if (count($flagCodes) === 1) {
3291
- $flags = " " . $flagCodes[0];
3292
- } else {
3293
- $flags = "";
3294
- }
3295
-
3296
3285
$classMethods = ($this->funcInfos === []) ? 'NULL' : "class_{$escapedName}_methods";
3297
3286
if ($this->type === "enum") {
3298
3287
$name = addslashes((string) $this->name);
3299
3288
$backingType = $this->enumBackingType
3300
3289
? $this->enumBackingType->toTypeCode() : "IS_UNDEF";
3301
3290
$code .= "\tzend_class_entry *class_entry = zend_register_internal_enum(\"$name\", $backingType, $classMethods);\n";
3302
- if ($flags !== "") {
3303
- $code .= "\tclass_entry->ce_flags |=$flags\n";
3304
- }
3291
+ $code .= implode("", generateVersionDependentFlagCode("\tclass_entry->ce_flags = %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility));
3305
3292
} else {
3306
3293
$code .= "\tzend_class_entry ce, *class_entry;\n\n";
3307
3294
if (count($this->name->getParts()) > 1) {
@@ -3318,22 +3305,25 @@ public function getRegistration(array $allConstInfos): string
3318
3305
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
3319
3306
}
3320
3307
3321
- $code .= "\tclass_entry = zend_register_internal_class_with_flags(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . "," . ($flags ?: " 0") . ");\n";
3308
+ $template = "\tclass_entry = zend_register_internal_class_with_flags(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ", %s);\n";
3309
+ $entries = generateVersionDependentFlagCode($template, $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility ? max($this->phpVersionIdMinimumCompatibility, PHP_84_VERSION_ID) : null);
3310
+ if ($entries !== []) {
3311
+ $code .= implode("", $entries);
3312
+ } else {
3313
+ $code .= sprintf($template, "0");
3314
+ }
3322
3315
3323
3316
if (!$php84MinimumCompatibility) {
3324
3317
$code .= "#else\n";
3325
3318
3326
3319
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ");\n";
3327
- if ($flags !== "") {
3328
- $code .= "\tclass_entry->ce_flags |=$flags;\n";
3329
- }
3320
+ $code .= implode("", generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility));
3330
3321
$code .= "#endif\n";
3331
3322
}
3332
3323
} else {
3333
3324
$code .= "\tclass_entry = zend_register_internal_interface(&ce);\n";
3334
- if ($flags !== "") {
3335
- $code .= "\tclass_entry->ce_flags |=$flags\n";
3336
- }
3325
+ $code .= implode("", generateVersionDependentFlagCode("\tclass_entry->ce_flags |= %s;\n", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility));
3326
+
3337
3327
}
3338
3328
}
3339
3329
@@ -5399,16 +5389,12 @@ static function (array $value): bool {
5399
5389
$code = "";
5400
5390
5401
5391
$if = $i === 0 ? "#if" : "#elif";
5392
+ $endif = $i === $flagCount - 1 ? "#endif\n" : "";
5402
5393
5403
5394
$code .= "$if (PHP_VERSION_ID >= $version)\n";
5404
5395
5405
5396
$code .= sprintf($codeTemplate, implode("|", $versionFlags));
5406
- if ($i === $flagCount - 1) {
5407
- if (!str_ends_with($code, "\n")) {
5408
- $code .= "\n";
5409
- }
5410
- $code .= "#endif\n";
5411
- }
5397
+ $code .= $endif;
5412
5398
5413
5399
$result[] = $code;
5414
5400
$i++;
0 commit comments