> -----Ursprüngliche Nachricht----- > Von: Lester Caine [mailto:les...@lsces.co.uk] > Gesendet: Montag, 2. Februar 2015 21:06 > An: internals@lists.php.net > Betreff: Re: [PHP-DEV] What do we need strict scalar type hints for? > > On 02/02/15 09:12, Dmitry Stogov wrote: > > could you please write down few use cases, when strict scalar type > > hints are really useful. > > Do we NEED strict scalar type control ... No Are there situations where > strict scalar type control may be useful ...Yes Can a > library be built ONLY using strict scalar type control ... Maybe ... provided > that it only requires a set of data that can be 'strict' > > Much has been made of the idea that automatically causing errors when a wrong > scalar type has been passed will simplify > things, and in some cases that may be true, A few examples have been thrown > up which suggest that integer values are a > magic bullet when dealing with time or currency for example, but only some > elements of that can easily be constrained to > integers, other parts will require float or even string. > When there is an error in any of this would one not expect any good library > to produce a sensible set of error messages? A > generic 'value not integer' needs to be augmented, so error checking against > those elements that may be constrained > would be mixed with error checking with the more weakly typed elements anyway? > > I can see that for some cases there may be an advantage but would it not be > better to provide something that can act as a > validity check against any input rather than some limited set of data? One > 'class' that can identify where a scalar can be > constrained or give a more relaxed result when required ... rather than > having one rule for one and one for the other? > > -- > Lester Caine - G8HFL
Nobody would stop you from implementing a utility class Money or likewise and providing a better error message instead of using int if PHP would be strict only (what is not proposed in the RFC anyway). You could also just omit the type hint, it is entirely up to you. There are plenty of strongly typed languages out there which work very well without the mentioned lack of specific error messages for each individual use case. And btw. PHP is strict for array and class type hints as well - of course you can also omit those type hints. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php