Bug #10770 Updated: . (concatenation) preceeds mathematical operations in order of execution
| From: | sniper@php.net | Date: | Wed, 09 May 2001 23:57:23 +0000 |
| Subject: | Bug #10770 Updated: . (concatenation) preceeds mathematical operations in order of execution | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-54582@lists.php.net to get a copy of this message | ||
ID: 10770
Updated by: sniper
Reported By: vitaliyf@gameaholic.com
Old-Status: Open
Status: Closed
Bug Type: Feature/Change Request
Operating system:
PHP Version: 4.0.5
Assigned To:
Comments:
http://www.php.net/manual/en/language.operators.precedence.php
. and - are equal. Use ()'s to override it.
--Jani
Previous Comments:
---------------------------------------------------------------------------
[2001-05-09 19:21:33] vitaliyf@gameaholic.com
<?
$i=10;
print "hello " . $i-2 . " world";
?>
will output: -2 world
("hello " . $i is evaluated into "hello 10", then 2 is subtracted (by casting
"hello 10" into a 0, then subtracting 2). Then "world" is appened, thus giving
us "-2 world")
I think this might be way counter-intuitive to what should be happening: - (or all other operations)
should be avaluated first, and concatenation last, producing "hello 8 world".
Or how about this example, which definately can confuse some people:
print "Hello is less than " . 1+strlen('hello') . " characters long.";
Workaround: use () to arrange things to be executed in proper order but that might not be obvious
for someone who doesn't know about this situation.
PS:
Thanks PartyZan for finding this.
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=10770&edit=2