3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class DomainEvent { private static $events = []; /** * @var \DateTime */ private $occurredOn; private function __construct() { static::addEvent($this); $this->occurredOn = new \DateTime(); } public static function trigger(...$args) { $event = new static(); $event->instantiate(...$args); return $event; } abstract protected function instantiate(...$args); private static function addEvent($event) { self::$events[] = $event; } public static function getEvents() { return self::$events; } /** * @return DateTime */ public function getOccurredOn() { return $this->occurredOn; } } class UserRegisteredEvent extends DomainEvent { private $data; protected function instantiate(...$args) { $this->data = $args; } } class User { /** * @var string */ private $username; /** * User constructor. * * @param string $username */ public function __construct($username) { $this->username = $username; UserRegisteredEvent::trigger($this); } /** * @return string */ public function getUsername() { return $this->username; } } $user = new User('Jimmy K. Oak'); $events = DomainEvent::getEvents();
Output for git.master, git.master_jit, rfc.property-hooks

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:
31.33 ms | 401 KiB | 8 Q