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
 [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

Pull Requests

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: Thu Dec 05 13:01:31 2024 UTC