On 25 February 2016 at 18:32, Ryan Pallas <derokor...@gmail.com> 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 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. But why is it restricted to PDO? Why can't I do the equivalent with other DB libraries of my choice? Why can't I use it with userland libraries that retrieve data from Redis, Mongo or any other datasource? It has shown to be a useful pattern inside PDO. We should be empowering userland developers to have the same tools available to them as extensions do, wherever possible. This RFC would allow the equivalent of PDO::FETCH_CLASS to be implemented by userland code. Which sounds great to me. > Moreover, if you want to pass in a callable that creates the class, why not > just create a method on that class called create (or whatever) much the > same way that singletons often work. Why should every PHP developer have to jump through that hoop, why can't we (as the RFC proposes) make constructors be callable, instead of having to create another method just to call something that should have been callable in the first place? And to be precise, people need to use code that was either written outside their organisation, or within their organisation but in another department. In either case it wouldn't be possible to alter the code just to make it callable in a certain way. And so it would be easier if the language just supported something that could have been supported right from the start. cheers Dan -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php