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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 + 9 = ?
Subscribe to this entry?

 
 [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: Thu Mar 28 23:01:26 2024 UTC