Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91415 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1337 invoked from network); 25 Feb 2016 18:20:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2016 18:20:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.175 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.217.175 mail-lb0-f175.google.com Received: from [209.85.217.175] ([209.85.217.175:35747] helo=mail-lb0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/F3-11730-1F54FC65 for ; Thu, 25 Feb 2016 13:20:34 -0500 Received: by mail-lb0-f175.google.com with SMTP id bc4so33773436lbc.2 for ; Thu, 25 Feb 2016 10:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=5YdI0bV1CdpK+56ggZcNyvx+TbhLU4YfY/Ac+XQmK/s=; b=GB9LAl3dQhB4FvbGwY6F9aFEpSLyAfC0Q2iZAK61sGT1hzIxG0jZsIu4SzsTDoDXzP 3a3eWRArz2NmNunf9xcRJ4jmo54j8LqKKIusgOjvPz8yWlTS7bTkGWWJbjtLQuQPYeE5 Ix3LGAzDojzhel/jkQLPr4dsAnsyt5S/gXNDK4VAdiUPDLCTNgjOZXDhEBMQnUpBLQHR Vf5pt3ZAocJxrRv6FoxS0lpMM0nTxg8IkdVGu80usbY1R+x7f4g4PYFK7xHyCf4SlbCE YjJj/z2oqrOMdT2RVF5ZHTgSOhOIxfyFeo/2kpUKE4cKiapWuN4/sxPCA58+SeWFhdWH H3yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=5YdI0bV1CdpK+56ggZcNyvx+TbhLU4YfY/Ac+XQmK/s=; b=mPQp9qkhu18dGtJvyy7mtvab3YpwNkc3E5PmO2ah8YAbeRc5p10acYbFi7VU+G/bQZ 5fC8K6HmR8Fq4/m9IdSFdUYjI5JuoFCCx5x+cWZDLJV4sUJuBC5TFpSxEuphXHXWlThk 0xSU44TCvYlNamd+0lk1gCRVo4ZBZhWwMJG5MohOgTFPDG+hUi5JL2BCzUXx5B+3VGHw fWvWXRq01RpHRT7fTNNuF+Ro6YpV/hl+6gqFo+qkhYQipCoul2IXSDDnKeGyUgYvFLBr mM0xO9PHNz0k7J0h0XtnQax9XjD3NnTMTd1RGNbmnX7FCVsqzoKNo0bXzFF53QVQjTaw w4Eg== X-Gm-Message-State: AG10YOTwUqGA8nzphW3vF2q6WdED3hefppjYTlz41vFAjF/fb9qgxwp7X/bffbpATE2x+TT6dZo7sHtx+0ZoAw== X-Received: by 10.112.129.169 with SMTP id nx9mr17493672lbb.96.1456424431059; Thu, 25 Feb 2016 10:20:31 -0800 (PST) MIME-Version: 1.0 Received: by 10.112.199.234 with HTTP; Thu, 25 Feb 2016 10:20:11 -0800 (PST) In-Reply-To: References: Date: Thu, 25 Feb 2016 13:20:11 -0500 Message-ID: To: Dan Ackroyd Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b3441dadb0987052c9c3c54 Subject: Re: [PHP-DEV] [RFC] Callable constructors From: ocramius@gmail.com (Marco Pivetta) --047d7b3441dadb0987052c9c3c54 Content-Type: text/plain; charset=UTF-8 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()); So yeah, I see some clear advantages in making constructors (static by design) available statically. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 25 February 2016 at 11:44, 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/callableconstructors > > After gathering informal feedback for the RFC, one person said that > they felt it needed more of an emphasis on why it should be > implemented. I wanted to keep the actual RFC short, in the hope that > more people would read it in it's entirety, and also wanted to leave > library specific code out of the RFC. So, as an addendum to the RFC > text: > > 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'); > > Which tells the injector "Whenever something requests an object that > implements FooInterface as a dependency, just execute the > FooImplementation constructor to make that object". > > 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. > > As for the 'BC break' - I would be interested in hearing if anyone > actually (admits to) having any code that would be affected by it. > > I think possibly the best way to manage this BC break, would be to > make call_user_function($fn) behave the same as $fn(), when $fn = > 'Foo::__construct' in a 7.0.x release, before adding the new > functionality in 7.1.0. That would allow people to upgrade to a > version where the changed behaviour breaks entirely, and so they can > fix their code to use the correct calling semantics, before adding the > new functionality in a later version. That give a clear way for people > to detect problems, rather than it being a subtle change which is hard > to detect. However I remain open to ideas on how to manage it better. > > cheers > Dan > > > * https://github.com/rdlowrey/auryn > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7b3441dadb0987052c9c3c54--