<?php //function fact($x) //{ // return $x == 0 ? 1 : $x * fac($x - 1); //} // //echo fact(0); //localhost:8000/index.php?action=show&id=1 //localhost:8000/index.php?action=about //localhost:8000/show/1 //localhost:8000/about //include 'actions.php'; // скрипт завершается. работает быстро //include_once 'actions.php'; //require 'actions.php'; // скрипт прерывается?? работает медленно require_once 'actions.php'; function runAction($name = null, ...$args) { $name = $name ?: 'index'; $action = $name . 'Action'; if (!function_exists($action)) { header('HTTP/1.1 404 Not found'); exit('Satan welcomes'); } $action(...$args); } $action = isset($_GET['action']) ? $_GET['action'] : null; ini_set('display_errors', 1); runAction($action, $_GET); // < 5.6 ... // call_user_func_array('', []);
<?php ini_set('display_errors', 1); // localhost:8080/index.php?action=show&id=1 // localhost:8080/index.php?action=about // localhost:8080/show/1 // localhost:8080/about #include 'actions.php'; #include_once 'actions.php'; #require 'actions.php'; require_once 'actions.php'; function runAction($name = null) { $name = $name ?: 'index'; $action = $name . 'Action'; $args = array_slice(func_get_args(), 1); if (!function_exists($action)) { header('HTTP/1.1 404 Not Found'); exit('404 Not found'); } // $action(...$args); call_user_func_array($action, $args); } $action = isset($_GET['action']) ? $_GET['action'] : null; runAction($action); runAction('show', 56); # < 5.6 ... // call_user_func_array('', []);
<?php //Load the base controller require_once 'core/BaseController.php'; //Load extra functions to front require_once 'core/controller.extra.php'; //Load the controllers if (isset($_GET["controller"])) { $controllerObj = loadController($_GET["controller"]); runAction($controllerObj); } else { $controllerObj = loadController('Home'); runAction($controllerObj); }
/** * Created by PhpStorm. * User: Lyubov * Date: 15.01.2016 * Time: 20:39 */ include 'actions.php'; //- выдает ошибку, но код выполняет: выводит число 885 #include_once 'actions.php2'; #require 'actions.php2'; //- выдает фатальную ошибку и ничего не выполняет #require_once 'actions.php2'; //echo '8885'; function runAction($name = null, ...$args) { $name = $name ?: 'index'; //= $name = $name ? $name: 'index'; $action = $name . 'Action'; if (!function_exists($action)) { //404 header('HTTP/1.1 404 Not Found'); exit('404 Not Found'); } $action(...$args); } //ini_set('display_errors', 1); $action = isset($_GET['action']) ? $_GET['action'] : null; runAction($action); //runAction('show', 1); //runAction('about'); //runAction('test', 'Hi', 'users', ['user1', 'user2']);