3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* class Pont { } $towerBridge = new Pont; $towerBridge->__construct(12.2, 43.1); */ class Player { private int $level; private Weapon $weapon; public function __construct(int $level) { $this->level = $level; } public function getLevel(): int { return $this->level; } public function setLevel(int $level) : void { $this->level = $level; } public function getWeapon(): Weapon { return $this->weapon; } public function setWeapon(Weapon $weapon) : void { $this->weapon = $weapon; } } class Weapon { private string $name; private int $attack; public function __construct(string $name, int $attack) { $this->name = $name; $this->attack = $attack; } public function getName(): string { return $this->name; } public function setName(string $name) : void { $this->name = $name; } public function getAttack(): int { return $this->attack; } public function setAttack(int $attack) : void { $this->attack = $attack; } } $masterSword = new Weapon("Master Sword", 1000); $link = new Player(4); $link->setWeapon($masterSword); echo "Link est de niveau ".$link->getLevel()."et il possède la ".$link->getWeapon()->name;
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
Fatal error: Uncaught Error: Cannot access private property Weapon::$name in /in/6vvOu:81 Stack trace: #0 {main} thrown in /in/6vvOu on line 81
Process exited with code 255.
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/6vvOu on line 15
Process exited with code 255.

preferences:
147.07 ms | 401 KiB | 152 Q