Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91421 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14297 invoked from network); 25 Feb 2016 20:28:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2016 20:28:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.43 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.43 mail-wm0-f43.google.com Received: from [74.125.82.43] ([74.125.82.43:37540] helo=mail-wm0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/46-11730-3E36FC65 for ; Thu, 25 Feb 2016 15:28:20 -0500 Received: by mail-wm0-f43.google.com with SMTP id g62so44070618wme.0 for ; Thu, 25 Feb 2016 12:28:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=VpP7+QdsXA4frygAqzrwM6K5KO/z4xGjwMrzOWfyh7c=; b=nVOwrul4L9VD1B084SLOVrdgpTiR3IUEQgqkFEFUHAwcd5X70ge20CaDVT+fupNjjx Zo/Tzxb4N85YUM9369/jCzXnYrxzXtprImOQWDCTgC8TzzjjgftBpXtEejyr2h6YZY2r gac915zeM1jA+vhoIqpG8MbN64To0Xll/TOVIb1MZZENyvC/WOojRLgCdgM6GrP92D2K cdY6AyfPD9RQ2MPFsi5+eqW28+bnGkqePQVbNIVVxLPPFaTOmefFyVom4R2qxNmODGeE y0X+IxdhJCCEFyKhupm51yDOSrRBkS1CV+N80Mf4hl0AwFThRLkv8Er19LSNvIYxfeZc WBbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=VpP7+QdsXA4frygAqzrwM6K5KO/z4xGjwMrzOWfyh7c=; b=nGksxGXA0Iq5Y9bCub8uf1+kVZ8JUI1krRMH/3Ke/m3n0yJNF21XAZ059dNQPJLt+D JD981l/A8Hi7lYx9OFIXgOyqtNG6+W2v0muU0VQQZRAMSEnuhSORSopktk0oXvyLvdzR cxOsWd/fZgS2+HV1rQb6CoRdNmeuFbiFOERywr4U32ocG/9U9NZqNVd6PZt0HDaQ2OkK z2viXgqnJ/s6BTeE542ZXhTRXKmPeLM8dcpJulQX4KlShEqPtCbDRsDLZn3Lxz1H4r4R yBADi/oPySMJHvAhNm/gc8gi3+KJdL9zUSAzsaO+kzC5R+UYz58Hn86AFKnDfY786yXd XPrQ== X-Gm-Message-State: AG10YOR3RtFYNVlFx7PLn03OlRgsrE1tAierhPZynr9yyXras7sZI1851RoTE/RatrtVyg== X-Received: by 10.28.72.197 with SMTP id v188mr583597wma.34.1456432096000; Thu, 25 Feb 2016 12:28:16 -0800 (PST) Received: from [192.168.1.189] ([95.148.161.211]) by smtp.googlemail.com with ESMTPSA id av3sm9494701wjc.44.2016.02.25.12.28.14 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Feb 2016 12:28:15 -0800 (PST) To: internals@lists.php.net References: <97.82.11730.D8C3FC65@pb1.pair.com> Message-ID: <56CF63D8.8020005@gmail.com> Date: Thu, 25 Feb 2016 20:28:08 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <97.82.11730.D8C3FC65@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: [RFC] Callable constructors From: rowan.collins@gmail.com (Rowan Collins) On 25/02/2016 17:40, Andrea Faulds wrote: > Dan Ackroyd wrote: >> 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 > > While I like the concept, I dislike the execution. Snipped for brevity, but I agree with your sentiment here. Making __construct more magic seems like an imperfect solution to this. I'm not sure making a new magic method (new, __new, etc) is much better though, since it would serve such a limited purpose. It has come up before in various contexts that PHP lacks a true callable type, in the sense that you never "construct" a callable, you just *use* something as a callable. I think callable constructors would fit better as part of an API that solved this. For instance, there could be a (magic) Callable class with various named constructors: - Callable::forFunction(string $function_name) - Callable::forMethod(object $instance, string $method_name) - Callable::forStaticMethod(string $class_name, string $method_name) - Callable::fromPaamayimNekudotayim(string $class_colon_colon_method) // OK, maybe not ;) This isn't perfect, because the parameters would still look like strings to static analysis, rather than being proper compiled-in references, but it's nicer than repeatedly analysing an array or string to evaluate is_callable() or type-checks. Then we could add to that a special case for constructors: - Callable::forConstructor(string $class_name) This would be roughly equivalent to (and polyfillable with): return function (...$args) use ( $class_name ) { return new $class_name(...$args); }; Regards, -- Rowan Collins [IMSoP]