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 getFriendsOf($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->getFriendsOf('Alan') . "\n"; // Get company echo "\n" . $person::getNewPerson()::$company . "\n";
based on 6YhkA
Output for 7.0.0 - 7.2.0
John is my best friend! Alan is old friend! TechBase VietNam
Output for 5.5.0 - 5.6.28
Parse error: syntax error, unexpected '(' in /in/CnaXt on line 16
Process exited with code 255.