3v4l.org

run code in 300+ PHP versions simultaneously
<?php // parent class class Vehicle { // private property name private $name; // public function start public function start() { echo $this->name. " - Engine start...<br/>"; } // public function stop public function stop() { echo $this->name. " - Engine stop...<br/>"; } } // child class class Car extends Vehicle { public function drive() { // accessing name variable of Car class echo "I am " . $this->name . "<br/>"; echo "Lets go on a drive..."; } } $car = new Car(); $car->name = "Mercedes benz"; var_dump($car);
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.30, 8.0.0 - 8.0.22, 8.1.0 - 8.1.9
object(Car)#1 (2) { ["name":"Vehicle":private]=> NULL ["name"]=> string(13) "Mercedes benz" }

preferences:
65.78 ms | 409 KiB | 5 Q