Bug #76959 [Opn->Nab]: string concat with or without parenthesis
| From: | cmb@php.net | Date: | Tue, 02 Oct 2018 14:07:48 +0000 |
| Subject: | Bug #76959 [Opn->Nab]: string concat with or without parenthesis | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217353@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76959&edit=1
ID: 76959
Updated by: cmb@php.net
Reported by: anatole dot ng at free dot fr
Summary: string concat with or without parenthesis
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Linux Mint 18.3
PHP Version: 7.0.32
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This is expected behavior. The . and the - operator have the same
precedence, and both are left associative, so
"Something : " . 5-2 . " foo\n"
is evaluated as
(("Something : " . 5) - 2) . " foo\n"
Previous Comments:
------------------------------------------------------------------------
[2018-10-02 12:25:13] anatole dot ng at free dot fr
Description:
------------
Hi guys,
Concatenation with some numeric operation results in strange behavior when no parenthesis are used.
$str = "Something: " . (5-2) . " foo\n";
$str2 = "Something : " . 5-2 . " foo\n";
Sorry if it's not a bug, and if I'm wrong...
Test script:
---------------
<?php
$str = "Something: " . (5-2) . " foo\n";
$str2 = "Something : " . 5-2 . " foo\n";
echo $str;
echo $str2;
return
Expected result:
----------------
Something: 3 foo
Something: 3 foo
Actual result:
--------------
Something: 3 foo
-2 foo
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76959&edit=1