Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83927 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85051 invoked from network); 26 Feb 2015 20:43:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2015 20:43:15 -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.223.177 as permitted sender) X-PHP-List-Original-Sender: pencap@gmail.com X-Host-Fingerprint: 209.85.223.177 mail-ie0-f177.google.com Received: from [209.85.223.177] ([209.85.223.177:35383] helo=mail-ie0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/70-32582-1658FE45 for ; Thu, 26 Feb 2015 15:43:14 -0500 Received: by iecrl12 with SMTP id rl12so20888418iec.2 for ; Thu, 26 Feb 2015 12:43:10 -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=qib9/BSHHA3g253KMqDBE+yAk0tQQk2uGYJC+JYKuY4=; b=OybrmQCu7AVsNpTmx6Sa+WaS1ieAXOl+S83BaAEWZLR4GuiG8vddoxQGoX9cdxTSQ4 eMV1nuc4yTV/palCbISFllzJKRcg8WZzjqWS6owr8zd3A6TJhlIyfCjXxof3Uyzq2gIF JJ+R+185j2VfwqpcLuJbO3PyB4xhC3SHn07Zk3AQSRvd1l2o7dMrR9mPV1boqACK1Rq0 7r9wMgYyTvBPGEePXcY/JFk6aAr1YsoeqlOI6FAxnDdUOWFsguVtrPWcDRosNTibS9Xf C6CjOiaLnYMA70OVA+w1lJzm8Hl5Dml6ePNPfNB+UkLhtDhoo8APt50mQzSZ9wl24oQr gXsQ== MIME-Version: 1.0 X-Received: by 10.43.64.204 with SMTP id xj12mr6486932icb.9.1424983390825; Thu, 26 Feb 2015 12:43:10 -0800 (PST) Received: by 10.64.125.33 with HTTP; Thu, 26 Feb 2015 12:43:10 -0800 (PST) In-Reply-To: <2a8b6b586398939a6cc6e5ad0ed67924@mail.gmail.com> References: <3d639901ae85227b219e7ee59b3140fe@mail.gmail.com> <2a8b6b586398939a6cc6e5ad0ed67924@mail.gmail.com> Date: Thu, 26 Feb 2015 14:43:10 -0600 Message-ID: To: Zeev Suraski Cc: PHP Internals Content-Type: multipart/alternative; boundary=bcaec517ce0ad23493051003ccda Subject: Re: [PHP-DEV] A different user perspective on scalar type declarations From: pencap@gmail.com (Mike Willbanks) --bcaec517ce0ad23493051003ccda Content-Type: text/plain; charset=UTF-8 Zeev, On Thu, Feb 26, 2015 at 2:18 PM, Zeev Suraski wrote: > > -----Original Message----- > > From: Mike Willbanks [mailto:pencap@gmail.com] > > Sent: Thursday, February 26, 2015 9:46 PM > > To: Anthony Ferrara > > Cc: Dan Ackroyd; Zeev Suraski; Theodore Brown; internals@lists.php.net > > Subject: Re: [PHP-DEV] A different user perspective on scalar type > > declarations > > > > Anthony, > > > > > > On Thu, Feb 26, 2015 at 1:29 PM, Anthony Ferrara > > wrote: > > > > > > Mike, > > > > One point of clarification: > > > > > This is true, however, the types that you are receiving back > form a > > > multitude of data sources might be in a mixed format (databases > > for example > > > often provide representation back as a string, non-json based web > > services > > > provide mainly as a string, etc). While I know what my data > looks > > like > > > and I know I am always going to get a "string" integer back I do > not > > want > > > to have to type cast this each and every time. Or that I have a > > boolean > > > integer representation that is in a string... You get the point. > > Sure, > > I > > > could certainly go in and take 5 minutes and cast each one but > I'm > > not > > > certain why the purpose is there... It specifically changes the > > > determination that PHP is a weakly typed language and all of a > > sudden I now > > > need to care that my string integer boolean is not actually a > > boolean. > > > > It's funny that you bring up boolean... > > > > With the current coercive proposal, you will still need to worry > about > > the types: https://wiki.php.net/rfc/coercive_sth#coercion_rules > > > > > > For some unbeknown reason I was inside of my head going ok, i have a > > string > > integer so that would make an integer and then it would make a boolean. > > Thank you for pointing out my obvious miss there :) > > > > > > > > > > Passing boolean(false) where an integer is expected will generate > an > > error. This is a common practice, specifically around internal > > functions. Example: > > https://github.com/sebastianbergmann/phpunit/blob/a4e23a10d4ee > > ea5fd9fe8916859a07430b94cf42/src/Util/ErrorHandler.php#L58 > > > > So yes, you'll still need to go in and cast each one **in both > RFCs** > > (or handle the errors properly). > > > > > > > > This is certainly a common case, actually quite often for database > > purposes > > do we need to handle booleans to integer conversions which my integer > > comes back as a string (depending on which extension of course) and which > > type field it is. > > Can you explain that in a bit more detail? What's the data flow exactly, > in > both directions? > 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 > > Thanks! > > Zeev > --bcaec517ce0ad23493051003ccda--