# RFC: Automatic Property Initialization

- Thread: https://staging.externals.io/message/69377
- Original archive: https://news-web.php.net/php.internals/69377
- Started by Gordon Oheim on 2013-09-27T07:17:08+00:00
- Messages: 5
- RFC: Automatic Property Initialization (Declined) — https://staging.externals.io/rfc/automatic_property_initialization.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #69377 — Gordon Oheim — 2013-09-27T07:17:08+00:00

URL: https://staging.externals.io/message/69377#69377

Independent but related to

- https://wiki.php.net/rfc/constructor-promotion

I wrote an RFC about porting Dart-like Automatic Property Initialization 
to PHP. Nikic was so generous to provide an initial PoC for it (since I 
don't do C):

- https://wiki.php.net/rfc/automatic_property_initialization
- https://github.com/php/php-src/pull/474

I am proposing this for inclusion in 5.6.
There is no BC breaks afaik.

The RFC suggests to allow for $this->foo as Constructor arguments to 
make the boilerplate code for property assignments in constructors 
superfluous. This is the core feature subject to discussion.

I've spoken to about two dozen developers outside internals prior to 
suggesting this RFC and the general response was positive and the core 
feature unanimously deemed useful. Moreover, in the previous discussion 
about constructor promotion there was some messages suggesting that the 
now proposed syntactic approach is more preferred than using visibility 
keywords.

The RFC also suggests some related syntactic sugar like Methodless 
Constructors, an alternate and shorter syntax, as well as making this 
available in the entire class scope. These are things I am not sure of 
so I am hoping for comments on these. Should this RFC get into the 
voting phase, we should by then have either promoted or eliminated these 
options through discussion.

Thanks and Regards, Gordon

---

## #69384 — Sebastian Krebs — 2013-09-27T09:59:49+00:00

URL: https://staging.externals.io/message/69377#69384 · In reply to: #69377

2013/9/27 Gordon Oheim <gooh@php.net>

>
> Independent but related to
>
> - https://wiki.php.net/rfc/**constructor-promotion<https://wiki.php.net/rfc/constructor-promotion>
>
> I wrote an RFC about porting Dart-like Automatic Property Initialization
> to PHP. Nikic was so generous to provide an initial PoC for it (since I
> don't do C):
>
> - https://wiki.php.net/rfc/**automatic_property_**initialization<https://wiki.php.net/rfc/automatic_property_initialization>
> - https://github.com/php/php-**src/pull/474<https://github.com/php/php-src/pull/474>
>
> I am proposing this for inclusion in 5.6.
> There is no BC breaks afaik.
>
> The RFC suggests to allow for $this->foo as Constructor arguments to make
> the boilerplate code for property assignments in constructors superfluous.
> This is the core feature subject to discussion.
>

I simply don't like it to have a concrete method without body. Either
abstract without body, or concrete _with_ body. In this case it would mean
to have an empty body

public function __construct ($this->x) {}

but I think that wouldn't be too bad :)


>
> I've spoken to about two dozen developers outside internals prior to
> suggesting this RFC and the general response was positive and the core
> feature unanimously deemed useful. Moreover, in the previous discussion
> about constructor promotion there was some messages suggesting that the now
> proposed syntactic approach is more preferred than using visibility
> keywords.
>
> The RFC also suggests some related syntactic sugar like Methodless
> Constructors, an alternate and shorter syntax, as well as making this
> available in the entire class scope. These are things I am not sure of so I
> am hoping for comments on these. Should this RFC get into the voting phase,
> we should by then have either promoted or eliminated these options through
> discussion.
>
> Thanks and Regards, Gordon
>
> --
> 
> 
>
>


-- 
github.com/KingCrunch

---

## #69385 — Sebastian Krebs — 2013-09-27T10:02:46+00:00

URL: https://staging.externals.io/message/69377#69385

2013/9/27 Matthieu Napoli <matthieu@mnapoli.fr>

> Le 27/09/2013 09:17, Gordon Oheim a écrit :
>
>
> > […]
>
> I really like the proposal.
>
> I just wonder about how it could mix/conflict with the named parameters
> proposal? Given what you said about Reflection ($this->foo is treated like
> $foo), then I guess it's not a problem then.
>
> However maybe the RFC should reflect that you can't use:
>
> public function __construct($this->foo, $foo) { … }
>
> Also, at first glance I didn't find the "methodless constructor" very
> useful (since it's only saving "{}"), but actually the possibility to use
> this feature in setters too looks very good, it would avoid a lot of
> boilerplate code.


Actually I would prefer to get rid of getters/setters completely and
finally get _real_ accessor methods like in
https://wiki.php.net/rfc/propertygetsetsyntax-v1.2
The ability to shorten the setters is interesting, but it makes them look
"asymetric" to their corresponding getter (which still requires a
body/code) and anyway: It just patches the symptom, that they are required
at all.


>
>
> --
> 
> 
>
>


-- 
github.com/KingCrunch

---

## #69397 — Tobias Schlitt — 2013-09-27T18:17:39+00:00

URL: https://staging.externals.io/message/69377#69397 · In reply to: #69377

Hi,

big +1 from my side. Would love to see this functionality in 5.6.

Thanks for the proposal, Gordon.

Cheers,
Toby

-- 
Helping people to create high quality web apps      http://qafoo.com
Tobias Schlitt        http://schlitt.info        GPG Key: 0xC462BC14

---

## #69398 — Andrea Faulds — 2013-09-27T19:21:39+00:00

URL: https://staging.externals.io/message/69377#69398 · In reply to: #69377

>

I think this is a great proposal. Anything that reduces code verbosity, 
increases programmer productivity, improves readability and doesn't 
bloat PHP gets my support.


-- 
Andrea Faulds
http://ajf.me/
