Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.2.9

Bug #2295 Timer.php: undefined index "Stop" on line 208
Submitted: 2004-09-06 16:24 UTC
From: pmjones Assigned: sebastian
Status: Closed Package: Benchmark
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    

 [2004-09-06 16:24 UTC] pmjones
Description: ------------ The getProfiling() method does not check for the existence of a "Stop" key in Timer.php at line 208 and 210. This generates a notice under E_ALL when you call display() before stopping the timer. If you call stop() before display() then the error does not appear. Suggestion: when checking for the endpoint, and "Stop" does not exist, use the last array key as the endpoint instead. This may be an issue for user-defined beginpoints as well. Reproduce code: --------------- <?php $timer =& new Benchmark_Timer(); $timer->start(); $timer->setMarker('here we are'); $timer->display(); ?> Expected result: ---------------- Expect to have no errors when displaying the current time profile. Actual result: -------------- Notice: Undefined index: Stop in Timer.php on line 208


 [2004-09-06 18:29 UTC] pmjones
Here's a "fixed" version of the timeElapsed() method for Timer.php. function timeElapsed($start = 'Start', $end = 'Stop') { // Set the ending time; sets the ending time to the current // time when the timer has not been stopped. if ($end == 'Stop' && ! isset($this- >markers['Stop'])) { $microtime = explode(' ', microtime()); $endtime = $microtime[1] . substr($microtime[0], 1); } else { $endtime = $this->markers[$end]; } // now do the math if (extension_loaded('bcmath')) { return bcsub($endtime, $this->markers[$start], 6); } else { return $endtime - $this->markers[$start]; } }
 [2004-12-17 06:15 UTC] dufuz
Could you provide a diff -u patch instead of pasting the fixed function here ? Thanks.
 [2004-12-17 06:57 UTC] sebastian
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on In case this was a website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.