Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85220 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98477 invoked from network); 19 Mar 2015 17:08:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Mar 2015 17:08:36 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wg0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:35693] helo=mail-wg0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/51-25408-1920B055 for ; Thu, 19 Mar 2015 12:08:33 -0500 Received: by wgdm6 with SMTP id m6so68134475wgd.2 for ; Thu, 19 Mar 2015 10:08:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=m4LOer0Ln6OoMOveMY+EKuFvvXVcFNSoXX8eIE+mpJQ=; b=CcWzvPsiu0dTWyZtnKa9G4kzlRSTIk4k6o+GDmldjsvpCzns2OsWiKExanPrdyqOIP 2j7GmYRJxgVXXGQFXiRxP6mo3EM37nZTydZ3nWNUhkzi8uMpvz6U9U5/1tMq3fWotQez EzLhX/ci95BnzJ4s+58gCDVT8BQeY7wFmn4Bc8YDLAjfgKX1WL9dqYXBiSVRDRdTXtVQ GpnTxDJ379j1txYQ6LViSqcqhkrX0OX3wrPyObmYNFmgGR3Cr7ORT31GjWOxy7mrbCDX PX99E9Ha6QorT8sSilmCMUzZ8itN9ysCrTSNVJx5rMsZtDv7syfyCh3Jv5+KaNN5LD0n mElQ== X-Received: by 10.180.79.232 with SMTP id m8mr18304843wix.81.1426784910436; Thu, 19 Mar 2015 10:08:30 -0700 (PDT) Received: from [192.168.0.159] ([62.189.198.114]) by mx.google.com with ESMTPSA id ch6sm2751072wjc.3.2015.03.19.10.08.28 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 10:08:29 -0700 (PDT) Message-ID: <550B0281.5000300@gmail.com> Date: Thu, 19 Mar 2015 17:08:17 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "Sebastian B.-Hagensen" , "S.A.N" CC: Yasuo Ohgaki , Nicolas Grekas , "internals@lists.php.net" , Stanislav Malyshev References: <54BEC072.5000507@mabe.berlin> <54C28B63.1040506@gmail.com> <54C2E405.4090204@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Inconsistencies in callable, call_user_func and direct variable calls From: rowan.collins@gmail.com (Rowan Collins) Sebastian B.-Hagensen wrote on 19/03/2015 16:27: > Another way to unify array and string callback may be to use the > callable syntax and have it return a closure: > callable('strlen'); > callable($object, $methodName); > callable('class', 'staticMethod') Andrea proposed a slightly different syntax for function references a few months back - see withdrawn RFC [1] and accompanying Internals thread [2]. I actually quite like the callable() syntax. Whereas Andrea's suggestion was a parser rule that took a bare string, like &foo, this would have to always take a string, like callable('foo'), but that's good if we want to roll in dynamic callbacks as well: Right now, we have to embed the type information in the variable name, because this is just a string: $hook_callback = 'hook_' . $hook_name; This has a much strong information scent: $hook = callable('hook_' . $hook_name); There's then the question of what kind of object it would return - a Closure? Some child or sibling of Closure? What methods could be usefully provided? What should happen if the arguments provided aren't callable? Throw an exception? Also, do we still need a way to delay testing of callability, to allow this: class A { private function foo() { echo 'foo'; } public function bar(callable $call) { $call(); } } $a = new A; // A::foo is not callable here, but will be when we get inside A::bar var_dump(is_callable([$a, 'foo'] )); $a->bar( [$a, 'foo'] ); Currently works: http://3v4l.org/pNZgn [1] https://wiki.php.net/rfc/function_referencing [2] http://marc.info/?t=140710275400001&r=2&w=2 Regards, -- Rowan Collins [IMSoP]