Lukas Kahwe Smith <m...@pooteeweet.org> wrote: > On 10.07.2009, at 13:20, Lewis Wright wrote: > > >> 3) function Foo(is_int($x)) { > >> > >> Function is_int is called, an error is raised if it returns false. > >> > > > > But then you're complicating it to the point where it's no longer > > much more > > useful than just calling the is_numeric method in the function body. > > > > Plus > > there's no longer the advantage of optimisers knowing the data-type. > > > right .. lets not forget the original goal (though it hasnt been > perfectly defined) > the idea was to move common validation code out of the function body > to reduce code, increase readability and enable IDE's to be even > smarter. > moving the function body into the signature was not the plan, as it > will kill the above features for the sake of flexibility. > the point is not flexibility, its finding a sensible common > denominator for validation of input parameters and optimizing the > syntax for that case. > > regards, > Lukas Kahwe Smith > m...@pooteeweet.org
I don't believe it kills the above features. 1) Move common validation code out of the function body to reduce code This option moves the validation code out of the body and reduces the amount of code. PHP does the error checking instead of the user having to do something like: <?php function test($x) { if (!is_numeric($x)) { trigger_error(...); } ... } 2) Increase readability If is_numeric($x) is in the method signature, then obviously $x needs to be numeric. Now of course userland code can abuse this, but that is nothing new for PHP. 3) Enable IDEs to be even smarter For the internal functions, this should be very easy for an IDE to figure out: simply remove the is_ from the beginning of the function and you get the desired type. It can then display the method signature and even verify the type supplied. It could also do the same for the userland functions. There may be problems with the contracts idea, but I just don't think these are very convincing arguments against it. -- Joshua Thompson Mechanical Engineer/Software Developer http://www.schmalls.com -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php