Skip to content

Fix inconsistencies and invalid examples in specification - #155

Merged
Crell merged 1 commit into
php-fig:masterfrom
samdark:fix-spec-inconsistencies
Aug 13, 2026
Merged

Fix inconsistencies and invalid examples in specification#155
Crell merged 1 commit into
php-fig:masterfrom
samdark:fix-spec-inconsistencies

Conversation

@samdark

@samdark samdark commented Aug 12, 2026

Copy link
Copy Markdown
Member

This fixes several inconsistencies and invalid examples in the specification.

Changes include:

  • use an explicit nullable parameter and correct the backed-enum example
  • clarify parentheses for intersections within union types
  • clarify import-name resolution
  • make the declare spacing rule apply to all directives while presenting strict_types as an example
  • correct indentation in code examples
  • use the normative BCP 14 keyword for the switch requirement
  • make the multiline-array rule applicable outside assignments
  • document the expanded multiline-array rule in the v3.1 migration guide

Copilot AI lite review requested due to automatic review settings August 12, 2026 20:24
Comment thread spec.md
class Foo extends Bar implements FooInterface
{
public function sampleFunction(int $a, int $b = null): array
public function sampleFunction(int $a, ?int $b = null): array

@samdark samdark Aug 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This syntax still works in PHP 8.4, but emits a deprecation notice. Using ?int avoids the notice and follows the specification’s later recommendation for explicit nullable types.

Comment thread spec.md
public function isOdd(): bool
{
return $this->value() % 2;
return $this->value % 2 !== 0;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backed enum values are exposed through the value property, not a value() method. The explicit comparison also makes the expression produce the declared bool under strict_types=1.

Comment thread spec.md
intersections be encased with parentheses.
Compound types include intersection, union, and mixed intersection and union type declarations. PHP requires
that mixed intersection and union types be structured as an ORed (unioned) series of ANDs (intersections),
and that each intersection in such a union be encased with parentheses.

@samdark samdark Aug 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A standalone intersection is written A&B, without parentheses. Parentheses are required only when that intersection is one option in a union, as in A|(B&C). The previous wording incorrectly implied that standalone intersections should also be parenthesized.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the previous text is correct: A single set of ANDs is still technically ORed with the empty set. However, you're correct that the parens are only meaningful in mixed cases, so we'll go with these revisions.

Comment thread spec.md
|\ReflectionProperty $reflect
): object|null {
// ...
// ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is presented as correctly formatted, so its body should use the mandatory four-space indentation defined in section 2.4.

Comment thread spec.md
Import statements MUST never begin with a leading backslash as they
must always be fully qualified.
Import statements MUST never begin with a leading backslash, as imported names
are always resolved from the namespace root.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An imported name is resolved from the namespace root by PHP; calling it “fully qualified” is potentially confusing because fully qualified names are normally written with a leading backslash.

Comment thread spec.md
public function __construct(
public readonly int $x,
public readonly int $y,
public readonly int $x,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor-promoted parameters are still parameters and therefore use the standard four-space indentation level.

Comment thread spec.md

somefunction($foo, $bar, [
// ...
// ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The array is a single multiline argument rather than a split argument list, but its contents still need the standard four-space indentation.

Comment thread spec.md
### 5.2 `switch`, `case`, `match`

A switch structure must follow the rules below:
A switch structure MUST follow the rules below:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BCP 14 preamble gives normative meaning only to uppercase keywords. Since the detailed switch rules are requirements, this introductory MUST should be normative too.

Comment thread spec.md
$muchLongerArgument,
) {
// ...
// ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These closure-body comments used three spaces while section 2.4 requires four. The same correction is applied to every example in this group.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates spec.md to correct invalid PHP examples and tighten/clarify several normative style rules so the specification is internally consistent and aligns with PHP language behavior (nullable types, backed enums, mixed union/intersection typing, import resolution, strict types formatting, and multiline layout guidance).

Changes:

  • Fix invalid/incorrect PHP examples (nullable default parameter typing; backed-enum value access and odd check; multiple indentation corrections in code snippets).
  • Clarify specification language for mixed union/intersection (DNF) parentheses and for how use imports are resolved (namespace root, no leading \).
  • Refine normative requirements (strict types declaration formatting scoped correctly; switch rules made normative; multiline array bracket placement generalized beyond assignments).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread spec.md
Declare statements MUST NOT contain any spaces and MUST be exactly `declare(strict_types=1)`
(with an optional semicolon terminator).
Declare statements MUST NOT contain any spaces inside the parentheses. For example:
`declare(strict_types=1)` (with an optional semicolon terminator).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The no-spaces rule applies to every declare statement. The previous wording made declare(strict_types=1) sound like the only permitted declaration, even though it is just an example of the required formatting; other directives such as declare(ticks=1) are also allowed.

@samdark
samdark force-pushed the fix-spec-inconsistencies branch 2 times, most recently from 9496a79 to 56573ac Compare August 12, 2026 20:41
@samdark
samdark force-pushed the fix-spec-inconsistencies branch from 56573ac to f389c1b Compare August 12, 2026 20:43
Comment thread spec.md
When the array declaration is split across multiple lines, the opening bracket
MUST be placed on the same line as the equals sign. The closing bracket
When an array declaration is split across multiple lines, the opening bracket
MUST NOT be placed on its own line. The closing bracket

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old wording mentioned an equals sign, but multiline arrays can also appear in arguments, return statements, defaults, attributes, and nested expressions. Requiring the opening bracket not to be on its own line makes the rule applicable in every context.

@Crell
Crell merged commit fec6fe1 into php-fig:master Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants