-
Couldn't load subscription status.
- Fork 8k
Description
🧩 Proposal: Built-in Front Controller / Auto-Routing Mode for PHP
Title: Native front-controller routing without frameworks or config files
🎯 Goal
Enable developers to use clean URLs and centralized routing behavior like /hello/{name} or /api/posts without frameworks, .htaccess, or server config.
Everything should work automatically through a single index.php entry point.
💡 Concept
Add a built-in feature or ini flag such as:
auto_route = On
When enabled, PHP would:
- Accept all requests (even if the
.phpextension isn’t present). - Try to serve static files if they exist.
- If no static file is found:
- Try
<path>.php - Try
<path>/index.php - Otherwise, forward to
/index.php
- Try
- Populate a special variable like
$_SERVER['PATH_INFO']or$ROUTE_PATHto reflect the clean URL.
This would make it possible to handle all routes from a single index.php file:
<?php
$router = new Php\Router();
$router->get('/hello/{name}', function($params) {
echo "Well, Ello There {$params['name']}";
});
$router->get('/test/add-random/skills', function() {
$db = class_exists('AppGlobals') && AppGlobals::isLocal()
? new DBLocal()
: new DBProd();
$users = new ModelUsers($db, Logger::instance());
$result = $users->addSkillsToMockUsers();
echo json_encode($result);
});
$router->run();🧠 Rationale
This would make PHP immediately useful for:
- Rapid prototypes and microservices.
- Shared hosting where
.htaccessis restricted. - Developers who want framework-like routing without dependencies.
It matches the “batteries included” philosophy of modern scripting environments (Node’s Express, Python’s Flask, etc.) while keeping PHP simple and fast.
⚙️ Implementation Notes
- SAPI target: Built-in CLI server first (
php -S ...). Later expansion to Apache SAPI (optional). - Security: Static files should still be prioritized to prevent accidental exposure.
- Performance: Only a few
is_file()checks added whenauto_routeis enabled. - Backward compatibility: Off by default; purely opt-in.
🗣️ Summary
PHP should have a native, optional front controller mode that allows
/route→/route.phpor/index.phprouting automatically, with no external config.
This would make PHP dramatically more accessible to beginners and microservice developers, eliminating the “.php suffix” problem and creating a simpler out-of-the-box experience similar to Slim or Express, but without frameworks.