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

From: Date: Tue, 29 Jan 2002 02:09:07 +0000
Subject: Bug #12735 Updated: Shorthand for X ? X : Y
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-78399@lists.php.net to get a copy of this message
ID: 12735 Updated by: yohgaki Reported By: david@php.net Old Status: Open Status: Closed Bug Type: Feature/Change Request PHP Version: 4.0.6 New Comment: Won't change.... You can use "or"/"and" also. Previous Comments: ------------------------------------------------------------------------ [2001-08-14 03:30:21] david@php.net 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 this bug report at http://bugs.php.net/?id=12735&edit=1

« previous php.dev (#78399) next »