我想我在PHP v5.3.3-1ubuntu9.5 CLI中发现了一个bug


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

我可能发现了一个bug,如果是,我该向谁报告呢?

这是我得到的:

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";

输出如下所示:

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

只显示列表中的最后一项。但是如果我稍微改变一下代码:

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";
我得到了我期望看到的完整输出:
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 Cache 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

我是否发现了一个错误,或者我在第一种方式中做错了什么,并在第二种方式中纠正?

如果我发现了一个bug,我该向谁报告呢?

PHP v5.3.3在Ubuntu 10.10上运行CLI版本

在代码的第一个比特中,更改:

$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";

$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=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

第一种情况下的奇怪行为即使在对(int)进行加法运算时也会发生。

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