Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83930 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92674 invoked from network); 26 Feb 2015 21:24:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2015 21:24:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=pencap@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pencap@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.48 as permitted sender) X-PHP-List-Original-Sender: pencap@gmail.com X-Host-Fingerprint: 209.85.218.48 mail-oi0-f48.google.com Received: from [209.85.218.48] ([209.85.218.48:49134] helo=mail-oi0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B9/D1-32582-32F8FE45 for ; Thu, 26 Feb 2015 16:24:52 -0500 Received: by mail-oi0-f48.google.com with SMTP id a3so12148278oib.7 for ; Thu, 26 Feb 2015 13:24:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZftKf8pdh5PN53VZFZ3ZH1480pGLr8O1wJuCHLdFzzE=; b=FxVl81+WgpjpixXpNyWwX4BT7hL1BJpBNkisRhqSbEIm2VhP3doIDwddNNz0b/Rsh2 NgBEGlFFLcb2MGUBVFMblATkki37ufMg2GZUJHFG0EQJ/dXt0VUjbF8YzMHgU83HV1l3 v1oTMAjlFKErBnIGUTtEB37VR03cRA5lBIavUU3726UPvtpfsdbL4B4/JByBhqb5dDoc sWLtwB+LeGD9wnm6TrKfmU/QNcDi9pBbDliAr2ZjZXFLCV0VqykofUfT7TRxnJESqnmT WmOeeb8XJA6eLplMhDuq5vMdjhTsw9Xau+1jynQp3to8j6kcjBpsa++ZsyE6AeZGqHj0 bYsw== MIME-Version: 1.0 X-Received: by 10.107.34.210 with SMTP id i201mr14512402ioi.1.1424985889190; Thu, 26 Feb 2015 13:24:49 -0800 (PST) Received: by 10.64.125.33 with HTTP; Thu, 26 Feb 2015 13:24:49 -0800 (PST) In-Reply-To: References: <3d639901ae85227b219e7ee59b3140fe@mail.gmail.com> <2a8b6b586398939a6cc6e5ad0ed67924@mail.gmail.com> Date: Thu, 26 Feb 2015 15:24:49 -0600 Message-ID: To: Zeev Suraski Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a114031a0bc5e560510046142 Subject: Re: [PHP-DEV] A different user perspective on scalar type declarations From: pencap@gmail.com (Mike Willbanks) --001a114031a0bc5e560510046142 Content-Type: text/plain; charset=UTF-8 On Thu, Feb 26, 2015 at 3:15 PM, Zeev Suraski wrote: > > -----Original Message----- > > From: Mike Willbanks [mailto:pencap@gmail.com] > > Sent: Thursday, February 26, 2015 10:43 PM > > To: Zeev Suraski > > Cc: PHP Internals > > Subject: Re: [PHP-DEV] A different user perspective on scalar type > > declarations > > > > Here is the most basic example and something that people are going to > > often > > run into. You see this type of code with hydrators, mappers, etc. > > Ultimately > > the end result is going to be the same: > > > > https://gist.github.com/mwillbanks/04e3be68f737c25984ab > > > > I'm not certain if there is a need to explain that bit a bit more. But a > > string > > "1" as a bool should work as with a string "0". For instance, today we > > have > > the following for both string's 0 and 1: > > > > $bool = "0"; > > > > var_dump($bool); // "0"" > > > > var_dump($bool == false); // true > > var_dump($bool == true); // false > > var_dump($bool == 0); // true > > var_dump($bool == 1); // false > > OK, so essentially you're saying that you expect "1" and "0" to be coerced > into booleans. This is something we've been wondering about in the > Coercive > RFC, and in the original version we allowed all scalars to be coerced into > bool - but not the other way around. Right now the RFC only allows for > integer->bool coercion, but the database use case seems to be a pretty > strong one. The options we considered were int only, int+string or none at > all. Float is the one that really stands out as pretty meaningless. > Yes, the database use case and exterior data has been my main concern over the type hint proposals. Now, this could also be changed (fixed, etc) on a different layer (aka database extensions to deal with native types) but that is likely far more to bite off than one would want at this point. It is relatively painless to go in and cast all of those types but the amount of code out there which people are going to just 'expect' this to work will be fairly large and one of those cases that will possibly be cause for migration concerns. > > I think the opposite side is a lot trickier - converting from bool into > string (or any other scalar type for that matter) is quite likely to hide > bugs. We've found a bunch of bugs like that today, where return values of > strpos() are fed without validation into other APIs that expect an offset, > and similar use cases. Such code patterns are bound to be hiding bugs, at > least in some cases. I'm guessing that direction is less of an issue in > your mind, correct? > Yes, direction is less of an issue. --001a114031a0bc5e560510046142--