Re: Callable typehint

From: Date: Tue, 07 Jun 2011 10:09:17 +0000
Subject: Re: Callable typehint
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Tue, Jun 7, 2011 at 1:02 AM, Stas Malyshev <[email protected]> wrote:
> Sure. How about reducing boilterplate code like this:
>
> if(is_readable($foo)) {
>  $var = file_get_contents($foo);
> } else {
>  throw  InvalidArgumentException();
> }
>
> Why won't we make language construct to do that too? I don't think these
> things belong in the language syntax.

The whole point is that callables are generally not constructed from
user input, they're hardcoded in the code somewhere, and so if a fatal
error occurs, the developer notices it, hopefully during development.

With is_readable, a file can be anywhere, anytime, readable or not, it
depends on the environment the code runs on, and not on the code
itself, so it's not deterministic and you should therefore be able to
easily handle this gracefully.

Cheers

-- 
Jordi Boggiano
@seldaek :: http://seld.be/


Thread (63 messages)

« previous php.internals (#53125) next »