3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Template { private $dir = 'app/views/'; public function render($template, $data = [], $renderNow = true){ ob_start(); extract($data, EXTR_SKIP); require $this->dir.$template.'.html'; $ret = ob_get_clean(); if($renderNow){ echo $ret; } return $ret; } } //in controllers/someController.php class SomeController { public function list(){ $template = new Template(); $template->render('list'); } public function show($id){ $template = new Template(); $template->render('some',['id' => $id]); } } //in frontController //somehow you know you need 'someController' and action - 'show': $someController = new SomeController(); $someController->list(); ?>
based on uoJPf
Output for 7.0.0 - 7.1.7
Warning: require(app/views/list.html): failed to open stream: No such file or directory in /in/TvScq on line 9 Fatal error: require(): Failed opening required 'app/views/list.html' (include_path='.:') in /in/TvScq on line 9
Process exited with code 255.
Output for hhvm-3.15.4
Fatal error: Uncaught Error: require(app/views/list.html): File not found in /in/TvScq:9 Stack trace: #0 /in/TvScq(25): Template->render() #1 /in/TvScq(39): SomeController->list() #2 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected 'list' (T_LIST), expecting identifier (T_STRING) in /in/TvScq on line 23
Process exited with code 255.