RE: [PHP-DEV] A different user perspective on scalar type declarations
| From: | Zeev Suraski | Date: | Thu, 26 Feb 2015 20:18:11 +0000 |
| Subject: | RE: [PHP-DEV] A different user perspective on scalar type declarations | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-83923@lists.php.net to get a copy of this message | ||
> -----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 <ircmaxell@gmail.com>
> 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?
Thanks!
Zeev