On 14 Jul 2014, at 15:38, Derick Rethans <der...@php.net> wrote: > I am worried about this big casting conversion matrix. New rules should > not be invented, and the following should *always* be equivalent: > > function foo(typehint $var) > > vs: > > function foo($var) { > $var = typehint $var; > > In general, I am not in favour of casting typehints, as it would be a > different behaviour from the hard-check typehints that we already have > for classes and arrays.
I’ve talked about this before in this thread, but the justification for differing in behaviour from array and class hints is that these types are scalars (which PHP routinely juggles) and arrays and objects are not scalar (and not routinely juggled). While we are indeed casting, we’re only doing so where the conversion would be lossless. Sure, it’s not a hard check, but it is still quite strict. I don’t like the idea of completely strict type hints here, but I also don’t think that completely loose type hints that cast and do zero validation are for the best either. This RFC tries to strike a compromise. -- Andrea Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php