Re: Type hinting misunderstood
| From: | Mikko Koppanen | Date: | Sun, 06 Jan 2008 20:02:19 +0000 |
| Subject: | Re: Type hinting misunderstood | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-34537@lists.php.net to get a copy of this message | ||
>
> Why I mean by:
> Type HINTING is not type ENFORCEMENT.
> is that:
> function foo(int $a) {}
>
> foo(1); // OK
>
> foo("1"); // OK - the string is juggled to an int when the
> function is called
> // ENFORCEMENT would have (in some interpretations)
> caused this to
> // FAIL since the function argument was a string.
>
I have not been following very closely this conversation so this might have
been answered already:
$b = '5';
function foo( int &$a )
{
echo gettype( $a );
}
foo( $b );
echo gettype( $b );
what is type of $b after the function call?
--
Mikko Koppanen