Re: Callable typehint

From: Date: Tue, 07 Jun 2011 19:04:22 +0000
Subject: Re: Callable typehint
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 07.06.2011, at 12:09, Jordi Boggiano wrote:

> 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.

Precisely.

I'd love to see a "callable" type hint too. And a "scalar" one while
we're at it ;)

David



Attachment: [application/pkcs7-signature] smime.p7s

Thread (63 messages)

« previous php.internals (#53175) next »