3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Poll { private array $points; private RatingCost $cost; private array $votes = []; private array $votedUsers = []; public function __construct(array $points, RatingCost $cost, array $votes = [], array $votedUsers = []) { $this->points = $points; $this->cost = $cost; $this->votes = $votes; $this->votedUsers = $votedUsers; } public function vote(Vote $vote) { $this->votes[] = $vote; $votedUser = $vote->getUser(); $this->votedUsers[] = $votedUser; $votedUser->increaseRating($this->cost); } } class Vote { private User $user; private PollingPoint $point; public function __construct(User $user, PollingPoint $point) { $this->user = $user; $this->point = $point; } public function getUser() : User { return $this->user; } } class PollingPoint { private string $id; private string $value; public function __construct(string $id, string $value) { $this->id = $id; $this->value = $value; } } class User { private string $id; private Rating $rating; public function __construct(string $id, Rating $rating) { $this->id = $id; $this->rating = $rating; } public function increaseRating(RatingCost $cost) { $this->rating->increase($cost); } } class Rating { private int $value; public function __construct(int $value) { $this->value = $value; } public function increase(RatingCost $cost) { $this->value += $cost->getValue(); } } class RatingCost { private $value; public function __construct(int $value) { $this->value = $value; } public function getValue() : int { return $this->value; } } class VotePoll { public function __invoke(string $pollId, string $userId, string $pointId) { //$poll = $em->getPoll($pollId); $cost = new RatingCost(30); $firstPoint = new PollingPoint('firstPoint', 'Подписыюсь'); $secondPoint = new PollingPoint('secondPoint', 'За русь ем закусь'); $poll = new Poll([$firstPoint, $secondPoint], $cost); //$user = $em->getUser($userId); $rating = new Rating(1488); $user = new User('firstUser', $rating); $vote = new Vote($user, $firstPoint); $poll->vote($vote); //$em->flush(); return $user; } } print_r((new VotePoll)('pollId', 'userId', 'pointId'));
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
User Object ( [id:User:private] => firstUser [rating:User:private] => Rating Object ( [value:Rating:private] => 1518 ) )
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'array' (T_ARRAY), expecting function (T_FUNCTION) or const (T_CONST) in /in/AREPJ on line 4
Process exited with code 255.

preferences:
128.8 ms | 407 KiB | 5 Q