Re: [RFC] Callable constructors

From: Date: Thu, 25 Feb 2016 18:32:56 +0000
Subject: Re: [RFC] Callable constructors
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-91419@lists.php.net to get a copy of this message
On Thu, Feb 25, 2016 at 11:31 AM, Ryan Pallas <derokorian@gmail.com> wrote: > > > On Thu, Feb 25, 2016 at 11:20 AM, Marco Pivetta <ocramius@gmail.com> > 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 internal >> method calls: >> >> $records = array_map([MyRecord::class, 'fromResultSetRow'], >> $db->someQuery()->fetchAll()); >> > > If fetchAll is coming from PDO. then you could have simply done this: > > $records = $db->someQuery()->fetchAll(MyRecord::class); > Sorry, that should have been $records = $db->someQuery()->fetchAll(PDO::FETCH_CLASS, $MyRecord::class);

« previous php.internals (#91419) next »