php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: clouster at yandex dot ru
New email:
PHP Version: OS:

 

 [2010-06-22 16:35 UTC] clouster at yandex dot ru
Description:
------------
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 
variant:

$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:
----------------
bar
foo


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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 
operator.
 [2010-06-22 16:38 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2010-06-22 16:38 UTC] rasmus@php.net
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: Fri Apr 19 04:01:28 2024 UTC