Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Lester Caine
On 17/11/15 20:38, Marc Bennewitz wrote: > FYI there was a very small discussion about it ~ 1 year ago > https://www.mail-archive.com/internals@lists.php.net/msg71521.html And https://www.mail-archive.com/internals%40lists.php.net/msg61320.html covered making properties read_only ... -- Lester C

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Marc Bennewitz
FYI there was a very small discussion about it ~ 1 year ago https://www.mail-archive.com/internals@lists.php.net/msg71521.html On 11/16/2015 10:15 AM, Chris Riley wrote: Hi, There has been a lot of interest recently (eg psr-7) in immutable data. I'm considering putting an RFC together to add la

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Rowan Collins
Andrea Faulds wrote on 17/11/2015 15:37: Does it? You can write a five-line constructor which does what you need: private function __construct(array $properties) { foreach ($properties as $name => $value) { $this->{$name} = $value; } } You can do changes like

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Rowan Collins
Mathieu Rochette wrote on 17/11/2015 13:40: Indeed, maybe there is a use for a new language construct to help reduce the boilerplate, but it could be done afterward, the "everything in the constructor" works fine. If there is too much in the construct it might be a sign that the class is doing

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Andrea Faulds
Hi, Rowan Collins wrote: Hi Andrea, Andrea Faulds wrote on 17/11/2015 01:47: Larry Garfield wrote: The "everything in the constructor" is the problem. That results in, essentially, an obscenely long function call that just happens to be named __construct(). If I wanted something that obscur

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Mathieu Rochette
On 17/11/2015 13:26, Lester Caine wrote: On 17/11/15 11:04, Rowan Collins wrote: If you look at the PSR-7 implementation I linked to earlier [1], there's no such boilerplate, just a single call to "clone $this", and PHP does it all for you. But that doesn't work with a simplistic definition of

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Lester Caine
On 17/11/15 11:04, Rowan Collins wrote: > If you look at the PSR-7 implementation I linked to earlier [1], there's > no such boilerplate, just a single call to "clone $this", and PHP does > it all for you. But that doesn't work with a simplistic definition of > immutable like "mutable in constructo

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Chris Riley
On 17 November 2015 at 11:04, Rowan Collins wrote: > Hi Andrea, > > Andrea Faulds wrote on 17/11/2015 01:47: > >> Larry Garfield wrote: >> >>> The "everything in the constructor" is the problem. That results in, >>> essentially, an obscenely long function call that just happens to be >>> named _

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Rowan Collins
Hi Andrea, Andrea Faulds wrote on 17/11/2015 01:47: Larry Garfield wrote: The "everything in the constructor" is the problem. That results in, essentially, an obscenely long function call that just happens to be named __construct(). If I wanted something that obscure and hard to work with I'd

Re: [PHP-DEV] Immutable modifier

