Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91409 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89052 invoked from network); 25 Feb 2016 16:44:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2016 16:44:44 -0000 Authentication-Results: pb1.pair.com header.from=danack@basereality.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=danack@basereality.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain basereality.com from 209.85.160.180 cause and error) X-PHP-List-Original-Sender: danack@basereality.com X-Host-Fingerprint: 209.85.160.180 mail-yk0-f180.google.com Received: from [209.85.160.180] ([209.85.160.180:34312] helo=mail-yk0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 55/B1-11730-B7F2FC65 for ; Thu, 25 Feb 2016 11:44:44 -0500 Received: by mail-yk0-f180.google.com with SMTP id u9so24458908ykd.1 for ; Thu, 25 Feb 2016 08:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:date:message-id:subject:from:to:content-type; bh=qKNEUoFlVU/lPWA/DPRRV/ywGmKs+QfiHdax9LjKzIU=; b=eol0jWhMCA1CAmCBKSWKrbRUQsFzMXN9tDt3rPskq6bid4PS0UR9sjS/GiOkwXnWqn /o3MEYGWji6+4oamPZit9SOjZ5ydE2vESCytv5L/eBNBClEMvAKU9K8HNNGnlyFaz0sL xNipeFa82o4zyWqJWJUF1mcEiieTZUDi8AFmTWpW6Rq80ACuucaQiK/xJWbJInhdCxtm Bw3zIYWedg+RGo5AB/qcQ9zIaxx+ebziGHwyDYVjazVZuGp+DclXv5VXJscNq/LJ/jzY FMWeHA2ENEVBGXqXonheNYgiVQL4ZYOjjz+/dqURtKXMKvAbg4VHENFihL3z9eUeS3LX bFlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=qKNEUoFlVU/lPWA/DPRRV/ywGmKs+QfiHdax9LjKzIU=; b=TrDJA4xGn3f379kRpEZzcf8K+7wxMRlYF4VkMW9gNKWkbtvGeRHUVuRgAoFa/UCX+F 2x/+L6vO9ULbdyZt9uyeoptTlkuOoZXBYpytLo6fnc8SkSn1gF/TE71fxguU9Ob0kQap S9umLp16cIrJYo/3UR4ZN0eUKLK78sUELsmaEr6xk8n1RgCxOnA92k3s761T36BGsbfb +4fQpUpd96ERZRh1Qb0fzdMJKv2fP3qSqxYG6FbLDHBtZqokUSgLcO6/xTODbDsomlSi VKvgd+L5vihSW+lj0RvtxPUXcTXG3ZIsDWtAKeuQdHcb/F4I7LdZVI6KInjMwsTwoPVS xrIA== X-Gm-Message-State: AG10YOQE5BCY0f0Ir9cMTNJ6RfBCKe1mS5+GiQwQ1edaSHYxBtBnB3qkjJuzWU/oPgk8u52Xz4fv7DNutjlDMw== MIME-Version: 1.0 X-Received: by 10.37.76.7 with SMTP id z7mr24701847yba.164.1456418681087; Thu, 25 Feb 2016 08:44:41 -0800 (PST) Received: by 10.37.43.85 with HTTP; Thu, 25 Feb 2016 08:44:41 -0800 (PST) X-Originating-IP: [2.98.218.189] Date: Thu, 25 Feb 2016 16:44:41 +0000 Message-ID: To: "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: [RFC] Callable constructors From: danack@basereality.com (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 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