3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Wagon { private $name; public function setName($name){ $this->name = $name; } public function getName(){ return $this->name; } } class Train { public function __construct(array $wagons) { $this->wagons = (function (Wagon $wagons) { return $wagons->getName(); })($wagons); } } $vagon = new Wagon(); $vagon->setName('vagon 1'); var_dump(new Train([$vagon]));
based on RTgdo
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught TypeError: Argument 1 passed to Train::{closure}() must be an instance of Wagon, array given, called in /in/h9X1j on line 21 and defined in /in/h9X1j:19 Stack trace: #0 /in/h9X1j(21): Train->{closure}(Array) #1 /in/h9X1j(29): Train->__construct(Array) #2 {main} thrown in /in/h9X1j on line 19
Process exited with code 255.
Output for 5.4.0 - 5.6.28
Parse error: syntax error, unexpected '(' in /in/h9X1j on line 21
Process exited with code 255.