On 13 Jul 2014, at 13:50, Jocelyn Fournier <[email protected]> wrote:
> Would it possible to control the implicit casting through a PHP variable ?
> (or perhaps modify E_STRICT to display a warning if this kind of implicit
> cast is done ?)
No. I mean, yes, it’s possible, but allowing the effective function signature
of a function to change based on some variable or ini setting does not sound
like a good idea to me.
> I mean specifying explicitly a type is often useful to make sure the proper
> type is passed to the function, and there's no bug in the calling func.
>
> e.g. safety check like
>
> function foo($bar) {
> if (!is_int($bar)) {
> throw new Exception('Invalid parameter type');
> }
> }
>
> will not be "equivalent" to
>
> function foo(int $bar) {
>
> }
>
> and there will be no way to have an equivalent behaviour once "type hinting"
> is used !
You just demonstrated one:
> function foo($bar) {
> if (!is_int($bar)) {
> throw new Exception('Invalid parameter type');
> }
> }
If you really want to continue doing that, nothing would stop you.
--
Andrea Faulds
http://ajf.me/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php