It can be a good idea to pass an object to the const parameter in php4
style (copy on write). Then original object will be untouched.

The same will be for local objects with const flag.

No reassignments. Always pass a copy (like with arrays now)

пятница, 30 января 2015 г. пользователь Andrea Faulds написал:

> 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...@gmail.com <javascript:;>>
> > To: Andrea Faulds <a...@ajf.me <javascript:;>>
> >
> >
> > 2015-01-30 18:41 GMT+03:00 Andrea Faulds <a...@ajf.me <javascript:;>
> <mailto:a...@ajf.me <javascript:;>>>:
> > 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/
>
>
>
>
>

Reply via email to