3v4l.org

run code in 500+ PHP versions simultaneously
<?php class HelloWorld { public function sayHello(): string { return 'Hello, World!'; } } $date = new HelloWorld(); $a = match (true) { $date instanceof HelloWorld => 1, default => false }; var_dump($a); function applyDiscount(int $tier, float $price): float { switch ($tier) { case 1: $price = $price * 0.9; break; case 2: $price = $price * 0.8; break; } return $price; } var_dump(applyDiscount('9', 100.0)); function statusLabel($code): string { return match ($code) { 1 => 'active', 2 => 'disabled', default => 'unknown', }; } var_dump(statusLabel('1'));
Output for 8.2.31 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
int(1) float(100) string(7) "unknown"

preferences:
25.68 ms | 1136 KiB | 7 Q