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('Score should be between 0 and 100'); } } public function analyzeScore(): Array { return $results = [ 'Status' => $this->determineStatus(), 'Grade' => $this->calculateGrade(), 'Number' => $this->number, 'Type' => $this->findType(), ]; } 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(77, 4); $results =$scoreAnalyzer->analyzeScore(); printf("Status: %s \nGrade: %d \nNumber: %d \nType: %s", $results['Status'], $results['Grade'], $results['Number'], $result['Type']); } catch (Throwable $e) { echo $e->getMessage(); }
Output for 8.3.0 - 8.3.33, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
Warning: Undefined variable $result in /in/pYfXo on line 52 Warning: Trying to access array offset on null in /in/pYfXo on line 52 Status: pass Grade: 0 Number: 4 Type:
Output for 8.2.31 - 8.2.33
Warning: Undefined variable $result in /in/pYfXo on line 52 Warning: Trying to access array offset on value of type null in /in/pYfXo on line 52 Status: pass Grade: 0 Number: 4 Type:

preferences:
58.79 ms | 780 KiB | 4 Q