|  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
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: divyaedward89 at gmail dot com
New email:
PHP Version: OS:


 [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-2023 The PHP Group
All rights reserved.
Last updated: Sat Sep 23 02:01:23 2023 UTC