Fwd: [PHP-DEV] [RFC] Immutable variables and objects
| From: | Andrea Faulds | Date: | Fri, 30 Jan 2015 16:05:14 +0000 |
| Subject: | Fwd: [PHP-DEV] [RFC] Immutable variables and objects | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81435@lists.php.net to get a copy of this message | ||
Hi,
This accidentally went off-list, forwarding for everyone else’s sake.
> Begin forwarded message:
>
> Date: 30 January 2015 16:01:43 GMT
> Subject: Re: [PHP-DEV] [RFC] Immutable variables and objects
> From: Alexander Lisachenko <lisachenko.it@gmail.com>
> To: Andrea Faulds <ajf@ajf.me>
>
>
> 2015-01-30 18:41 GMT+03:00 Andrea Faulds <ajf@ajf.me
> <mailto:ajf@ajf.me>>:
> So what you’re suggesting is a special type of variable modifier which makes that variable
> have completely different copying semantics to usual?
>
> That would be quite strange, I don’t see that getting much support.
>
>
>
> Yes, this should affect a variable state and passing an object to the function to make it
> immutable. But this technique (weakly immutable) is quite useful in several languages. For example,
> in Java:
>
> final int j = 42;
> j = 43; // does not compile. j is final so can't be reassigned
> or alternative in C++
> const int j = 42;
> j = 43; // does not compile. j is const so can't be reassigned
>
> One more example is passing an argument to function as immutable in C++ with "const"
> and then make a mutable copy of object with const_cast.
>
Thanks.
--
Andrea Faulds
http://ajf.me/