Re: Type hinting

From: Date: Wed, 26 May 2010 21:15:58 +0000
Subject: Re: Type hinting
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-48477@lists.php.net to get a copy of this message
Davey Shafik wrote:
Do you propose to have a warning when the types are a mis-match, similar to the array->scalar conversion example from Gustavo? (strtoupper(array('ABC'))) If you have a warning or notice, that warns of potential loss of data accuracy, then I think I'd be OK with auto-converting. Having said that, all other type hints are strict, throwing a catchable fatal error — consistency for what is essentially the same syntax, is more important IMO. Would it be possible to support two syntaxes: function foo( (int) $bar) { } // auto-cast to int
function foo(int $bar) { }      // require int
There has never been casting to objects other than stdClass, so I don't think it conflicts that there is no: function foo( (DBAdapter) $bar) { } - Davey
I completely agree with this option, would vote for it. The two syntaxes and errors if it's not supported. I've wanted this option since it was proposed. Again, from a PHP user.

« previous php.internals (#48477) next »