3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TimePeriod { private $Seconds; // Properties accessors are implemented just like you would define an actual property public $Hours { get() { return $this->Seconds / 3600; } // In the set accessor, the variable $x holds the incoming value to be "set" set($x) { $this->Seconds = $x * 3600; } }; } // Accessing the property is the same as accessing a class member $time = new TimePeriod(); $time->Hours = 12; // Stored as 43200 echo $time->Hours; // Outputs 12
Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.21
Parse error: syntax error, unexpected '{', expecting ',' or ';' in /in/oquto on line 7
Process exited with code 255.

preferences:
184.95 ms | 1395 KiB | 57 Q