|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79160 String Concatenation along with condition/ternary operator yields wrong result.
Submitted: 2020-01-23 13:25 UTC Modified: 2020-01-23 13:40 UTC
From: divyaedward89 at gmail dot com Assigned: sjon (profile)
Status: Not a bug Package: Strings related
PHP Version: 7.2.27 OS:
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:
Solve the problem:
25 - 4 = ?
Subscribe to this entry?

 [2020-01-23 13:25 UTC] divyaedward89 at gmail dot com
From manual page:

String Concatenation along with condition/ternary operator yields wrong result.
The condition does not execute as expected. The condition affects the string concatenation.

Test script:

$var='I am not empty';
$query = '';
$query .= 'Value of var='.(empty($var)) ? '0' : $var;
echo $query;


Expected result:
Value of var=I am not empty


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-23 13:32 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: sjon
 [2020-01-23 13:32 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

the proper way to write this is:

> $query .= 'Value of var='.(empty($var) ? '0' : $var);
 [2020-01-23 13:40 UTC]
-Status: Closed +Status: Not a bug
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 11:01:28 2024 UTC