Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85197 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49861 invoked from network); 18 Mar 2015 15:37:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2015 15:37:03 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.48 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.48 mail-wg0-f48.google.com Received: from [74.125.82.48] ([74.125.82.48:35882] helo=mail-wg0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/F2-32095-C9B99055 for ; Wed, 18 Mar 2015 10:37:01 -0500 Received: by wgra20 with SMTP id a20so38534348wgr.3 for ; Wed, 18 Mar 2015 08:36:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=BDiVJs8+MXWkOCw5JkY6d7gMCtntUEN50XbmBesyCc8=; b=QFCPo+IWkGZ7hLJBro8ZlcUy5H9zaeRYbtLDmw3MzoSDUZ5wBNtA/lV7lNm0pdE6JE 1qOD1JEndC5lqvi0R0w/D8UamxF8nyY1vjH24NUkCJvxxAAR5IPKSqfD5/SNhfuZXz6c 8wmFjyo06E/OgkOOq1TM/Iuk1qGI61zva+v6tflZPDtGncq7X5TpRLbI//mwFBEf7bQU Ao216lbWtSJPDYThETRGPhNfJKM1d9s+QG4A5PcihKedq8rUvRdZlD6e3HohHIDN0StJ sxnB8/SdKl0pi+ILpK2h9iJjsMKXbMVcGY+kQdFY1UEh0b0LA3IzyK0z73Ryb0AFfN/7 b7UQ== X-Gm-Message-State: ALoCoQn8WBSm45ym4czhVfK7dPnHynqsuE7k/2jaEZkpgbnfM3AMn+C91wBhQl7WMoeogQctEZ1Z MIME-Version: 1.0 X-Received: by 10.194.239.65 with SMTP id vq1mr139036670wjc.98.1426693018193; Wed, 18 Mar 2015 08:36:58 -0700 (PDT) Received: by 10.194.36.134 with HTTP; Wed, 18 Mar 2015 08:36:58 -0700 (PDT) X-Originating-IP: [93.129.137.33] In-Reply-To: References: Date: Wed, 18 Mar 2015 16:36:58 +0100 Message-ID: To: Chris Wright Cc: =?UTF-8?Q?Pavel_Kou=C5=99il?= , Nikita Nefedov , PHP internals Content-Type: multipart/alternative; boundary=001a11c1b8f08da7dc051191da39 Subject: Re: [PHP-DEV] [RFC][Accepted] Scalar Type Declarations V0.5 From: kontakt@beberlei.de (Benjamin Eberlei) --001a11c1b8f08da7dc051191da39 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Wed, Mar 18, 2015 at 4:28 PM, Chris Wright wrote: > 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. > > > > > > >> 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 > > > > > there is even a better argument for this, say you can add a callback to your franework to register actions and it has to be: function (Request $request, Response $response) { } This is the "public interface" of the callback so to speak. If you add something different, you get a catchable fatal error, because you use that library wrong, right now in PHP 5.*. I don't see how strict mode enabled in a library, forcing you to define the right signature for scalars is problematic from any POV. Granted you can even just omit the scalar type hints completely and it would work. --001a11c1b8f08da7dc051191da39--