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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 - 30 = ?
Subscribe to this entry?

 
 [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: Tue Apr 23 21:01:31 2024 UTC