Bug #67753 [Opn->Wfx]: Concat not number with number, without space between

From: Date: Tue, 07 Oct 2014 13:35:59 +0000
Subject: Bug #67753 [Opn->Wfx]: Concat not number with number, without space between
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187918@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67753&edit=1 ID: 67753 Updated by: nikic@php.net Reported by: david dot proweb at gmail dot com Summary: Concat not number with number, without space between -Status: Open +Status: Wont fix Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 5.5.15 Block user comment: N Private report: N New Comment: This is a standard problem present in languages using a dot operator (e.g. JS has the same issue if you try to access a property of an integer). It can't be fixed without significant complication of lexical analysis. Previous Comments: ------------------------------------------------------------------------ [2014-08-03 18:04:50] david dot proweb at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=67753&edit=1

« previous php.bugs (#187918) next »