Hi,
Le 13/07/2014 14:56, Andrea Faulds a écrit :
On 13 Jul 2014, at 13:50, Jocelyn Fournier <jocelyn.fourn...@gmail.com> 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.
Actually displaying a warning in E_STRICT but still doing the implicit
cast would not change the function signature.
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.
Indeed :) But I have also performances in mind. Usually (at least in
HACK / Zephir), "type hinting" is used to help the compiler optimize the
code. If this type hinting could be useful to help my code working in a
futur PHP->PECL compiler, or help the PHP opcache to do some
optimisations, I'd like to use "type hinting" as much as possible.
But with the above limitation, I'll not be able to do so.
Thanks,
Jocelyn
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php