Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94171 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20799 invoked from network); 21 Jun 2016 09:44:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2016 09:44:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=inefedor@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=inefedor@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.50 as permitted sender) X-PHP-List-Original-Sender: inefedor@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-lf0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:34955] helo=mail-lf0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/C0-14239-18C09675 for ; Tue, 21 Jun 2016 05:44:34 -0400 Received: by mail-lf0-f50.google.com with SMTP id l188so14827378lfe.2 for ; Tue, 21 Jun 2016 02:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:date:subject:mime-version:content-transfer-encoding:from :message-id:user-agent; bh=BMXUCYiZnEc9bQXRtugv/yAj46qmSGucnPkB/SzTEc4=; b=MxRv/UbfVE2Ml9OcIEepuEKOOKlKAjAWjoByq6jRp6wf2SMLaagZEtXywFpWGbkx0j 8gYTs1Mpr9Z0Cfb1dBunEb7Hn5Tw7DeSdMG7JqEsqpKX7mMsbbPU2dTemywqUq4Krstc zsNySMxm5ftHYs2w9N1ZLTHchl43MEOy/V7pSf3gZp1yAYmNFKSYGHIFsfDPftB6LInN gEJQXfbjSKr9b3Tg1LZFaCJpNIlv+f4qMbaZOIXMZ1KLjh4d1W+nkwhz7kiRm5a1DEiy g5/3/oB1loLd4Ln9rBVuO72WXzHxiQJ2KHY5NIIxXwsgqQlDNTXgETmbg2Dq6ZSUAOef OMEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:date:subject:mime-version :content-transfer-encoding:from:message-id:user-agent; bh=BMXUCYiZnEc9bQXRtugv/yAj46qmSGucnPkB/SzTEc4=; b=GQ8haa2+2boR6X/oDAwZJ60DojxRLkQqDRZHVmGOV6b8RQJgSF/qkl6ye+orOS973Q SfWQRWnfcSLH49MNRkJZB9nBaVSjiEcNLAc3VAeBAc0t5+iVoLVYPjBLOUK7nLPJ0nrj saz9Xyh+53eHkbglF51zlONlxau/qB1oVPcZzqdTYKkcPO/cMml710oj148toRNXfMsW HBTUh55gNhXu2fWF3C7Qp+W4Da2dgmjcPALlJ5SoDM5OFffQ8kOQK8m1IXVFMzuWuupF PgqD9VGSuHFJjMNA7En2H/akHQAdaVqcNDVALITFfPde8NT7O2O0YGHTrhBjNVL3W1Ez hUYA== X-Gm-Message-State: ALyK8tIfoKfRpd4YIsevSJ0P1GDKsQH9+Gl55z+lnBp4ejByVQs3ad2CILanr70ZN7g6VQ== X-Received: by 10.25.20.95 with SMTP id k92mr6232123lfi.207.1466502270540; Tue, 21 Jun 2016 02:44:30 -0700 (PDT) Received: from nikita-pc (broadband-95-84-234-130.nationalcablenetworks.ru. [95.84.234.130]) by smtp.gmail.com with ESMTPSA id mh10sm6592655lbb.14.2016.06.21.02.44.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 21 Jun 2016 02:44:29 -0700 (PDT) Content-Type: text/plain; charset=koi8-r; format=flowed; delsp=yes To: "internals@lists.php.net" Date: Tue, 21 Jun 2016 12:44:29 +0300 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Message-ID: User-Agent: Opera Mail/12.17 (Win32) Subject: Statically verifiable callables From: inefedor@gmail.com ("Nikita Nefedov") Morning internals, I would like to gather some reactions on the proposal to add a 'statically verifiable callable as a closure language construct'. That would be functionally similar to the recently added Closure::fromCallable() with the exception being statically verified by IDEs or precompilers/linters/code inspection tools. Right now it is absolutely context-dependent guess whether `[$obj, 'foo']` is a reference to a method `foo` of `$obj` or something completely different. This makes code analysis and refactoring very hard when it comes to using methods/functions as callables passed somewhere. What I'm proposing is to add a language construct, the usage of which would look similar to this: function bar() {} class Foo { function dyn(){} static function stat(){} } callable(Foo::stat); callable((new Foo)->dyn); callable(bar); callable() construct would return a Closure instance, just like Closure::fromCallable() does but without the overhead of parsing the array and with all function/class identifiers being T_STRINGs rather than string literals. The main advantage for me personally will be IDEs being able to implement refactoring and code highlighting (=> more readable) features on top of this (e.g. rename method can also rename all accesses to this method but not when it's a string literal). I'm aware that people might not like the fact that with this syntax method access looks completely the same to the field access and can be misleading for novices or can harm readability of the code. If someone has better ideas we can all share them here. The patch should be pretty simple, here for example are the parser changes I made to make sure this syntax is possible: https://gist.github.com/nikita2206/bf419c8c23479bbf826c31cffe16a749