|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 11:01:29 2024 UTC