Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83929 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90273 invoked from network); 26 Feb 2015 21:15:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2015 21:15:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=zeev@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=zeev@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.223.178 as permitted sender) X-PHP-List-Original-Sender: zeev@zend.com X-Host-Fingerprint: 209.85.223.178 mail-ie0-f178.google.com Received: from [209.85.223.178] ([209.85.223.178:43190] helo=mail-ie0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FE/51-32582-90D8FE45 for ; Thu, 26 Feb 2015 16:15:54 -0500 Received: by iebtr6 with SMTP id tr6so21283259ieb.10 for ; Thu, 26 Feb 2015 13:15:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:references:in-reply-to:mime-version :thread-index:date:message-id:subject:to:cc:content-type; bh=51x1enYp5/k6QZWPt5L+E9vk4/68glXQMv/D8AQ04b8=; b=Iizv/MF5EF4C6oxIYiLyot7m55ni72vWCbPtkiypVWPH9/0IcA05XGMhY3lO+/QYiH 3Qk/a/Ur3NgQTQ0j9KJcakFW8PB7EL5PZ+koMfTRrl/r0aJFnWNJwULFR/bJpHVgOuUs d+Mr3cFXZBvQq75DLHBMPL2B2yxuu6gvRsvIQLwJmL4WY7w3IT4Cxsdpe/ywdxBqatpB m+tekR2s1gYqMBRr5s9Zghvh07TFgZ/ImhlkoVTNq6VzCLW57T3KpTScRFg0FDpaAl2m /W1Vf7lIgHGfnHhJhoTImb5R2VjdHrB/A53aU+pF3i4xPjUBZhbt8HWf/c/payZooR8y I/pw== X-Gm-Message-State: ALoCoQmYK1QtBk5rqiNV004c/OGb00pkMVTDhd9kaWCObdjhDprjFgVtrN/aDhMEnxSpCvlC3HMguJA4/ggMZBSRCNgtVV4PkEWJdtWnMC2pmzo0IYYuyKWwu25lGpXKutdlCHI3ONR1yVaWg6rQHS4qV0wlyT3s5w== X-Received: by 10.50.30.202 with SMTP id u10mr36616927igh.35.1424985350246; Thu, 26 Feb 2015 13:15:50 -0800 (PST) References: <3d639901ae85227b219e7ee59b3140fe@mail.gmail.com> <2a8b6b586398939a6cc6e5ad0ed67924@mail.gmail.com> In-Reply-To: MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGwbbdURx2shUG2o7Zj2Ywptu8MnAHNhHseASj3TG8CBU/YnAHY8IsNAja8iU0CV/sRfgD/+/f7nOAYvdA= Date: Thu, 26 Feb 2015 23:15:49 +0200 Message-ID: To: Mike Willbanks Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: RE: [PHP-DEV] A different user perspective on scalar type declarations From: zeev@zend.com (Zeev Suraski) > -----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. 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? Zeev