On Fri, 2008-01-04 at 12:53 -0500, Sam Barrow wrote:
> On Fri, 2008-01-04 at 17:51 +0000, Alain Williams wrote:
> > On Fri, Jan 04, 2008 at 12:37:19PM -0500, Robert Cummings wrote:
> > 
> > > IMHO, optionally inclusion of type hinting for functions/methods can
> > > only be a boon to code quality and readability. IMHO when a type hint is
> > > provided and a parameter doesn't match the type hint then I think a
> > > fatal error should occur. This forces the user of the function that has
> > > type hinting to ensure their data is of the correct type. This prevents
> > > accidental wrong data conversion. However, I see the other side of the
> > > coin too where automatic type conversion could be desirable also.
> > > Perhaps a mixed solution would be viable?
> > > 
> > > <?php
> > > 
> > > function foo( require int $a, require string $b ){}
> > > 
> > > foo( '5', 'bleh' );  // <-- fatal error
> > 
> > No.
> > 
> > > ?>
> > > 
> > > Contrast versus:
> > > 
> > > <?php
> > > 
> > > function foo( int $a, string $b ){}
> > > 
> > > foo( '5', 'bleh' );  // <-- no exception or error $a in foo() will
> > >                      //     be type int (automatic conversion)
> > 
> > Yes. If $a is '5' but reject if $a is '5five'.
> 
> This is what I was considering, but to do something like this we will
> have to implement a whole separate rule set just for type hint
> conversion.

Personally I think it's a bit silly to allow '5' and reject '5five'. The
following is fairly standard behaviour in PHP:

<?php

    echo 'Foo: '.(0 + '5five')."\n";
    echo 'Foo: '.((int)'5five')."\n";
    echo 'Foo: '.(intval( ' 5five' ))."\n";
    echo 'Foo: '.(sprintf( '%d', '5five' ))."\n";

?>

All produce 5.

Cheers,
Rob.
-- 
...........................................................
SwarmBuy.com - http://www.swarmbuy.com

    Leveraging the buying power of the masses!
...........................................................

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

Reply via email to