php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76959 string concat with or without parenthesis
Submitted: 2018-10-02 12:25 UTC Modified: 2018-10-02 15:14 UTC
From: anatole dot ng at free dot fr Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.0.32 OS: Linux Mint 18.3
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: anatole dot ng at free dot fr
New email:
PHP Version: OS:

 

 [2018-10-02 12:25 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-02 14:07 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-10-02 14:07 UTC] cmb@php.net
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"
 [2018-10-02 15:14 UTC] anatole dot ng at free dot fr
Thank you for answering so fast!
And sooooory for this "not a bug" request :-(
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 11:01:28 2024 UTC