3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Blar_DateTime extends DateTime { /** * Return Date in ISO8601 format * * @return String */ public function __toString() { return $this->format('Y-m-d H:i'); } /** * Return difference between $this and $now * * @param Datetime|String $now * @return DateInterval */ public function diff($now = 'NOW') { if(!($now instanceOf DateTime)) { $now = new DateTime($now); } return parent::diff($now); } /** * Return Age in Years * * @param Datetime|String $now * @return Integer */ public function getAge($now = 'NOW') { return $this->diff($now)->format('%y'); } } $birthday = new Blar_DateTime('1879-03-14'); // Example 1 echo $birthday; // Result: 1879-03-14 00:00 // Example 2 echo '<p>Albert Einstein would now be ', $birthday->getAge(), ' years old.</p>'; // Result: <p>Albert Einstein would now be 130 years old.</p> // Example 3 echo '<p>Albert Einstein would now be ', $birthday->diff()->format('%y Years, %m Months, %d Days'), ' old.</p>'; // Result: <p>Albert Einstein would now be 130 Years, 10 Months, 10 Days old.</p> // Example 4 echo '<p>Albert Einstein was on 2010-10-10 ', $birthday->getAge('2010-10-10'), ' years old.</p>'; // Result: <p>Albert Einstein was on 2010-10-10 131 years old.</p>
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Declaration of Blar_DateTime::diff($now = 'NOW') must be compatible with DateTime::diff(DateTimeInterface $targetObject, bool $absolute = false): DateInterval in /in/WXoa8 on line 20
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.82 ms | 401 KiB | 8 Q