开发者

Think I found a bug in PHP v5.3.3-1ubuntu9.5 CLI?

开发者 https://www.devze.com 2023-04-03 02:44 出处:网络
I may have found a bug, if so who do I report this too? Here is what I\'ve got: for ($i = 0; $i <= ($count)-1; ++$i) {

I may have found a bug, if so who do I report this too?

Here is what I've got:

for ($i = 0; $i <= ($count)-1; ++$i) {
 Lots of code...more then I want to put here
....
.....
.....
$mailto = $mailto . $i +1 . ") " . $name . " " . $location . " Type: " . $type . " Status: " . $geostatus . " Difficulty " .$difficulty . "\n" . $region . "\nHidden: " . $hidden . " Last Update: " . $lastupdate . " Last Found: " . $lastfound . "\nDistance: $distance Bearing: $bearing degrees $direction\n\n";
}

echo "$mailto \n";

The output will look like this:

4) Morrow Parking - RR Relic LMBT Lat: 39.35455 Lon: -84.133733 Type: Traditional Cache Status: Active Difficulty 3
City/State: Morrow, OH Warren Co.
Hidden: Wed June 09 2010 04:00 Last Update: Wed August 03 2011 17:43 Last Found: Wed December 31 1970 19:00
Distance: 4.31 Bearing: 212 degrees SW

Showing me only the last item in the list. However if I change the code just slightly to this:

for ($i = 0; $i <= ($count)-1; ++$i) {
 Lots of code...more then I want to put here
....
.....
.....
$cc = $i +1;
$mailto = $mailto . $cc . ") " . $name . " " . $location . " Type: " . $type . " Status: " . $geostatus . " Difficulty " .$difficulty . "\n" . $region . "\nHidden: " . $hidden . " Last Update: " . $lastupdate . " Last Found: " . $lastfound . "\nDistance: $distance Bearing: $bearing degrees $direction\n\n";
}

echo "$mailto \n";

I get the full output as I expect to see:

1) Uranus - The Solar System - Lil Miami Bike Trail Lat: 39.415517 Lon: -84.103383 Type: Traditional Cache Status: Active Difficulty 1.5
City/State: , OH Warren Co.
Hidden: Sun October 17 2010 04:00 Last Update: Fri August 05 2011 18:25 Last Found: Wed December 31 1970 19:00
Distance: 0.92 Bearing: 309 degrees NW

2) 79 Lat: 39.394517 Lon: -84.096533 Type: Traditional Cach开发者_开发知识库e Status: Active Difficulty 2
City/State: , OH Warren Co.
Hidden: Sun May 30 2010 04:00 Last Update: Wed August 03 2011 17:42 Last Found: Wed December 31 1970 19:00
Distance: 0.93 Bearing: 201 degrees S

3) RR Relic - Oregonia Lat: 39.462583 Lon: -84.100383 Type: Traditional Cache Status: Active Difficulty 1.5
City/State: Oregonia, OH Warren Co.
Hidden: Sun May 02 2010 04:00 Last Update: Wed August 03 2011 17:41 Last Found: Wed December 31 1970 19:00
Distance: 3.88 Bearing: 351 degrees N

4) Morrow Parking - RR Relic LMBT Lat: 39.35455 Lon: -84.133733 Type: Traditional Cache Status: Active Difficulty 3
City/State: Morrow, OH Warren Co.
Hidden: Wed June 09 2010 04:00 Last Update: Wed August 03 2011 17:43 Last Found: Wed December 31 1970 19:00
Distance: 4.31 Bearing: 212 degrees SW

Did I find a bug, or am I doing something wrong in the 1st way, and correct in the 2nd way?

And if I did find a bug, who do I report it too.

PHP v5.3.3 running CLI version on Ubuntu 10.10 Thanks.


In the first bit of code, change:

$mailto = $mailto . $i +1 . ") " . $name . " " . $location . " Type: " . $type . " Status: " . $geostatus . " Difficulty " .$difficulty . "\n" . $region . "\nHidden: " . $hidden . " Last Update: " . $lastupdate . " Last Found: " . $lastfound . "\nDistance: $distance Bearing: $bearing degrees $direction\n\n";

to

$mailto = $mailto . ($i +1) . ") " . $name . " " . $location . " Type: " . $type . " Status: " . $geostatus . " Difficulty " .$difficulty . "\n" . $region . "\nHidden: " . $hidden . " Last Update: " . $lastupdate . " Last Found: " . $lastfound . "\nDistance: $distance Bearing: $bearing degrees $direction\n\n";

I suspect you're just getting the order of operations wrong.


It has to do with operator precedence. Here's a simplified example:

$i=1;// doesn't matter what this value is
$s = " alpha " . $i+1 .  " beta " . " gamma<br>\n";
echo $s; // 1 beta gamma

$s = " alpha " . ($i+1) .  " beta " . " gamma<br>\n";
echo $s; // alpha 2 beta gamma

The odd behavior in the first case even happens if you cat the addition to an (int).

$s = " alpha " . (int)$i+1 .  " beta " . " gamma<br>\n";
0

精彩评论

暂无评论...
验证码 换一张
取 消