Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51893 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29654 invoked from network); 14 Apr 2011 12:08:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2011 12:08:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 74.125.82.170 mail-wy0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:65400] helo=mail-wy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 48/70-25347-3D3E6AD4 for ; Thu, 14 Apr 2011 08:08:53 -0400 Received: by wyb34 with SMTP id 34so1443810wyb.29 for ; Thu, 14 Apr 2011 05:08:48 -0700 (PDT) Received: by 10.227.54.210 with SMTP id r18mr739061wbg.116.1302782927079; Thu, 14 Apr 2011 05:08:47 -0700 (PDT) Received: from [192.168.80.137] (77-58-253-248.dclient.hispeed.ch [77.58.253.248]) by mx.google.com with ESMTPS id y12sm951905wby.59.2011.04.14.05.08.43 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 14 Apr 2011 05:08:43 -0700 (PDT) Message-ID: <4DA6E3CC.2090100@seld.be> Date: Thu, 14 Apr 2011 14:08:44 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101027 Lightning/1.0b2 Thunderbird/3.1.6 MIME-Version: 1.0 To: internals@lists.php.net References: <4D950434.3060704@yahoo.com.au> <4D9E0543.1080600@lerdorf.com> <69.82.36433.EC33E9D4@pb1.pair.com> <4D9E34C4.5000406@lerdorf.com> <4D9E429B.20503@sugarcrm.com> <4D9E96B6.6060401@lerdorf.com> <718216446.20110408143441@cypressintegrated.com> <4DA0E71C.9030008@gmail.com> <4DA63ED8.4080402@yahoo.com.au> <4DA6E151.4030707@yahoo.com.au> In-Reply-To: <4DA6E151.4030707@yahoo.com.au> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Implicit isset/isempty check on short-ternary operator From: j.boggiano@seld.be (Jordi Boggiano) 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/