Skip to content
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

Closed
wants to merge 56 commits into from
Closed

Immutable classes and properties #3148

wants to merge 56 commits into from

Conversation

smarijic
Copy link

This is pull request for following RFC: https://wiki.php.net/rfc/immutability

Silvio Marijic added 30 commits February 18, 2018 22:32
@Majkl578
Copy link
Contributor

How is this going to work with Serializable, __sleep()/__wakeup() or __clone()?

@smarijic
Copy link
Author

@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.

@krakjoe krakjoe added the RFC label Feb 24, 2018
@itsjavi
Copy link

itsjavi commented Dec 18, 2018

how will this work with typed properties RFC (syntactically I mean)? #3313

@Kingdutch
Copy link

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;
}

@smarijic
Copy link
Author

smarijic commented Jun 7, 2019

@Kingdutch
Hi Alexander,
It has been over a year since I looked at this as basically I have discontinued any work on this after last discussion on the internals. But what you are suggesting in the example at the moment is not possible.
There was a plan to extend this RFC to introduce a convenient mechanism for changing values on the immutable object where you would specify only properties you want to change along with the new values and result of that call would be a new immutable object with specified changes applied. That could be used as a solution to your question. Unfortunately I don't see that happening any time soon as I have exhausted all my efforts to push this RFC and no one else seems to have interest to continue.

Kind regards,
Silvio.

@fondberg
Copy link

fondberg commented Sep 5, 2019

Is there any ongoing work on this or any related to native immutability?

@smarijic
Copy link
Author

@fondberg From my side no.

@smarijic smarijic closed this Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants