Re: [PHP-DEV] [RFC] Callable constructors

2016-03-01 Thread Stanislav Malyshev
Hi! > If constructors had always been callable in PHP, this would be a > standard thing to do and not controversial imo. It's only due to > reasons lost in the mists of time, that object instantiation can only > be invoked via 'new' that it's not possible currently, and so needs an > RFC to change

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-27 Thread Rowan Collins
On 26/02/2016 17:08, Dan Ackroyd wrote: Rowan Wrote: I would like to join Adam in asking if you can find examples in other languages where constructors can be used as though they were static methods in this way. Python would be a good example. constructors are just functions that can be called,

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-26 Thread Dan Ackroyd
On 25 February 2016 at 22:43, Adam Harvey wrote: > Why is having a special syntax that is considered callable and > conflates instantiation and method calls better than having the injector > accept a class name > and use reflection as required to instantiate that? > They're > trivially special

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-26 Thread Johannes Schlüter
On Fri, 2016-02-26 at 11:30 +, Andrea Faulds wrote: > This is true for a trivial implementation like the one above, but I > would point out that a more sophisticated userland implementation could > fix this by generating PHP code. You don't have to generate PHP code for this to work: $arr

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-26 Thread Andrea Faulds
Hi Dan, Dan Ackroyd wrote: On 25 February 2016 at 18:16, Adam Harvey wrote: am I right that this is equivalent to the following? $injector->delegate('FooInterface', function (...$args) { return new FooImplementation(...$args); }); Nope. The vital part you missed is that with the original

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-26 Thread Rowan Collins
On 25/02/2016 22:11, Dan Ackroyd wrote: It's been possible to do that in PDO for years, and people have been using it, and liking it, even if they weren't aware that 'under the hood' the PDO extension was doing the equivalent of calling 'new' as a callable. Actually, PDO_FETCH_CLASS does someth

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Adam Harvey
On 25 February 2016 at 14:19, Dan Ackroyd wrote: > On 25 February 2016 at 18:16, Adam Harvey wrote: >> >> am I right >> that this is equivalent to the following? >> >>$injector->delegate('FooInterface', function (...$args) { return new > FooImplementation(...$args); }); > > Nope. > > The vital pa

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Dan Ackroyd
On 25 February 2016 at 18:16, Adam Harvey wrote: > > am I right > that this is equivalent to the following? > >$injector->delegate('FooInterface', function (...$args) { return new FooImplementation(...$args); }); Nope. The vital part you missed is that with the original function, all of the para

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Dan Ackroyd
On 25 February 2016 at 18:32, Ryan Pallas wrote: > If fetchAll is coming from PDO. then you could have simply done this: > > $records = $db->someQuery()->fetchAll(MyRecord::class); That is a great argument as to why constructors should be callable without using the 'new'. It's been possible to d

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Ryan Pallas
On Thu, Feb 25, 2016 at 11:31 AM, Ryan Pallas wrote: > > > On Thu, Feb 25, 2016 at 11:20 AM, Marco Pivetta > wrote: > >> Just adding to the use-cases: I really could've needed this the other day: >> >> >> $records = array_map([MyRecord::class, '__construct'], >> $db->someQuery()->fetchAll()); >>

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Marco Pivetta
On 25 February 2016 at 13:31, Ryan Pallas wrote: > > > On Thu, Feb 25, 2016 at 11:20 AM, Marco Pivetta > wrote: > >> Just adding to the use-cases: I really could've needed this the other day: >> >> >> $records = array_map([MyRecord::class, '__construct'], >> $db->someQuery()->fetchAll()); >> >>

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Ryan Pallas
On Thu, Feb 25, 2016 at 11:20 AM, Marco Pivetta wrote: > Just adding to the use-cases: I really could've needed this the other day: > > > $records = array_map([MyRecord::class, '__construct'], > $db->someQuery()->fetchAll()); > > I used a named constructor instead, but this results with more inte

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Ryan Pallas
On Thu, Feb 25, 2016 at 9:44 AM, Dan Ackroyd wrote: > Hello internals, > > I've written a small RFC to make it possible to call constructors of > objects as a callable, rather than only being able to call them > through the 'new' language construct. > > https://wiki.php.net/rfc/callableconstructo

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Marco Pivetta
Just adding to the use-cases: I really could've needed this the other day: $records = array_map([MyRecord::class, '__construct'], $db->someQuery()->fetchAll()); I used a named constructor instead, but this results with more internal method calls: $records = array_map([MyRecord::class, 'fromResu

Re: [PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Adam Harvey
On 25 February 2016 at 08:44, Dan Ackroyd wrote: > I use the Auryn* DIC library. What I've wanted to do, and should be > able to do in my opinion, is this: > > $injector->delegate('FooInterface', 'FooImplementation::__construct'); I only skimmed the RFC (and am unfamiliar with Auryn beyond glanci

[PHP-DEV] [RFC] Callable constructors

2016-02-25 Thread Dan Ackroyd
Hello internals, I've written a small RFC to make it possible to call constructors of objects as a callable, rather than only being able to call them through the 'new' language construct. https://wiki.php.net/rfc/callableconstructors After gathering informal feedback for the RFC, one person said