Hi Anthony,

I understand your concerns and think the work we are doing should be suitable 
to compilers and static analyzers, but that's hard to make everyone happy.

One thing I thought we should reserve for a future release is the addition of a 
set of strict type hints : something like (just example syntax) 'int!', 
'float!', 'string!', 'bool!' (other types are strict already). These types 
would have their counterpart at the ZPP level and their parsing rule would be 
to reject everything except the corresponding zval type.

This way, the user can write :

function convertToInt(string $number): int! {           <- int! instead of int
     if (!preg_match("(^[0-9]{1,17}$)", $number)) {
         throw new InvalidArgumentException("Supplied argument is not a valid 
number");
     }
     return $number;
 }

Which makes it usable for static analysis, I guess. These would be primarily 
used for return types.

Another valuable type would be something like 'numeric!', which could accept 
IS_LONG and IS_FLOAT only. This would be interesting for static analysis, to 
know that it cannot be a string, while accepting any zval numeric value. This 
is a little harder because it should be implemented as an alias of 
'int!|float!', and we wanted to reserve union types for a future release.

About using zval type *and* value, I don't like it too, and I would prefer 
using types only, but I see no way of keeping accepting "31" as int without 
depending of the runtime value. Additional strict types, as proposed above, may 
be a partial solution because those would never care about value.

However, the more I think about it, the more I think that this set of strict 
types will be necessary to design union types, as defining a set of rules to 
convert a zval to a union of weak types, while possible, will be a mess. So, 
future union types could be strict-only, which will make them suitable for 
analysis.

I'm afraid this is probably not what you expect but, as I previously said, I'm 
trying to satisfy as many people as possible. Maybe you're right and '0.3 or 
nothing' proponents are a 'crowd', but I am not doing politics. If this is the 
case, the 'crowd' will win and this will be perfect.

Now, if you want to collaborate on the compromise we are trying to build, I 
really value your opinion. I don't pretend to be right in any way and I 
understand your pov but, if you stay on '0.3 or nothing', I cannot do much more.

Regards

François



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to