3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class UserPreferences { function __construct(Storage $storage) { $this->storage = $storage; } function getImagesPerPage() { $value = $this->storage->get('imagesPerPage'); if ($value !== null) { return $value; } return 20; //Default value } } class ImageGalleryController { public function indexAction(MyLibrary $obj, $imagesPerPage) { //do something that requires knowing imagesPerPage } } $injector->delegate('imagesPerPage', [UserPreferences::class, 'getImagesPerPage']) $injector->make(ImageGalleryController::class);
Output for 5.4.0 - 5.4.28
Parse error: syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /in/IRaqs on line 25
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected '[' in /in/IRaqs on line 25
Process exited with code 255.