Re: type hinting
| From: | Johannes Schlüter | Date: | Sun, 06 Jan 2008 21:03:44 +0000 |
| Subject: | Re: type hinting | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.internals php.internals |
| Request: | Send a blank email to internals+get-34547@lists.php.net to get a copy of this message | ||
Hi,
On Sun, 2008-01-06 at 21:24 +0100, Marcus Boerger wrote:
> That said I would only agree to type hints if we make them respect existing
> PHP conversion rules.
Which we can't really do. Think about Mikko's example:
$b = '5';
function foo( int &$a )
{
echo gettype( $a );
}
foo( $b );
echo gettype( $b );
Casting there would, for sure, create problems. Doing no cast fails when
thinking about Kore's example:
$ php -r 'var_dump( ~"1", ~1 );'
string(1) "�"
int(-2)
Or:
$ php -r 'var_dump( "1" ^ "2", 1 ^ 2 );'
string(1) ""
int(3)
I can see why people want it, but it won't really fit into PHP's type
system imo.
And about the part being "optional": As long as you only use your own
code it's optional, sure. But as soon as you use a library or maintain
code written by others it isn't optional anymore - while that of course
is true for all design decisions made by the previous devs.
johannes