Use modern class-name idioms (self::class / $x::class) in templates#200
Merged
dcarbone merged 1 commit intoJun 9, 2026
Merged
Conversation
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
There was a problem hiding this comment.
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 withself::classin exception messages and autoloader callbacks. - Replace
get_class($x)with$x::classin 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
approved these changes
Jun 9, 2026
Owner
|
Looks good, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces
__CLASS__withself::classandget_class($x)with$x::classin the generator templates so the emitted code uses the conventional modern form.self::classresolves identically to__CLASS__(including inside traits), and reads more cleanly.$x::classis available since PHP 8.0 — well under the^8.1minimum for generated output.7 templates touched, 14 lines changed.
Closes #197
Test plan
php -lpasses on all changed templates (verified locally)