> De : Robert Stoll [mailto:p...@tutteli.ch]
>
> Strict mode is useful in the sense that it prevents unnecessary implicit
> conversions (which are costly) and it improves readability.
> Following an example:
> 
> function foo(string $x, int $y){
>   bar(1);
>   return strstr($x,"hello", $y);
> }
> 
> function bar(float $a){}
> 
> After adding the implicit conversions the code would look as follows:
> 
> function foo(string $x, int $y){
>   bar((float) 1);
>   return strstr($x, "hello", (bool) $y);
> }
> 
> function bar(float $a){}
> 
> In strict mode the original code would not be valid (rightly so IMO).

Actually, your example is partially invalid because strict-typing radicals now 
propose to add a (int -> float) exception to so-called strict mode (which 
proves the approach is flawed, IMHO).

You don't propose a strict-mode alternative in your example. OK, it generates 
conversions and should fail. Now, how would you write the same code using 
strict-mode and without adding casts which would do exactly the same, but 
slower.

If you just mean there's an undetected bug, you're right, but, IMO, a C-like 
syntax like PHP's cannot disable (int -> bool) implicit conversion.

A partial solution can be brought by a set of strict types I am planning to 
define in the single (not so weak) mode approach I am working on (something 
like 'int!', 'float!',...). This would allow people who know what they're doing 
to demand zval-type-based strict checks, arg by arg. It can be used for 
performance reasons and for the rare cases where zval type really matters 
(sorting, for instance). This would be available to internal and userland 
functions.

Regards

François


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

Reply via email to