3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class StringCastable { private $data; public function __construct(string $data) { $this->data = $data; } public function __toString(): string { return $this->toString(); } public function toString(): string { return $this->data; } } function testStringCast(string $data) { var_dump($data, get_class($data)); } $speculoos = new StringCastable("speculoos"); var_dump($speculoos); testStringCast($speculoos);
based on PODQY
Output for 7.0.0 - 7.2.0
object(StringCastable)#1 (1) { ["data":"StringCastable":private]=> string(9) "speculoos" } Warning: get_class() expects parameter 1 to be object, string given in /in/5926B on line 25 string(9) "speculoos" bool(false)
Output for 5.3.18 - 5.6.28
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/5926B on line 12
Process exited with code 255.