On 14.04.2011 13:58, Ben Schmidt wrote:
> I have many, many uses for this. E.g. patterns like this:
> 
> class Foo {
>    private $defaultBar;
>    public function foobar(Bar $bar=null) {
>       $bar = isset($bar) ? $bar : $this->defaultBar;
>       $bar->doSomething();
>    }
> }

I'm sorry but this is not a valid use case, isset() is totally
unnecessary here. You can use

  $bar = $bar ?: $this->defaultBar;

Of course it still repeats $bar, but it's not that verbose, and will
work exactly the same as what you do. I'd argue it's even better than
what you do because, if it weren't for that Bar type hint, if someone
passes false or "blah" to your function, isset() will return true, and
you'll try to call doSomething on false/"blah", which is a cute fatal error.

Cheers

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

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

Reply via email to