What is PHP like nowadays? I know it has a bad reputation and a history of kitchen sink design but have they managed to tame it into something more sensible? Do the docs help steer developers away from legacy issues and common bad patterns? Would anyone recommend it for new projects?
But I don't follow the elite crowd's advice. I don't write classes. I don't use frameworks or routing functions, like get('/' function () { ... }). In fact I try to write as little PHP as possible. I think of it as a glue language between the browser and the database.
I spent a lot of time learning SQL inside and out, and I use one of the best databases in the world, Postgres. I try to do as much processing in the database as I can. So PHP's job is mainly to select, insert, update, or delete on a view, or to call a database function. The data that PHP gets from the database is often ready for display. So PHP just needs to wrap it in a template.
$data = $db->query('select * from some_view where id = ?', [ $id ])->fetchAll();
render('path/to/template.hbs', $data);
That's a super-simple example that won't even run, some cross between PHP and pseudocode, but it gives you a hint.I just haven't let go of the newb's approach that URLs map to files.
https://www.example.com/widgets/detail/1234
would map to /path/to/docroot/widgets/detail.php. With Apache, I don't even have to use mod_rewrite to get rid of the .php suffix and to allow /1234 as PATH_INFO. I just turn on MultiViews. Options +MultiViews