|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52148 Modify ternary operator request
Submitted: 2010-06-22 16:35 UTC Modified: 2010-06-22 16:38 UTC
From: clouster at yandex dot ru Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: Irrelevant OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: clouster at yandex dot ru
New email:
PHP Version: OS:


 [2010-06-22 16:35 UTC] clouster at yandex dot ru
There is a need for another operator, which would reduce the code dramatically. 
Be sure there are situations when stupid testing for validity get load of code, 
so i suggest modify ternary operator ( expression ? true : false ) to next 

$foo = "hello";
$bar = "world";

$output = $foo ? $bar;

$output is "hello";

$foo = null (0, false, etc);
$bar = "world";

$output is "world";

Test script:
$foo = false;
$bar = "foo";

echo $foo ? "bar";
echo $bar ? "bar";

Expected result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-22 16:37 UTC] clouster at yandex dot ru
sorry for "stream of consciousness" and my bad english :)
Actually when i said "modify ternary operator" i mean to add new ternary 
 [2010-06-22 16:38 UTC]
-Status: Open +Status: Bogus
 [2010-06-22 16:38 UTC]
The operator exists.  Try your code like this in PHP 5.3:

echo $foo ?: "bar";
echo $bar ?: "bar";
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 17:01:30 2024 UTC