On Wed, Jul 1, 2009 at 10:23 PM, Hannes Magnusson<hannes.magnus...@gmail.com> wrote: > On Wed, Jul 1, 2009 at 23:07, Paul Biggar<paul.big...@gmail.com> wrote: >> So, what you're saying is, the patch already handles coercion? If >> that's the case, then problem solved. > > The patch offers scalar type _hinting_. Not type _casting_. > > Type hinting in PHP works very simply: If the value doesn't type-match > the argument information (arginfo internally) then it will be rejected > and E_RECOVERABLE_ERROR thrown. > > In most circumstances that error is fatal. However. If the user > chooses then he can ignore that error (by creating his own error > handler) and continue the execution. > > Type _hinting_ is in no way related to type _casting_.
It should be. The current type hinting is for objects, which in PHP are strongly typed. We plan to extend it to scalars, which in PHP are weakly typed. Adding a strong type system for scalars goes against the rest of the language. As Stas said: > With this patch, we won't have one logic anymore - we'd have two logics - one > for typehinted functions (reject everything that doesn't match the type) and > one for the rest of the language (try to coerce > types). Two logics in one language is usually not good. PHP already has 2 type systems. I don't think that adding a 3rd one is complementary. > Furthermore, the patch introduces couple of new types, "scalar" and > "numeric". These are "magic types" and do value-to-real-type > comparison. No type casting. > The scalar type hint accepts strings, booleans, ints and floats. > The numeric type hint accepts strings (that pass is_numeric()), > booleans, ints and floats. Yes. Therefore only the scalar and numeric types are useful. Nobody wants to use an 'int' hint that fails on numeric strings. Also, I don't know what happens for string hints when you pass an object with a __toString handler, but it should be allowed. Thanks, Paul -- Paul Biggar paul.big...@gmail.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php