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 [ 'Score' => $this->score, '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"; } } readonly class ScoreAnalysisResult { public construct__(private int $score, private int $status, private int $grade, private int $numver, private int $type){} } try{ $scoreAnalyzer = new ScoreAnalyzer(77, 4); $results =$scoreAnalyzer->analyzeScore(); printf("Score: %d \nStatus: %s \nGrade: %s \nNumber: %d \nType: %s", $results['Score'], $results['Status'], $results['Grade'], $results['Number'], $results['Type']); } catch (Throwable $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
Parse error: syntax error, unexpected token "(", expecting variable in /in/d757T on line 52
Process exited with code 255.

preferences:
59.11 ms | 779 KiB | 3 Q