Skip to content

Use modern class-name idioms (self::class / $x::class) in templates#200

Merged
dcarbone merged 1 commit into
dcarbone:mainfrom
kojiromike:feature/modern-class-name-idioms
Jun 9, 2026
Merged

Use modern class-name idioms (self::class / $x::class) in templates#200
dcarbone merged 1 commit into
dcarbone:mainfrom
kojiromike:feature/modern-class-name-idioms

Conversation

@kojiromike

Copy link
Copy Markdown
Contributor

Summary

Replaces __CLASS__ with self::class and get_class($x) with $x::class in the generator templates so the emitted code uses the conventional modern form.

  • self::class resolves identically to __CLASS__ (including inside traits), and reads more cleanly.
  • $x::class is available since PHP 8.0 — well under the ^8.1 minimum for generated output.

7 templates touched, 14 lines changed.

Closes #197

Test plan

  • php -l passes on all changed templates (verified locally)
  • CI generate-and-test cycle passes across the PHP 8.1–8.5 matrix

Replace __CLASS__ with self::class and get_class($x) with $x::class in
generator templates so emitted code uses the conventional modern form.
self::class resolves identically to __CLASS__ (including inside traits),
and $x::class is available since PHP 8.0, well under the ^8.1 minimum.

Closes dcarbone#197

Assisted-by: Claude Code

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

Updates generator templates to emit modern PHP class-name references by replacing __CLASS__ with self::class and get_class($x) with $x::class, aligning generated output with current PHP idioms (Issue #197).

Changes:

  • Replace __CLASS__ occurrences with self::class in exception messages and autoloader callbacks.
  • Replace get_class($x) with $x::class in type/config validation error messages across templates.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
template/versions/types/serialization/xml/unserialize/header.php Modernize class-name references in XML unserialize error reporting.
template/versions/types/serialization/json/unserialize/header.php Modernize class-name references in JSON unserialize error reporting.
template/versions/core/class_version.php Use $config::class for config-type mismatch reporting.
template/versions/core/class_autoloader.php Use self::class for autoloader register/unregister callbacks.
template/tests/core/class_test_autoloader.php Use self::class for test autoloader register/unregister callbacks.
template/core/encoding/trait_xml_serialization_options.php Use self::class in trait exception messages.
template/core/class_autoloader.php Use self::class for autoloader register/unregister callbacks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dcarbone

dcarbone commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Looks good, thanks!

@dcarbone
dcarbone merged commit 627c403 into dcarbone:main Jun 9, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use modern class-name idioms (self::class / $x::class) in templates

3 participants