3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Timer { private $_state; private $_date; public function __construct($state, \DateTime $date) { $this->_state = $state; $this->_date = clone $date; } public function getType() { return $this->_state; } public function getInterval() { return (new \DateTime('2015-01-01'))->diff(clone $this->_date); } public function isPositive() { return !(bool) $this->getInterval()->invert; } public function isNegative() { return (bool) $this->getInterval()->invert; } } $timer = new Timer('lalala', new \DateTime('2015-01-01')); var_dump( $timer->isPositive(), $timer->isNegative() );

preferences:
45.81 ms | 402 KiB | 5 Q