Re: [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Sun, 13 Jul 2014 11:48:09 +0000
Subject: Re: [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-75390@lists.php.net to get a copy of this message
On 13 Jul 2014, at 12:35, Zeev Suraski <zeev@zend.com> wrote:

> I haven't yet reviewed the conversion table in detail, but unless I'm
> missing something, this RFC is in fact much more in the spirit of PHP -
> and implements type juggling - unlike the previous incarnation of strict
> typing that almost made it into PHP.  It's a bit too strict to my liking
> (especially around conversion of floating point to int, which should pass
> and perhaps generate a notice IMHO), but this is a big step towards the
> spirit of what I proposed together with Lukas back in 2010
> (https://wiki.php.net/rfc/typecheckingstrictandweak) - which was an
> alternative to the strong typing suggested by several others.
> 
> 
> Type juggling is an *inherent* feature of PHP.  Paraphrasing what Rasmus
> said several years ago(*), 'if you implement this [strong typing], please
> don't call it PHP'.
> 
> Again, luckily, what Andrea proposes isn't strong typing.  It still
> maintains the most important properties of type juggling - e.g. the
> ability to work with strings coming in as input (GET/POST/etc.) without
> having to worry about typing.

Right. I think this RFC would strengthen PHP’s weak typing guarantees, because while internal
functions will convert to the right type and hence avoid issues with strings and such not acting
quite like integers in some situations, userland functions usually don’t. This RFC would mean
that, at least for “hinted” functions, user_land_function($_GET[‘id’]) should work just as
well as internal_function($_GET[‘id’]).

Also, it’s not really “what Andrea proposes”, it’s Anthony’s proposal, even if he is sadly
absent from the list these days. I’m just trying to fix up the patch, iron out remaining wrinkles,
and get this into PHP.

--
Andrea Faulds
http://ajf.me/






Thread (250 messages)

« previous php.internals (#75390) next »