Re: What do we need strict scalar type hints for?

From: Date: Thu, 05 Feb 2015 18:53:20 +0000
Subject: Re: What do we need strict scalar type hints for?
References: 1 2 3 4 5 6 7 8 9 10 11 12  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi François,

> On 5 Feb 2015, at 08:58, François Laupretre <[email protected]> wrote:
> 
> +1. Checking IS_<type> at the C level after implicit conversions and checking this at the
> PHP level are very different.
> 
> IMHO, the key point is the concept of 'type'. Strict typing considers a one-to-one
> correspondence between PHP types and zval types, which is nonsense. At the PHP level, any value
> returning true through is_numeric() IS a 'number', and it must remain so. Any such value
> with a null decimal part is an 'integer' (not the result of 'is_int()') and so
> on.

This simply isn’t how PHP works. PHP has a limited form of type juggling, but the types of values
are not merely an implementation detail. There are numerous places where PHP completely violates the
notion that these types don’t matter, such as comparisons, sorting, functions accepting multiple
types, functions returning multiple types, bitwise operators and array indexing. All of these
discriminate between types. To claim that types are merely an aspect of a zval is ignorance in the
extreme.

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






Thread (78 messages)