Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63391 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64459 invoked from network); 13 Oct 2012 11:31:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Oct 2012 11:31:16 -0000 Authentication-Results: pb1.pair.com header.from=christian.kaps@mohiva.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=christian.kaps@mohiva.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mohiva.com from 80.67.29.23 cause and error) X-PHP-List-Original-Sender: christian.kaps@mohiva.com X-Host-Fingerprint: 80.67.29.23 smtprelay01.ispgateway.de Linux 2.6 Received: from [80.67.29.23] ([80.67.29.23:40654] helo=smtprelay01.ispgateway.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/FA-06472-10159705 for ; Sat, 13 Oct 2012 07:31:15 -0400 Received: from [87.181.60.248] (helo=[192.168.0.3]) by smtprelay01.ispgateway.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1TMzvx-0001Qa-Gi for internals@lists.php.net; Sat, 13 Oct 2012 13:31:09 +0200 Message-ID: <507950FC.7000404@mohiva.com> Date: Sat, 13 Oct 2012 13:31:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120916 Thunderbird/15.0.1 MIME-Version: 1.0 CC: "internals@lists.php.net" References: <5078850D.7090702@sugarcrm.com> In-Reply-To: <5078850D.7090702@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Df-Sender: Y2hyaXN0aWFuLmthcHNAbW9oaXZhLmNvbQ== Subject: Re: [PHP-DEV] Closures and type hinting From: christian.kaps@mohiva.com (Christian Kaps) Hi >> Now if you pass a closure to the scan method which doesn't follow the >> signature of the __invoke method, the engine should throw an error. >> >> What do you think? > You are trying to take typing way beyond what PHP (or probably any > mainstream dynamic language that exists now) provides. There are > languages which provide static type systems capable of doing such > things, but PHP isn't one of them and I don't think it should be. PHP > has no static type control, and IMHO doing type safety validation at > runtime does not seem to be a good proposition for PHP. I thought it would be a good idea to make the closure functionality consistent with the rest of the language. Because closures are currently implemented as class. And with classes it is possible to define static type checks at runtime. The other thing is that I can define a static type control for closures. It works only the other way around. Because the caller can define the static type control and not the interface designer. $closure = function(Foo $foo, Bar $bar) {}; function execute(Closure $closure) { $closure(1, 2); } execute($closure); // PHP Catchable fatal error: Argument 1 passed to {closure}() must be an instance of Foo, integer given Normally as interface designer I would like to define what a caller of the interface should be passed to a certain method. Yes I know with primitive types, this isn't possible in PHP. But with closure I have the option to restrict the interface. Sure I can do this only for one type of a closure. Quasi the the smallest common denominator. But it's possible. So when we look at the above example then it throws an error, because the caller passes the wrong type of a closure to the interface. But what is wrong, I have passed a closure to the method! So it seems that the interface lies. And for me this is the inconsistency in the implementation. I cannot tell the caller, what type of closure he must pass to the interface. And yes, for me a closure can be of a different type. If closures have different parameter signatures than they are of a different type. But this is only my subjective opinion. And I'm guessing by the reactions of my post that I'm all alone with it (o; Cheers, Christian