3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo{ public $age = ''; public $name = ''; public $barObj = ''; public function setAge($age){ $this->age = $age; } public function setName($name){ $this->name = $name; } public function getUsersPropertyInfo(Bar $objBar){ if($objBar instanceof Bar1) { $objBar->getCarInfo(); } return $objBar; } } class Bar{ public $carName = ''; public $drivingSpeed = ''; public function __construct() { $this->setCarName('Mercedes'); $this->setdrivingSpeed(300); } public function setCarName($carName){ $this->carName = $carName; } public function setdrivingSpeed($drivingSpeed){ $this->drivingSpeed = $drivingSpeed; } public function getCarInfo(){ return $this->carName.'>>'.$this->drivingSpeed; } } $objFoo = new Foo(); $objFoo->setAge(22); $objFoo->setName('babalu'); $barObj = new Bar(); $usersPropertyInfo = $objFoo->getUsersPropertyInfo($barObj); print_r($usersPropertyInfo->carName);
Output for 5.6.38, 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Mercedes

preferences:
97.41 ms | 1482 KiB | 4 Q