Re: Ternary operator enhancement for fluent code

From: Date: Tue, 04 Jul 2000 23:03:04 +0000
Subject: Re: Ternary operator enhancement for fluent code
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-23512@lists.php.net to get a copy of this message
I do like some of the proposed functionality but would prefer something that doesn't look like line noise. For example, instead of $foo = $a ? $b; which would set $foo to $a if $a wasn't false and $b if $a was false, even resusing or again to produce something like $foo = $a or $b; seems cleaner. Even better might be a function which would return the first parameter which isn't false: $foo = first_valid($a, $b, $c, $d ...). This would be handy for more than simple binary work, too:
    $text_color = first_valid(@$MemberSetting["PageColor"],
@$InstallationSetting["PageColor"], "WHITE"); The other advantage, of course, is that this wouldn't require any changes to the core language, which is why I wrote http://gateway.digitaria.com/~chris/php/first_valid/ back when I needed it.
Maybe you´ve got the motivation to create some enhancement report? A function that returns the first variable sounds to have big chances to be implemented... I´d welcome 1) one function which checks for identity against FALSE and another function 2) that performs an isset() on each var regards -- o----------0-¬---------O-·---¬----o---®-----o o O ° . | http://www.kiffen.de | pRoteçt y0ur bRaín |0 O ° ¤ ° · 0°·³°²'²³-¹'³´³°^°³~³²³°'³²²¨³²^³¹³²°²³`³º³°Þ ° o © ° . · | psychedelic experience | gott@kiffen.de | O ° o ° o-¬--o--0-----©-·--O-----o-----0-¤----------o 0 ° · ° . ¤ ·

« previous php.dev (#23512) next »