3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Employee { protected $salary; public function __construct($salary) { $this->salary = $salary; } public function getSalary() { return $this->salary; } } class Manager extends Employee { protected $bonus; public function __construct($salary, $bonus) { parent::__construct($salary); $this->bonus = $bonus; } public function getSalary() { return $this->salary + $this->bonus; } } function printEmployeeSalary(Employee $employee) { echo "Salary: " . $employee->getSalary() . "\n"; } $employee = new Employee(3000); $manager = new Manager(5000, 2000); printEmployeeSalary($employee); // Ожидается: Salary: 3000 printEmployeeSalary($manager); // Ожидается: Salary: 7000
Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
Salary: 3000 Salary: 7000

preferences:
38.74 ms | 406 KiB | 5 Q