AW: [PHP-DEV] RFC: constructor argument promotion

From: Date: Thu, 08 Aug 2013 18:05:58 +0000
Subject: AW: [PHP-DEV] RFC: constructor argument promotion
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
I agree, that looks nice. It is still readable IMO and removes the
boilerplate code in the constructor (and setters and where needed)
This proposal seems much better to me because the class members $foo and
$bar are still in the same place as usual and the compiler does not generate
magic code as before.


-----Ursprüngliche Nachricht-----
Von: Leigh [mailto:[email protected]] 
Gesendet: Donnerstag, 8. August 2013 17:17
An: Matthieu Napoli
Cc: [email protected]
Betreff: Re: [PHP-DEV] RFC: constructor argument promotion

On 8 August 2013 14:12, Matthieu Napoli <[email protected]> wrote:

> class MyClass {
>   public $foo;
>   protected $bar;
>
>   public function __construct($this->foo, $this->bar, $baz) {
>     // $this->foo and $this->bar are now set
>

This actually feels _way_ more intuitive to me, it feels like you are
passing the parameter directly into that property.

With that style, why even limit it to the ctor?

function mySetter(array $this->items) {}



Thread (18 messages)

« previous php.internals (#68445) next »