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.4.120.0070.00524.19
8.4.110.0110.00822.55
8.4.100.0140.00819.01
8.4.90.0110.01017.65
8.4.80.0060.00317.75
8.4.70.0090.01118.11
8.4.60.0140.00718.79
8.4.50.0040.00419.01
8.4.40.0100.01018.74
8.4.30.0080.00018.81
8.4.20.0040.00417.68
8.4.10.0060.00319.30
8.3.250.0070.01119.08
8.3.240.0110.00817.52
8.3.230.0100.01016.52
8.3.220.0120.00616.56
8.3.210.0070.00116.75
8.3.200.0110.00916.48
8.3.190.0100.00719.21
8.3.180.0120.00616.64
8.3.170.0110.00618.83
8.3.160.0070.01018.59
8.3.150.0030.00619.00
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.290.0100.00820.36
8.2.280.0090.00920.32
8.2.270.0070.01317.21
8.2.260.0060.00918.57
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.330.0100.00821.60
8.1.320.0110.00816.30
8.1.310.0060.00818.19
8.1.300.0070.00318.43

preferences:
26.69 ms | 403 KiB | 5 Q