Repository navigation
docs: point to native readonly and keep the library as a z-engine showcase - #18
Merged
Merged
Conversation
…wcase PHP gained readonly properties (8.1), readonly classes (8.2), readonly re-initialization in __clone (8.3), asymmetric visibility (8.4) and clone with (8.5), so new code needs neither FFI nor this library to get immutable objects. The README now says so up front, with a native example, and explains why the repository stays: a compact, tested example of rewriting engine object handlers from PHP. The old rationale is kept, marked historical, and the composer description follows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FxhC1D34vSRsQVcgd3HwS6
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.
Why
This library was written when PHP had no way to stop a property from changing after construction, and the Immutability RFC had stalled. The language has caught up since, so for new code the honest advice is "use
readonly". This PR says that up front, and explains why the repository is still worth keeping.What changes
showcasestatus badge.readonlyproperties (8.1),readonlyclasses (8.2), readonly re-initialization in__clone()(8.3), asymmetric visibilitypublic private(set)(8.4), andclone($obj, [...])(8.5).final readonly class Moneyexample, with a wither built onclone with.interface_gets_implemented, replacingcreate_objectto give each instance its own handler table, overridingwrite_property/unset_property/get_property_ptr_ptr, and checking at start-up that the interception really works under OPcache (z-engine#238). It points readers to the existing "Low-level details (for geeks)" section.composer.jsondescription describe the library as handler-rewriting via z-engine and a showcase, instead of "native immutable objects".No code or CI changes. The library keeps running on PHP 8.4, 8.5 and 8.6.
Checked
Error: Cannot modify readonly property Money::$amount;withAmount(80)returns a new object and leaves the original untouched.clone withonly works inside the class (a wither): from global scope it fails with "Cannot modify protected(set) readonly property", so the example uses a method.composer validate --strictpasses.Generated by Claude Code