Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85198 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57657 invoked from network); 18 Mar 2015 17:08:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2015 17:08:03 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wg0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:34376] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 96/90-53852-2F0B9055 for ; Wed, 18 Mar 2015 12:08:03 -0500 Received: by wggv3 with SMTP id v3so40841861wgg.1 for ; Wed, 18 Mar 2015 10:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=wscjUtRed/U/hxB0cVszkwuCq5PrNMSFRQhikCj64ks=; b=Mnivwyfy/Q859loa9/OnmshR3GGZ8I/5KhTIDAZuFT8McwV78hnBEFfsfmXyZHCA8h x9BHct/qz55tDIQL1Jnll2lKJoSTLtsi8Jvo7uxMd8hwMQeOstyH64WoDSNCDPNOOaOs Zc7k8mtqV5XJQApSAJiJtVs0m6D6fuU/49+wiXGRdj2tcacEVPJuRwui3fpuuYjo5jw9 tZdjyCm/wL7PF9HrQNS0RpPDoWSO/rbsn/LZ7O3vpOc70i4QK0HR+RPeAIgqYFbsFlRd EXXXXBPTUOsL1iy+S1mmJFGJzyGAaupsZbHjXmsniEdDphiTOikkLoleUbVroRB1s5wQ Mi5Q== X-Received: by 10.180.102.199 with SMTP id fq7mr8357713wib.89.1426698479866; Wed, 18 Mar 2015 10:07:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.99.212 with HTTP; Wed, 18 Mar 2015 10:07:39 -0700 (PDT) In-Reply-To: References: Date: Wed, 18 Mar 2015 18:07:39 +0100 Message-ID: To: Chris Wright Cc: =?UTF-8?Q?Pavel_Kou=C5=99il?= , Nikita Nefedov , PHP internals Content-Type: multipart/alternative; boundary=f46d04451a8f181926051193201d Subject: Re: [PHP-DEV] [RFC][Accepted] Scalar Type Declarations V0.5 From: linepogl@gmail.com (Lazare Inepologlou) --f46d04451a8f181926051193201d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2015-03-18 16:28 GMT+01:00 Chris Wright : > On 18 March 2015 at 13:12, Pavel Kou=C5=99il wrote: > > > On Wed, Mar 18, 2015 at 2:02 PM, Nikita Nefedov > > wrote: > > > On 18 Mar 2015 15:52, "Pavel Kou=C5=99il" wrote: > > >> > > >> Hello, > > >> > > >> I made that conclusion because in the first example, the library kin= da > > >> forces strict mode rules on the caller, even if he doesn't want to u= se > > >> strict mode - this makes the interoperability of the two modes > > >> problematic. > > > > > > This is incorrect, library force itself to use right types, not you. = I > > don't > > > see any problems here. The only thing that for sure lacks in PHP and > that > > > would make STH better is callable signature types. > > > > > > > Well, it forces you to do that, basically. And also forces you to > > "care" about the mode of library, adding mental overhead. Look more > > closesly at the first example - does the error in that case make sense > > to you (from purely user's point of view)? When you call > > a(function(int $b) {return $b * 2; }) - should you really be required > > to check the context within the a() is declared? > > > > You don't need to check the declaration context of a(). Either the librar= y > is definitely passing an integer and your code will work, or it isn't > definitely passing an integer, maybe it's a float, so you shouldn't decla= re > the parameter type at all - it isn't a typed parameter. This is simply a > matter of RTFM in the library docs (and if there are no docs or the docs > are wrong then you have to go read the library code anyway just as you > would today, so you haven't lost anything). > > Type declarations are a way to more completely describe the interface > contract, they are *not* a replacement/shorthand for casts. If the desire= d > behaviour for your callback should be to accept anything and treat it as = an > integer for the computation, then your code should be written to describe > that intent, i.e: > > a(function($b) {return ((int)$b) * 2; }) > > This code both describes the behaviour of a() and the programmer's intend= ed > behaviour for the callback. Using a type declaration as a means to force = a > cast hides both of these - a reader would assume the callback is always > called with an integer. > > Yet, this code has a major flaw: the type of $b cannot be statically inferred. No matter how "strict" the new mode is, it can only catch errors at runtime. This is usually too late. Having the ability to find error at design time is priceless. For me, this is the primary reason I am using type hints. Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel > > > > > >> Also, the other possible outcome of the scenario (respecting the mod= e > > >> of the place where the callback is declared), is IMHO problematic as > > >> well, because it does not respect the strict mode of the place where > > >> it is called, making it inconsistent with how the dual mode RFC work= s > > >> in general. > > > > > > It doesn't matter where the callback or function was declared, it onl= y > > > matters where it was called. It pretty much is consistent. > > > > This was just a comment about how it would be (also) wrong to solve it > > the other way around. > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > --f46d04451a8f181926051193201d--