@@ -3283,7 +3283,15 @@ public function getRegistration(array $allConstInfos): string
3283
3283
$code .= "{\n";
3284
3284
3285
3285
$flagCodes = generateVersionDependentFlagCode("%s", $this->getFlagsByPhpVersion(), $this->phpVersionIdMinimumCompatibility);
3286
- $flags = implode("", $flagCodes);
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
+ }
3287
3295
3288
3296
$classMethods = ($this->funcInfos === []) ? 'NULL' : "class_{$escapedName}_methods";
3289
3297
if ($this->type === "enum") {
@@ -3292,7 +3300,7 @@ public function getRegistration(array $allConstInfos): string
3292
3300
? $this->enumBackingType->toTypeCode() : "IS_UNDEF";
3293
3301
$code .= "\tzend_class_entry *class_entry = zend_register_internal_enum(\"$name\", $backingType, $classMethods);\n";
3294
3302
if ($flags !== "") {
3295
- $code .= "\tclass_entry->ce_flags |= $flags\n";
3303
+ $code .= "\tclass_entry->ce_flags |=$flags\n";
3296
3304
}
3297
3305
} else {
3298
3306
$code .= "\tzend_class_entry ce, *class_entry;\n\n";
@@ -3310,21 +3318,21 @@ public function getRegistration(array $allConstInfos): string
3310
3318
$code .= "#if (PHP_VERSION_ID >= " . PHP_84_VERSION_ID . ")\n";
3311
3319
}
3312
3320
3313
- $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";
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";
3314
3322
3315
3323
if (!$php84MinimumCompatibility) {
3316
3324
$code .= "#else\n";
3317
3325
3318
3326
$code .= "\tclass_entry = zend_register_internal_class_ex(&ce, " . (isset($this->extends[0]) ? "class_entry_" . str_replace("\\", "_", $this->extends[0]->toString()) : "NULL") . ");\n";
3319
3327
if ($flags !== "") {
3320
- $code .= "\tclass_entry->ce_flags |= $flags;\n";
3328
+ $code .= "\tclass_entry->ce_flags |=$flags;\n";
3321
3329
}
3322
3330
$code .= "#endif\n";
3323
3331
}
3324
3332
} else {
3325
3333
$code .= "\tclass_entry = zend_register_internal_interface(&ce);\n";
3326
3334
if ($flags !== "") {
3327
- $code .= "\tclass_entry->ce_flags |= $flags\n";
3335
+ $code .= "\tclass_entry->ce_flags |=$flags\n";
3328
3336
}
3329
3337
}
3330
3338
}
@@ -5391,12 +5399,16 @@ static function (array $value): bool {
5391
5399
$code = "";
5392
5400
5393
5401
$if = $i === 0 ? "#if" : "#elif";
5394
- $endif = $i === $flagCount - 1 ? "#endif\n" : "";
5395
5402
5396
5403
$code .= "$if (PHP_VERSION_ID >= $version)\n";
5397
5404
5398
5405
$code .= sprintf($codeTemplate, implode("|", $versionFlags));
5399
- $code .= $endif;
5406
+ if ($i === $flagCount - 1) {
5407
+ if (!str_ends_with($code, "\n")) {
5408
+ $code .= "\n";
5409
+ }
5410
+ $code .= "#endif\n";
5411
+ }
5400
5412
5401
5413
$result[] = $code;
5402
5414
$i++;
0 commit comments