Re: Callable typehint
| From: | Martin Scotta | Date: | Tue, 07 Jun 2011 02:50:44 +0000 |
| Subject: | Re: Callable typehint | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53115@lists.php.net to get a copy of this message | ||
Martin Scotta
On Mon, Jun 6, 2011 at 8:02 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote:
> Hi!
>
>
> The point, though, is that with such a typehint available, we can reduce
>> boilerplate code like the following:
>>
>
> Sure. How about reducing boilterplate code like this:
>
> if(is_readable($foo)) {
> $var = file_get_contents($foo);
> } else {
> throw InvalidArgumentException();
> }
>
trol?
>
> Why won't we make language construct to do that too? I don't think these
> things belong in the language syntax.
>
>
>
>> public function addCallback($callback)
>> {
>> if (!is_callback($callback)) {
>> throw new InvalidArgumentException();
>> }
>>
>> The typehint makes this simpler:
>>
>> public function addCallback(callback $callback)
>>
>>
> You understand that these two pieces of code are completely different - for
> one, you can't catch failing strict type check upstream of addCallback and
> recover.
>
>
> which allows us to rely on PHP's native error handling. I, for one,
>> would love to see this.
>>
>
> I wouldn't love it a bit, frankly, as "rely on PHP's native error handling"
> in this context means "bombing out in runtime without any idea what went
> wrong". When you have exception, you could make it print what happened and
> recover, if you want. When you have fatal error, you can't do much at all.
>
> --
> Stanislav Malyshev, Software Architect
> SugarCRM: http://www.sugarcrm.com/
> (408)454-6900 ext. 227
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>