On Fri, 2008-01-04 at 09:52 -0600, Gregory Beaver wrote:
> Alain Williams wrote:
> > On Thu, Jan 03, 2008 at 10:36:15PM -0600, Gregory Beaver wrote:
> >   
> >> Hi all,
> >>
> >> As someone who has dealt with many scripts written by others as well as
> >> many of my own in a large-scale project (PEAR).  I can say with absolute
> >> certainty that scalar type hints would not make my job easier.
> >>
> >> In fact, it would make it harder.  Many of the functions I work with
> >> require varied input and almost always require some kind of validation
> >> of that input.  A built-in procedure that would either end execution
> >> with a fatal error or suddenly jump execution to a global error handler
> >> that has no idea of the context in which the error was triggered is
> >> almost as useful to me as a PHP extension that runs the pump on an
> >>     
> >
> > You are missing the point.
> > If you want your function to take an argument of arbitrary type, then
> > you simply don't give a type hint[**]
> >   
> But I *don't* want my functions to take an argument of arbitrary type -
> it is in fact you who are missing the point.  A type hint is a poor
> solution to a real problem that is much more easily solved via simple
> input validation and graceful error handling.  The current situation in
> PHP provides a much more flexible solution to the same problem.
> 

Are you suggesting that if a function requires an integer, string, and
object, we use is_int, is_string, and is_object to trigger errors? What
if we have 50 functions like this?

With type hinting:

function a(int $a, string $b, object $c) {
        
}

Without type hinting:

function a($a, $b, $c) {
        if (!is_int($a)) {
                trigger_error(E_WHATEVER, 'Argument 1 to function a() must be an
integer.') ;
        }
        if (!is_string($b)) {
                trigger_error(E_WHATEVER, 'Argument 2 to function a() must be an
integer.') ;
        }
        if (!is_object($c)) {
                trigger_error(E_WHATEVER, 'Argument 3 to function a() must be an
integer.') ;
        }
}

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

Reply via email to