Hi Rasmus, On Fri, 13 Sep 2019 at 11:18, Rasmus Schultz <ras...@mindplay.dk> wrote:
> All in all, I find this feature is useful or applicable only to a few, > select patterns within the language - it isn't general enough. > I've trimmed the quote for readability, but agree with basically everything in this message. :) I like the reasoning behind this RFC, but think it is unnecessarily limited. It's not about "public properties are bad", it's just that if we can come up with a feature that works for public properties *and* other programming styles, we should prefer that. A related proposal that's come up before is short-hand constructors: class Foo { private int $foo; public function __construct($this->foo) { // automatically assigns first parameter to $this->foo so body is simplified } } Combine that with opt-in named parameters, and the Customer example from the RFC might look something like this: class Customer { private $id; private $name; private DateTimeImmutable $createdAt; public function __construct(id => $this->id, name => $this->name, createdDate => string $dateString = 'now') { $this->createdAt = new DateTimeImmutable($dateString); } }$customer = new Customer( id => 123, name => 'John Doe', createdDate => '2019-01-01 12:34' ); It's slightly more verbose, but a lot more flexible. As a side note, I have always thought stdClass was a bit of a kludge, and now we have real anonymous classes I would love to see it gradually phased out. I would much rather see syntax for capturing variables in an anonymous class declaration than new ways to create stdClass objects. Regards, -- Rowan Tommins [IMSoP]