Richard Quadling schrieb:
Type juggling just doesn't seem to fit well with me.

You seem to live in a completely different PHP world. Because in our case we use (yes, knowingly use) the PHP type juggling and it safes us lots of manual type conversions.

We get input from all different sources as strings (_GET, MySQL, files) and in a lot of cases we just use it. We don't care if it's a string, a number or a float (or even null), if it yields the right result in our calculation it's fine.

Now if a function only expects int (and truncates floats because of that) like array_reduce does with the $initial parameter then this function is crippled (for no good reason).

Promoting type hints for PHP (and more so scalar type hints, especially specific scalar type hints like int) might give the impression to API developers that highly specified interfaces are better than more general ones. If we can learn something from the current hype around functional languages then it is the fact that generic, data type independant functions can be a very powerful tool. Something like array_* should be as generic as possible and API developers should also be aware of this topic and be given the right signals.

Therefore my conclusion (abusing Einstein ;-)):
Make interfaces as specific as *necessary* but *not more*.

- Chris


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to