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
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,
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
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
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
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
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
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
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
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());
>>
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());
>>
>>
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
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
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
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
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
16 matches
Mail list logo