3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DomainEventInterface { } trait EventRecordingTrait { /** * @var array<DomainEventInterface> */ protected array $domainEvents = []; protected function recordThat(DomainEventInterface $domainEvent): void { $this->domainEvents[] = $domainEvent; } /** * @return array<DomainEventInterface> */ public function releaseEvents(): array { $domainEvents = $this->domainEvents; $this->domainEvents = []; return $domainEvents; } } readonly class Created implements DomainEventInterface { public function __construct( public string $name, public string $email ) { } } readonly class NameUpdated implements DomainEventInterface { public function __construct(public string $name) { } } class User { use EventRecordingTrait; // No intention of throwing events, it's just a simple object hydration! public function __construct( private string $name, private string $email, ) { } // intent of creating an instance and recording that specific event public static function create(string $name, string $email): self { $self = new User($name, $email); $self->recordThat(new Created($name, $email)); return $self; } // Wouldn't be necessary with some kind of asymetric visibility, but it's not a big hassle public function getName(): string { return $this->name; } // Here I would update the same $name attribute but throwing a different event public function updateName(string $name): void { if ($this->name === $name) { return; } $this->recordThat(new NameUpdated($name)); $this->name = $name; } // Wouldn't be necessary with some kind of asymetric visibility, but it's not a big hassle public function getEmail(): string { return $this->email; } } $user1 = new User('Hydrated from database', 'user1@example.com'); var_dump($user1); $user1->updateName('Mutation intent'); var_dump($user1); $user2 = User::create('Created from controller', 'user2@example.com'); var_dump($user2); $user2->updateName('Another mutation intent'); var_dump($user2);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.140.0150.00020.66
8.3.130.0070.01018.50
8.3.120.0210.00718.60
8.3.110.0080.00022.58
8.3.100.0110.00820.94
8.3.90.0000.01020.94
8.3.80.0220.01230.84
8.3.50.0060.00320.94
8.2.250.0040.00418.34
8.2.240.0060.00317.08
8.2.230.0030.01320.94
8.2.220.0070.01422.58
8.2.210.0040.00422.58
8.2.110.0110.00921.85
8.1.300.0070.00318.43

preferences:
33.44 ms | 403 KiB | 5 Q