5 ms·
When's the last time PHP has been used in this way? Don't people use frameworks these days such as symfony, silex and laravel etc? And then point the web server
by jayflux 9y ago
When's the last time PHP has been used in this way?
Don't people use frameworks these days such as symfony, silex and laravel etc? And then point the web server to the entry point like with any other language?
- developer2 9y agoEven if you're not using a full-fledged framework, a router is a must these days. Anyone dropping a dozen or more .php files in the webroot that all include the same dependencies or header/footer is not following modern practices. And by "modern", I don't mean the newest fad from the past 1-5 years. We're talking about a standard way of doing things that is 10-15 years old. WordPress is a perfect example of extremely poor code. Worth vomiting every time you think about it. No seasoned developer would put together a project the way they still have it. It has nothing to do with "backwards compatibility", or "easy to host with free/cheap hosts". It's not just "not modern", it's actually straight-up unacceptable. WordPress looks like it's put together by a group of php3 juniors writing their first script, having never held a professional job. That's not so much an opinion, as it is a factual assessment that any honest professional developer would give.
- erikpukinskis 9y agoI believe WordPress and Drupal still work this way by default? I'm not a PHP dev anymore.
- krapp 9y ago>Don't people use frameworks these days such as symfony, silex and laravel etc People should, Composer (with PSR autoloading) and nikic's FastRoute get you most of the way to a really nice, lightweight meta-framework barring anything else, for practically nothing. There really is no excuse for the "URL points to a file" model to be a thing anymore. But a lot of legacy PHP code doesn't do that, and likely a lot of newbie code doesn't, because they follow old tutorials, and that model is faster and simpler. Not even Wordpress uses routing AFAIK.
- mysterydip 9y agoHonest/naive question: why not? Plenty of mvp or weekend projects can get by easily with url=page. If it's faster and simpler, what's wrong with doing it? Surely there's room for both on the intetnet.
- omnimus 9y agoIve read somewhere interview with original author of PHP and he was very strongly against routers and one point of entry index.php . Saying that they are doing webservers job again. Router makes php slower. I think while it is easier to use files as routing first time you use php.. once you start learn how to program, simple router is much much easier to reason about. Simple router is not the problem when learning php. Problem is clunky language with lot of legacy stuff and that people start with something like laravel that has so much stuff in it that you have to learn 20 concepts at once.
- krapp 9y agoHaving a router allows you to not have all of your files be web accessible, by using a single point of entry and a whitelist for all possible paths. Most projects which map PHP files to URLs have everything in the web root. If it's just a small brochure site with a few pages then it's no problem, but forums and larger projects built like this can leak information and expose vulnerabilities when PHP files which weren't meant to be directly accessed are, such as pages that perform SQL queries expecting variables in context that don't exist when accessed directly, or old config files, text files, open directories, etc. But "url=page" is still basically routing using the query string, and IMHO so is access control using .htaccess. Any system where URLs are validated and where they don't directly point to files on the server counts.
- developer2 9y ago>> not have all of your files be web accessible cough wp-config.php cough
- combatentropy 9y ago> Having a router allows you to not have all of your files be web accessible Having a router may make it easier, but it's not the only way. You can just put your libraries, passwords, etc., in some directory outside the document root. /var/www/example.com/public /var/www/example.com/lib Then you use "include" to get them.