3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); class ScoreAnalyzer { /** * @throws InvalidArgumentException */ public function __construct(private readonly int $score, private readonly int $number){ if($score < 0 || $score > 100){ throw new InvalidArgumentException('Invalid score input'); } } public function analyzeScore(): void { echo "Score: $this->score \n"; $status = $this->determineStatus(); echo "Status: $status \n"; $grade = $this->calculateGrade(); echo "Grade: $grade\n"; echo "Number: $this->number\n"; $type = $this->findType(); echo "Type: $type\n"; } private function determineStatus(): string { return $this->score >= 60 ? "pass" : "fail"; } private function calculateGrade(): string { return match (true) { $this->score < 60 => 'F', $this->score < 70 => 'D', $this->score < 80 => 'C', $this->score < 90 => 'B', default => 'A', }; } private function findType(): string { return $this->number % 2 === 0 ? "even" : "odd"; } } try{ $scoreAnalyzer = new ScoreAnalyzer(t, 4); $scoreAnalyzer->analyzeScore(); } catch (InvalidArgumentException $e){ echo $e->getMessage(); }
Output for 8.2.31 - 8.2.33, 8.3.0 - 8.3.33, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
Fatal error: Uncaught Error: Undefined constant "t" in /in/sATVF:55 Stack trace: #0 {main} thrown in /in/sATVF on line 55
Process exited with code 255.

preferences:
62.7 ms | 781 KiB | 4 Q