Re: Re: [RFC] Callable constructors

From: Date: Fri, 26 Feb 2016 11:26:01 +0000
Subject: Re: Re: [RFC] Callable constructors
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-91432@lists.php.net to get a copy of this message
Hi Adam, Adam Harvey wrote:
On 25 February 2016 at 09:40, Andrea Faulds <ajf@ajf.me> wrote:
Instead of changing __construct to implicitly create the object it acts on in certain contexts, I would suggest a simpler approach: add a magic ::new() static method that exists on all classes (think ::class, although that is a constant). Foo::new() would work identically to new Foo(), and would solve your use case. It would be more intuitive, I think, and it avoids the problems of changing __construct.
(Un?)fortunately, new() is a valid method name for userland classes in PHP 7.0.
It is indeed, but that means the risk of backwards compatibility breakage is quite low. PHP 7 hasn't been out for long. Thanks! -- Andrea Faulds https://ajf.me/

« previous php.internals (#91432) next »