Skip to content

Add explicit type declarations to class constants (PHP 8.3+)#215

Merged
Girgias merged 8 commits intophp:masterfrom
lacatoire:refactor/add-typed-class-constants
Feb 5, 2026
Merged

Add explicit type declarations to class constants (PHP 8.3+)#215
Girgias merged 8 commits intophp:masterfrom
lacatoire:refactor/add-typed-class-constants

Conversation

@lacatoire
Copy link
Contributor

Summary

This PR introduces explicit type declarations for class constants, leveraging the feature introduced in PHP 8.3.

Motivation

  • Enhances type safety and static analysis.
  • Makes code intent clearer.
  • Prepares PhD for PHP 8.4 compatibility and future strictness.

Scope

  • Added types such as int, string, bool, or array to class constants.
  • Example:
    Before:
    public const FORMAT_HTML = 1;
    public const NAME = 'PhD';
    After:
    public const int FORMAT_HTML = 1;
    public const string NAME = 'PhD';

Impact

  • ✅ No runtime behavior change.
  • ✅ Fully backward compatible with PHP 8.3+.
  • ⚙️ Code clarity and safety improvement only.

References

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Can you update the composer.json file to require 8.3? I checked with Derick and the doc machine runs 8.3 so it should be fine.

@lacatoire lacatoire requested a review from Girgias February 4, 2026 21:37
When <function> contains <replaceable>, skip link/parentheses
processing in format_function_text() and output plain text instead.
Uses the role stack pattern already established by format_constant().

Fixes php#171
@Girgias
Copy link
Member

Girgias commented Feb 5, 2026

Might need to get rid of the 8.1 and 8.2 CI too

@lacatoire lacatoire requested a review from Girgias February 5, 2026 18:32
@Girgias Girgias merged commit c651993 into php:master Feb 5, 2026
7 checks passed
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.

2 participants