Bug #67753 [NEW]: Concat not number with number, without space between
| From: | david dot proweb at gmail dot com | Date: | Sun, 03 Aug 2014 18:04:51 +0000 |
| Subject: | Bug #67753 [NEW]: Concat not number with number, without space between | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-186949@lists.php.net to get a copy of this message | ||
From: david dot proweb at gmail dot com
Operating system: Irrelevant
PHP version: 5.5.15
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Concat not number with number, without space between
Description:
------------
Ideally we always need to use spaces between concatenations.
$a = "Hello" . "World";
But in most cases, we can omit it.
$a = "Hello"."World";
$a = $b.$c;
Except when we have two numeric, for obvious reasons.
Speaking softly: it's because it becomes a float.
$a = 1.1;
However, suppose you want to concatenate a variable with an integer.
What do you would think?
$a = $b.1;
Exactly! The variable $a will get $b concatenated to the integer 1.
Err... Wait! Wait!
Parse error: syntax error, unexpected '.1' (T_DNUMBER), expecting
',' or ';'.
This also affects the reverse:
$a = 1.$b;
The problem occurs because PHP thinks that a dot and a number is a
"simplified float" (without integer part, or zero). However, in this
case is just (or should be) an integer concatenated, since we can not
expect a T_VARIABLE T_LNUMBER side to side.
Test script:
---------------
$a = 1;
// Expect all is true.
var_dump( $a . 1 === "11" );
var_dump( 1 . $a === "11" );
var_dump( $a . .1 === "10.1" );
var_dump( .1 . $a === "0.11" );
var_dump( $a..1 === "10.1" );
var_dump( .1.$a === "0.11" );
// Bad guys.
var_dump( $a.1 === "11" );
var_dump( 1.$a === "11" );
Expected result:
----------------
true
true
true
true
true
true
true
true
Actual result:
--------------
true
true
true
true
true
true
Error
Error
--
Edit bug report at https://bugs.php.net/bug.php?id=67753&edit=1
--