2015-11-17 Thread Alexander Lisachenko
Hello, internals! We discussed this topic early, see this thread: http://www.serverphorums.com/read.php?7,1123371,1124223 for any additional thoughts and ideas. I want to attach a link to the Java draft of partial immutability of objects: http://cr.openjdk.java.net/~jrose/values/values-0.html, it'

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Chris Riley
On Tue, 17 Nov 2015, 02:07 Andrea Faulds wrote: Hi, Chris Riley wrote: > > There has been a lot of interest recently (eg psr-7) in immutable data. I'm > considering putting an RFC together to add language support for immutables: > I wonder if immutable classes are really the right way to go. Im

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Andrea Faulds
Hi, Chris Riley wrote: There has been a lot of interest recently (eg psr-7) in immutable data. I'm considering putting an RFC together to add language support for immutables: I wonder if immutable classes are really the right way to go. Immutable reference types with manual copying are some

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Anthony Ferrara
Chris, On Mon, Nov 16, 2015 at 4:15 AM, Chris Riley wrote: > Hi, > > There has been a lot of interest recently (eg psr-7) in immutable data. I'm > considering putting an RFC together to add language support for immutables: > > immutable class Foo { > public $bar; > public function __construct($ba

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Andrea Faulds
Hi Larry, Larry Garfield wrote: The "everything in the constructor" is the problem. That results in, essentially, an obscenely long function call that just happens to be named __construct(). If I wanted something that obscure and hard to work with I'd just use anonymous arrays. :-) Huh? "wi

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Sebastian Bergmann
On 11/16/2015 04:15 AM, Chris Riley wrote: Any thoughts? Would love to have it for implementing value objects. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Larry Garfield
On 11/16/15 5:11 PM, Mathieu Rochette wrote: On 11/16/2015 11:11 PM, Larry Garfield wrote: On 11/16/15 3:15 AM, Chris Riley wrote: Immutable on a property makes the property immutable once it takes on a none null value. Attempts to modify the property after this results in a fatal error. A

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Levi Morrison
On Mon, Nov 16, 2015 at 2:15 AM, Chris Riley wrote: > Hi, > > There has been a lot of interest recently (eg psr-7) in immutable data. I'm > considering putting an RFC together to add language support for immutables: > > immutable class Foo { > public $bar; > public function __construct($bar) { >

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Mathieu Rochette
On 11/16/2015 11:11 PM, Larry Garfield wrote: On 11/16/15 3:15 AM, Chris Riley wrote: Hi, There has been a lot of interest recently (eg psr-7) in immutable data. I'm considering putting an RFC together to add language support for immutables: immutable class Foo { public $bar; public funct

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Larry Garfield
On 11/16/15 3:15 AM, Chris Riley wrote: Hi, There has been a lot of interest recently (eg psr-7) in immutable data. I'm considering putting an RFC together to add language support for immutables: immutable class Foo { public $bar; public function __construct($bar) { $this->bar = $bar; } } Immu

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Rowan Collins
Mathieu Rochette wrote on 16/11/2015 10:00: Would it be allowed to assign non immutable types to properties of an immutable class ? I think this is the trickiest part of trying to enforce immutability: nesting. Consider the following: // Basic properties $my_immutable_object->foo = 42; $my_i

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Lorenzo Fontana
2015-11-16 10:40 GMT+01:00 Chris Riley : > > > On 16 November 2015 at 09:33, Lorenzo Fontana > wrote: > >> I really like the concept of immutability, but I think that it should be >> applicable at instance level rather than declaration. >> >> I would also prefer another keyword than immutable. >

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Mathieu Rochette
hi, On 16/11/2015 10:33, Lorenzo Fontana wrote: I really like the concept of immutability, but I think that it should be applicable at instance level rather than declaration. I'm not sure about that, most PHP code assume mutable objects, I doubt much existing classes would be usable as immutab

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Chris Riley
On 16 November 2015 at 09:33, Lorenzo Fontana wrote: > I really like the concept of immutability, but I think that it should be > applicable at instance level rather than declaration. > > I would also prefer another keyword than immutable. > > Final does not make the properties immutable, it mak

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Lorenzo Fontana
I really like the concept of immutability, but I think that it should be applicable at instance level rather than declaration. I would also prefer another keyword than immutable. Final does not make the properties immutable, it makes the class not extensible. On Nov 16, 2015 10:24, "Daniel Perss

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Chris Riley
On 16 November 2015 at 09:24, Daniel Persson wrote: > Any differance from the final keyword? > > http://php.net/manual/en/language.oop5.final.php > > On Mon, Nov 16, 2015 at 10:15 AM, Chris Riley wrote: > >> Hi, >> >> There has been a lot of interest recently (eg psr-7) in immutable data. >> I'm

Re: [PHP-DEV] Immutable modifier

2015-11-16 Thread Daniel Persson
Any differance from the final keyword? http://php.net/manual/en/language.oop5.final.php On Mon, Nov 16, 2015 at 10:15 AM, Chris Riley wrote: > Hi, > > There has been a lot of interest recently (eg psr-7) in immutable data. I'm > considering putting an RFC together to add language support for im