3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Age { public function __construct(readonly public int $age) { if (0 > $age) { throw new DomainException('Age must be positive integer. "' . $age . '" provided.'); } } public function min(Age $comparingAge): Age { return min($this, $comparingAge); } } $firstAge = new Age(33); $secondAge = new Age(22); $minAge = $firstAge->min($secondAge); var_dump($minAge);
Output for 8.1.12 - 8.1.33, 8.2.21 - 8.2.29, 8.3.5 - 8.3.25, 8.4.1 - 8.4.12
object(Age)#2 (1) { ["age"]=> int(22) }

preferences:
61.41 ms | 406 KiB | 5 Q