What are the best practices for creating and using a timer class in PHP?

When creating a timer class in PHP, it is important to ensure that the class is flexible, reusable, and easily configurable. This can be achieved by using object-oriented programming principles and creating methods for starting, stopping, and resetting the timer. Additionally, it is recommended to use PHP's built-in time functions to accurately measure time intervals.

class Timer {
    private $start_time;

    public function start() {
        $this->start_time = microtime(true);
    }

    public function stop() {
        return microtime(true) - $this->start_time;
    }

    public function reset() {
        $this->start_time = null;
    }
}

// Example usage
$timer = new Timer();
$timer->start();
// Code to measure time
$elapsed_time = $timer->stop();
echo "Elapsed time: " . $elapsed_time . " seconds";
$timer->reset();