php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #12735 Shorthand for X ? X : Y
Submitted: 2001-08-14 03:30 UTC Modified: 2002-01-28 21:09 UTC
From: david@php.net Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.6 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: david@php.net
New email:
PHP Version: OS:

 

 [2001-08-14 03:30 UTC] 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'.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-28 21:09 UTC] yohgaki@php.net
Won't change....
You can use "or"/"and" also.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 23:01:28 2024 UTC