|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-10-12 20:13 UTC] skaventruc at yahoo dot fr
concatenation hazard ... on : $a = 2; echo 'c='.$a*2 .' ok'; it produce a good result : "c=4 ok" but : $a = 2; echo 'c='.$a*2.' ok'; produce a parse error : unexpected T_CONSTANT_ENCAPSED_STRING ... also the following works : echo 'c='.$a*2..' ok'; so it should be a bug when trying to see "2." as a float when it is an integer followed by a concatenation operator (that's the problem when using operators that are also separators...) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
maybe you do not consider it as a bug but it is quite annoying when contatenating arguments, I personnaly think that this is a lack of the parser/compiler to do not detect that the '.' is not a part of the '2' but it is an operator : putting a '.' after the 2 doesn't change it's display. $e = 2.3.'km'; // the dot after 2 followed by a digit // indicate a float '2.3km' $e = 2..'km'; // is ok the the dot after 2 is useless '2km' $e = 2.'km'; // produce a parse error $e = 2 .'km'; // is ok '2km'Yes, of course, I was only thinking that the advantage of PHP over C was that we can concatenate easily strings with expressions and functions results when setting variable, calling functions ... this syntax allow to do : something('a='.$a.' and f(a)*2 = '.f($a)*2.' ...'); instead of : $str = 'a='; $str .= $a; $str .= ' and f(a)*2 = '; $str .= f($a)*2; $str .= ' ...'; something($str); or : $str = sprintf('a=%d and f(a)*2 = %d ...', $a, f($a)*2); something($str); I really think that if you allow this kind of concatenation to avoid complex string composition, then the 'float' problem is a bug, standard C does not allow dynamic string concatenation but in C++ you can overload the '+' operator and there is no confusion with the '.' I know there is always a way to overcome the problem in syntax, my report is only about something that appear to me to be an error. Julien.