Re: Bug #12735: Shorthand for X ? X : Y

From: Date: Tue, 14 Aug 2001 09:31:45 +0000
Subject: Re: Bug #12735: Shorthand for X ? X : Y
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-63146@lists.php.net to get a copy of this message
Hi david! On Tue, 14 Aug 2001, david@php.net wrote: > From: david@php.net > Operating system: > PHP version: 4.0.6 > PHP Bug Type: Feature/Change Request > Bug description: Shorthand for X ? X : Y > > Providing default values for fields, I find myself using the following > syntax a lot: > > $a = $result->f('asd'); if (!$a) $a = 'nothing'; > > $a = ($result->f('asd') ? $result->f('asd') : 'nothing'); > > Generally: > > $a = ($x ? $x : $y); ($a = $x) || ($a = $y); there u go, only one eval of $x; > i.e. if 'value if true' is empty, use 'condition value'. can be done with expressions I guess. I do that most of the time, but usually the syntax ends up a bit weird to read. -- teodor

« previous php.dev (#63146) next »