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(); var_dump($events);
Output for git.master
array(1) { [0]=> object(UserRegisteredEvent)#2 (2) { ["occurredOn":"DomainEvent":private]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2015-10-17 22:40:55.003691" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ["data":"UserRegisteredEvent":private]=> array(1) { [0]=> object(User)#1 (1) { ["username":"User":private]=> string(12) "Jimmy K. Oak" } } } }
Output for git.master_jit
array(1) { [0]=> object(UserRegisteredEvent)#2 (2) { ["occurredOn":"DomainEvent":private]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2015-10-17 22:40:55.003763" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ["data":"UserRegisteredEvent":private]=> array(1) { [0]=> object(User)#1 (1) { ["username":"User":private]=> string(12) "Jimmy K. Oak" } } } }
Output for rfc.property-hooks
array(1) { [0]=> object(UserRegisteredEvent)#2 (2) { ["occurredOn":"DomainEvent":private]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2015-10-17 22:40:55.004294" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } ["data":"UserRegisteredEvent":private]=> array(1) { [0]=> object(User)#1 (1) { ["username":"User":private]=> string(12) "Jimmy K. Oak" } } } }

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