<?php
class PoweredVehicle {
protected $odometer = 0;
protected $vehicle_type;
protected $colour;
public function __construct($vehicle_type, $colour) {
$this->vehicle_type = $vehicle_type;
$this->colour = $colour;
}
}
$car = new PoweredVehicle('car', 'blue');
$go_back_in_time = function () : PoweredVehicle {
$this->vehicle_type = 'horse';
$this->colour = 'brown';
return $this;
};
$horse = $go_back_in_time->call($car);
var_dump($horse);
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 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.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- object(PoweredVehicle)#1 (3) {
["odometer":protected]=>
int(0)
["vehicle_type":protected]=>
string(5) "horse"
["colour":protected]=>
string(5) "brown"
}
- Output for 5.6.38
- Parse error: syntax error, unexpected ':', expecting '{' in /in/VIlXL on line 18
Process exited with code 255.
preferences:
165.47 ms | 407 KiB | 5 Q