Re: [RFC] Scalar Type Hints v0.2

From: Date: Wed, 14 Jan 2015 13:04:05 +0000
Subject: Re: [RFC] Scalar Type Hints v0.2
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-80459@lists.php.net to get a copy of this message
Hi Andrea, On 01/14/2015 11:20 AM, Andrea Faulds wrote:
Hi Thomas,
On 14 Jan 2015, at 10:08, Thomas Nunninger <thomas@nunninger.info> wrote: ---------------- $i = 1; $a = myFunc( $i ); declare(strict_typehints=TRUE); function myFunc( float $f ) {
    return otherFunc( $f );
} function otherFunc( float $f ) {
    ...
} ---------------- As author of strict code I need to replace
    return otherFunc( $f );
by
    return otherFunc( (float) $f );
I'm not sure - if this is what a strict coder wants and - if you find an acceptable way to test your strict code if it works with non-strict code.
I don’t understand, I’m sorry. If you are using declare(strict_typehints=TRUE); then all calls in a file are “strict”. If you are not, all calls in a file are “weak”.
Sorry, if my mail was not clear. My point was: If I write a library in strict mode and someone else is using it from his non-strict mode, he can pass an integer to myFunc() without an error. If I use this integer in my library and hand it over to otherFunc() (in my library) this will fail as integer is not accepted for float. Or did I misunderstood the RFC and there is a casting of the integer to a float when calling myFunc()? Regards Thomas

« previous php.internals (#80459) next »