Implement automatic property initialization #474

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@nikic

RFC: https://wiki.php.net/rfc/automatic_property_initialization

This does not yet implement the syntax variant without method body.

@nikic nikic Implement automatic property initialization
This does not yet implement the syntax variant without method body.
79df1e6
@liverbool

Where are the type-hints?
Why not just check declared property name with name of arguments and then auto assign to them?
To keep Type Hinting:

class Foo {
    public $bar;
    public function __construct(User $bar) {
        // auto matching `public $bar` with `User $bar` with the named.
        // this just one rule for user to keep in mind:
        // You MUST matching the name to auto assign by yourself.
    }
}
@nikic

Where are the type-hints?

Typehints are where they always are. You can write __construct(User $this->user) {} for example.

Why not just check declared property name with name of arguments and then auto assign to them?

That would break backwards compatibility and would be too much implicit magic.

@MartinStepar

Awesome, where is the "Vote for" button? =)

@JanTvrdik

I hope this will make it to PHP 5.6.

@nikic

Closing as the RFC was declined.

@nikic nikic closed this Aug 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment