Skip to content

Add support for PHP 8.3 typed class constants#736

Merged
jaapio merged 11 commits intophpDocumentor:6.xfrom
lacatoire:feat/typed-constants-support-6x
Apr 10, 2026
Merged

Add support for PHP 8.3 typed class constants#736
jaapio merged 11 commits intophpDocumentor:6.xfrom
lacatoire:feat/typed-constants-support-6x

Conversation

@lacatoire
Copy link
Copy Markdown
Contributor

@lacatoire lacatoire commented Apr 9, 2026

Summary

PHP 8.3 introduced native type declarations for class constants:

class Foo {
    const string BAR = 'baz';
    const int|string UNION = 42;
    const ?string NULLABLE = null;
}

This PR adds support for reading and exposing these types through the reflection API, following the same pattern already used by Property:

  • Add Type|null $type parameter to Constant class constructor and getType() accessor
  • Add getType() to ClassConstantIterator to read the type from the ClassConst AST node
  • Pass the resolved type through in the ClassConstant factory via the existing Type helper

Global constants are not affected (PHP does not support typed global constants).

jaapio and others added 10 commits January 23, 2026 21:25
Files without namespace did not get a type context, this resulted in
unknown scope of the types to be resolved.
The other fix in this commit is to make sure the FQSN coming from the
php-parser is correctly translated to a FQSEN object, this was not the
case for some situations.
…onstant

Files did not get any context when processed
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](dependabot/fetch-metadata@v2.4.0...v2.5.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-version: 2.5.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…thub_actions/dependabot/fetch-metadata-2.5.0

Bump dependabot/fetch-metadata from 2.4.0 to 2.5.0
Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 10.5.58 to 10.5.62.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/10.5.62/ChangeLog-10.5.md)
- [Commits](sebastianbergmann/phpunit@10.5.58...10.5.62)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-version: 10.5.62
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
…mposer/phpunit/phpunit-10.5.62

Bump phpunit/phpunit from 10.5.58 to 10.5.62
Bumps [phpspec/prophecy-phpunit](https://github.com/phpspec/prophecy-phpunit) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/phpspec/prophecy-phpunit/releases)
- [Changelog](https://github.com/phpspec/prophecy-phpunit/blob/master/CHANGES.md)
- [Commits](phpspec/prophecy-phpunit@v2.4.0...v2.5.0)

---
updated-dependencies:
- dependency-name: phpspec/prophecy-phpunit
  dependency-version: 2.5.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…mposer/phpspec/prophecy-phpunit-2.5.0

Bump phpspec/prophecy-phpunit from 2.4.0 to 2.5.0
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 5 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v5...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
…thub_actions/actions/upload-artifact-7

Bump actions/upload-artifact from 5 to 7
The Constant class now accepts and exposes a Type parameter,
following the same pattern used by Property. The ClassConstantIterator
reads the type from the AST node, and the ClassConstant factory
converts it via the Type helper before passing it to the Constant
constructor.
@lacatoire lacatoire force-pushed the feat/typed-constants-support-6x branch from 04cbae2 to 5d8c68c Compare April 9, 2026 18:21
@jaapio jaapio merged commit 70ad4ae into phpDocumentor:6.x Apr 10, 2026
40 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