<?php
class Car {
private $km = 0;
public function drive($distance) {
$this->$km += $distance;
}
public function getKm() {
return $this->$km;
}
}
$lexus = new Car();
$lexus->drive(5);
print $lexus->getKm();
Warning: Undefined variable $km in /in/GP3Fd on line 8
Deprecated: Creation of dynamic property Car::$ is deprecated in /in/GP3Fd on line 8
Warning: Undefined property: Car::$ in /in/GP3Fd on line 8
Warning: Undefined variable $km in /in/GP3Fd on line 12
5
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: Undefined variable $km in /in/GP3Fd on line 8
Warning: Undefined property: Car::$ in /in/GP3Fd on line 8
Warning: Undefined variable $km in /in/GP3Fd on line 12
5
Notice: Undefined variable: km in /in/GP3Fd on line 8
Notice: Undefined property: Car::$ in /in/GP3Fd on line 8
Notice: Undefined variable: km in /in/GP3Fd on line 12
5
Output for 7.3.32 - 7.3.33
5
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: km in /in/GP3Fd on line 8
Fatal error: Uncaught Error: Cannot access empty property in /in/GP3Fd:8
Stack trace:
#0 /in/GP3Fd(17): Car->drive(5)
#1 {main}
Next Error: Cannot access empty property in /in/GP3Fd:8
Stack trace:
#0 /in/GP3Fd(17): Car->drive(5)
#1 {main}
thrown in /in/GP3Fd on line 8
Process exited with code 255.
Notice: Undefined variable: km in /in/GP3Fd on line 8
Fatal error: Cannot access empty property in /in/GP3Fd on line 8
Process exited with code 255.
Output for 5.0.4
Notice: Undefined variable: km in /in/GP3Fd on line 8
Notice: Undefined variable: km in /in/GP3Fd on line 12
5
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: km in /in/GP3Fd on line 8
Notice: Undefined variable: km in /in/GP3Fd on line 12
5
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/GP3Fd on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/GP3Fd on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/GP3Fd on line 5
Process exited with code 255.