New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Immutable classes and properties #3148
Conversation
How is this going to work with |
@Majkl578 So far I can only tell you that behaviour of __clone() does not change at the moment, cloning immutable object will work same as for any other object. |
how will this work with typed properties RFC (syntactically I mean)? #3313 |
Is there a way to decouple the immutability of a property from the immutability of its contents? By extension also allowing regular variables to be immutable. For example, I may not want someone to mutate the reference that is held by a property in a class even though the object that the reference refers to can still be interacted with and mutate internally. The type system could be used to differentiate between 'external' and 'internal' immutability, e.g.: immutable class Inbox {
public id : int,
public address : int
}
class Wallet {};
class User {
// The user can be given a new inbox but the data that identifies a particular inbox can not be changed.
public $userMail : Inbox;
// The user only has one original inbox that they can never lose.
public immutable $initialInbox : Inbox;
// The user has only a single wallet but they can take funds out of this and put funds into it.
public immutable $wallet : Wallet;
} |
@Kingdutch Kind regards, |
Is there any ongoing work on this or any related to native immutability? |
@fondberg From my side no. |
This is pull request for following RFC: https://wiki.php.net/rfc/immutability