Bug #79160 [Csd->Nab]: String Concatenation along with condition/ternary operator yields wrong result.

From: Date: Thu, 23 Jan 2020 13:40:06 +0000
Subject: Bug #79160 [Csd->Nab]: String Concatenation along with condition/ternary operator yields wrong result.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225066@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79160&edit=1

 ID:                 79160
 Updated by:         nikic@php.net
 Reported by:        divyaedward89 at gmail dot com
 Summary:            String Concatenation along with condition/ternary
                     operator yields wrong result.
-Status:             Closed
+Status:             Not a bug
 Type:               Bug
 Package:            Strings related
 PHP Version:        7.2.27
 Assigned To:        sjon
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2020-01-23 13:32:22] sjon@php.net

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 http://www.php.net/support.php 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.

https://www.php.net/manual/en/language.operators.precedence.php

the proper way to write this is:

> $query .= 'Value of var='.(empty($var) ? '0' : $var);

------------------------------------------------------------------------
[2020-01-23 13:25:58] divyaedward89 at gmail dot com

Description:
------------
---
From manual page: https://php.net/language.operators.string
---

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:
---------------
<?php

$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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79160&edit=1


Thread (3 messages)

« previous php.bugs (#225066) next »