RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)

From: Date: Sun, 13 Jul 2014 14:21:59 +0000
Subject: RE: [PHP-DEV] [RFC] Scalar Type Hinting With Casts (re-opening)
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-75400@lists.php.net to get a copy of this message
> Which of the two below is clearer:
>
>     function CanDrive($age)
>     {
>         if( !is_numeric($age))
> 	    throw new Error("\$age is not integer (CanDrive())");
>
> 	return $age >= 17;
>     }
>
>     function CanDrive(int $age)
>     {
> 	return $age >= 17;
>     }

I think we're on the same page here that the 2nd one looks better, which
is the point of the RFC.

But the way I see it, the RFC should focus pretty much exclusively on
sanitizing information coming from the 'outer code' and into the 'inner
code', as opposed to enforcing strict typing within the inner code (a
function that unless I'm missing something it does not attempt to do,
thankfully).

The point of the RFC is that as the author of the API, you wouldn't have
to worry about input sanity, while still allowing the dynamic nature of
PHP - AKA type juggling - so that users who call that API don't need to be
bothered with the mechanics of their types either.

Zeev


Thread (250 messages)

« previous php.internals (#75400) next »