3v4l.org

run code in 300+ PHP versions simultaneously
<?php Class Driver { private $cars; public function __construct() { $this->cars = new \stdClass(); foreach (Car::$all_cars as $car) { $this->cars->$car = NULL; } } public function setRating($car, $rating) { $this->cars->$car = $rating; } public function __get($car) { return property_exists($this->cars, $car) ? $this->cars->$car : null; } } Class Car { public static $all_cars = array(); private $name; public function __construct($name) { $this->name = $name; self::$all_cars[] = $this; } public function __toString() { return $this->name; } } $bmw = new Car('bmw'); $benz = new Car('benz'); $tom = new Driver; $tom->setRating($bmw, 95); $tom->setRating($benz, 97); echo $tom->bmw; // 95
Output for git.master, git.master_jit, rfc.property-hooks
95

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
175.11 ms | 405 KiB | 5 Q