Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83593 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5961 invoked from network); 23 Feb 2015 17:26:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2015 17:26:06 -0000 Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 209.85.212.180 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 209.85.212.180 mail-wi0-f180.google.com Received: from [209.85.212.180] ([209.85.212.180:53883] helo=mail-wi0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/B8-01128-CA26BE45 for ; Mon, 23 Feb 2015 12:26:05 -0500 Received: by mail-wi0-f180.google.com with SMTP id h11so19252611wiw.1 for ; Mon, 23 Feb 2015 09:26:01 -0800 (PST) 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=GcJkxQQxX6V5wP0b0bc7zM6GUVTrcPLEQZAc0dLbQlg=; b=XJeRouQeX/Oxw9L5Pak1Eiz5GUK7tGLCRg55mZTvfIROYyVqHvptJuBZ/YP3Lxb4RM 3DL+IDxQiQpbrwZejOX5tHWc4dShz1xeU8+YJYMESKwFwoMpMCC66S2bZT0i0X/JiIOq aTL0S+cX2xcrzUWiXDhzPPHG0n6/W5r2eqw8FTivNXsrKCfZtK+/mlgMwD22ylHuq48G 81voLLL+tugtAqghC0+EhT/asDwAYunQA+GBKkVKkzGVn07akxnGB/9lr/TZFmm3cYlQ Ddi7r0Ihb/Eqi4pfEQBPkWOL6Iw6UedjXQb/sjOvbwn/1KRdgH8cjdisSPW9cuys9kp8 x+kA== X-Gm-Message-State: ALoCoQnnoUhC20xNtPnCCpwwgjYtPxCJbrw+q6mTK+1+eUmoA96CFZZRpS0X3T+3wUewnbOUvFYE MIME-Version: 1.0 X-Received: by 10.180.211.235 with SMTP id nf11mr23255958wic.52.1424712361340; Mon, 23 Feb 2015 09:26:01 -0800 (PST) Received: by 10.194.192.202 with HTTP; Mon, 23 Feb 2015 09:26:01 -0800 (PST) X-Originating-IP: [217.246.102.4] In-Reply-To: References: Date: Mon, 23 Feb 2015 18:26:01 +0100 Message-ID: To: "Matthew Weier O'Phinney" Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c389103489c7050fc4b25a Subject: Re: [PHP-DEV] User perspective on STH From: kontakt@beberlei.de (Benjamin Eberlei) --001a11c389103489c7050fc4b25a Content-Type: text/plain; charset=UTF-8 On Mon, Feb 23, 2015 at 6:21 PM, Matthew Weier O'Phinney wrote: > On Mon, Feb 23, 2015 at 10:21 AM, Anthony Ferrara > wrote: > > > > And what about other languages that have exactly this behavior? Such > > as Go/Hack/Haskell/etc. Do you see casts everywhere? No. You see them > > where it needs to be explicit. Otherwise, people just write using the > > correct types. > > > > And it also hand-waves over the fact that the same problem exists with > > coercive types. You're going to get the error anyway if you try to > > pass "apple" to an int parameter. So if someone was going to cast with > > strict, they will cast with coercive. > > True. But you're also hand-waving over a point I brought up: many, > many input sources for PHP return strings: HTTP calls, database calls, > etc. With coercive mode, I can pass these values on to other function > calls without a problem; with strict mode, I cannot; I MUST cast > first. > > > > >> If I don't enable strict mode on my code, and somebody else turns on > strict when > >> calling my code, there's the possibility of new errors if I do not > perform > >> validation or casting on such values. This means that the de facto > standard will > >> likely be to code to strict (I can already envision the flood of PRs > against OSS > >> projects for these issues). > > > > Incorrect. The only person that can turn on strict mode is you, the > > author. Now someone can install your library, and edit it to turn on > > strict mode (add the declares at the top of the file). But that's very > > different from what strict proposes. > > Okay, I'm confused then. > > Let's consider this scenario: > > I have a library. It does _not_ declare strict. It _does_ make calls > to either a web service or a database. Let's get even more specific: > the code does _not_ define any _scalar_ type hints, but accepts a > callable. > > function execute(callable $callback) > { > // fetch some data from a web service or database, > // gather item1 and item 2 from it, > // and pass the data on to the callback, which was passed to us. > // Assume that we know that item1 is an int-like value, and > item2 is a string-like value. > $callback($item1, $item2); > } > > You, as a consumer, declare your script in strict mode, and make a > call to my own code. > > declare(strict_types=1); > // somehow import the above function > > $callback = function (int $item1, string $item2) { > // do something with the items... > }; > execute($callback); > > How does that operate? > This may give an error, but this is totaally the fault of the strict_types=1 user. Why does he define a typehint for a closure that is passed to non typehinted code? Its a bug he has introduced himself. This is the only example you can construct to support your view, but its conceptually flawed. A bug on the side of the strict developer. > > https://wiki.php.net/rfc/scalar_type_hints_v5 indicates that the > caller determines strict mode, but I'm unclear what the scope of that > is: does it bubble down the entire stack? or does strict only apply to > the specific calls made (i.e., before it reaches the function/method > declared in the other file)? What happens when $callback is executed, > and $item1 is '10'? Is it interpreted strictly, or weakly? Where is > the boundary for where strict happens, exactly? > > If strict only applies to the execute() invocation, and doesn't apply > to $callback or the calls made to the web service or database, then I > can retract my statements; however, if the strict applies all the way > down the stack from the caller, I can see definite issues. That's what > I'm worried about. > > > > > However, with 2/3 of the options presented in the coercive RFC, you'll > > have an INI setting that changes the behavior of your code for you > > (the other 1/3 is potentially a significant BC break). How is that > > better than a per-file switch? Something you as a library developer > > have no control over... > > Personally, I'd prefer no INI switch, but I also recognize the BC > problems with that RFC. I want to note now, I'm not saying I support > either RFC specifically; my concern is with the dual-mode aspect of > the STH v0.5 (and predecessors). > > > > >> This is what I want from STH, no more no less: sane casting rules, and > the > >> ability to code to scalar types safely. While I can see some of the > benefits of > >> strict mode, I'm concerned about the schism it may create in the PHP > library > >> ecosystem, and that many of the benefits of the coercive portion of > that RFC > >> will be lost when working with data from unknown data sources. > > > > Considering the strict mode is file-local, it's not all or nothing. > > It's up to the author writing code to determine how to handle the > > calls (s)he will make. > > And, as noted, that's the part I need clarification on: is it really > local only to calls made directly in that file, or does strict follow > all the way down the chain? > > Finally, there's the other aspect of type casting coercion from the > competing RFC, https://wiki.php.net/rfc/coercive_sth. The tables in > there make a lot of sense to me, as do the eventual ramifications on > language consistency. If dual-mode is really restricted only to the > direct calls made in the given file, and does not travel all the way > down the callstack, the ideal STH proposal, to me, would be combining > the aspects of the second proposal with regards to type coercion with > the dual-mode. > > -- > Matthew Weier O'Phinney > Principal Engineer > Project Lead, Zend Framework and Apigility > matthew@zend.com > http://framework.zend.com > http://apigility.org > PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11c389103489c7050fc4b25a--