3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Person { public static $company = 'TechBase VietNam'; public function getFriends() { return [ 'John' => function () { return 'John is my best friend!'; }, 'Alan' => function () { return 'Alan is old friend!'; } ]; } public function getFriendOf($someone) { return $this->getFriends()[$someone]; } public static function getNewPerson() { return new Person(); } } // Create instance $person = new Person(); // Get friend echo "\n" . $person->getFriends()['John'] . "\n"; echo "\n" . $person->getFriends('Alan') . "\n"; // Get company echo "\n" . $person::getNewPerson()::$company . "\n";
based on Vab03
Output for 7.1.0 - 7.2.0
Recoverable fatal error: Object of class Closure could not be converted to string in /in/GDGGU on line 27
Process exited with code 255.
Output for 7.0.0 - 7.0.20
Catchable fatal error: Object of class Closure could not be converted to string in /in/GDGGU on line 27
Process exited with code 255.
Output for 5.4.10 - 5.6.28
Parse error: syntax error, unexpected '::' (T_PAAMAYIM_NEKUDOTAYIM), expecting ',' or ';' in /in/GDGGU on line 31
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/GDGGU on line 5
Process exited with code 255.