Re: [PHP-DEV] Bug #12735: Shorthand for X ? X : Y

2001-08-14 Thread teo

Hi david!
On Tue, 14 Aug 2001, [EMAIL PROTECTED] wrote:

> From: [EMAIL PROTECTED]
> 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

-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #12735: Shorthand for X ? X : Y

2001-08-14 Thread david

From: [EMAIL PROTECTED]
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);

It would be handy to have a shorthand for this that would easy typing,
legibility, and avoid duplicate evaluation of $x.

Proposed syntax (not fussy)

$x ?: $y

i.e. if 'value if true' is empty, use 'condition value'.
-- 
Edit bug report at: http://bugs.php.net/?id=12735&edit=1


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]