PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Benchmarking » Benchmark » Bug #8748

class destructor behavior

Details

Submitted2006-09-20 22:02 UTC
Fromtkirby at vabest dot com
Assignedanant
StatusClosed
PackageBenchmark
PHP Version4.3.11
OSlinux 2.6.8-022stab067.1-enterpr
Roadmaps(Not assigned)

Comments

[2006-09-20 22:02 UTC] tkirby at vabest dot com

Description:
------------
php class destructors behave differently in php 4.3.11 and php 5.1.6 (probably others, too). In 4.3.11, destructor is called AFTER class storage has been released. In 5.1.6 destructor is called BEFORE class storage has been released.
Problem shows up when using Benchmark in auto mode. initialize class, add markers, execution ends, then table is automatically displayed showing markers. But, no markers are displayed in 4.3.11 because marker storage was whacked before the destructor was called.

Fix: in Timer.php file, comment out destructor code, and add duplicate function Close, call Close when you want output (yes, auto does not work).

/**
* Destructor.
*
* @access private
*/
function _Benchmark_Timer() {
/*if ($this->auto) {
$this->stop();
$this->display();
}*/
}

function Close() {
if ($this->auto) {
$this->stop();
$this->display();
}
}

Might also be present in other two files associated with Benchmark... don't have time to check yet.

Test script:
---------------
<?php
require_once("Benchmark/Timer.php");

print phpversion()."<br>";

function wait($amount) {
for ($i=0; $i < $amount; $i++) {
for ($i=0; $i < 100000; $i++) $x = sin($i / 1.2340);
}
}

$timer = new Benchmark_Timer(TRUE);
$timer->setMarker("Marker1");
wait(10);
$timer->setMarker("Marker2");
wait(100);
$timer->setMarker("Marker3");
wait(1000);

//$timer->Close();
?>

Expected result:
----------------
output should be Start, three markers, and Stop

Actual result:
--------------
4.3.11 - output is Start and Stop markers only
5.1.6 - output includes three markers, too.