|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-10-07 13:35 UTC] nikic@php.net
-Status: Open
+Status: Wont fix
[2014-10-07 13:35 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 18:00:01 2025 UTC |
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