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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sat Dec 21 13:01:31 2024 UTC