News for hackers. Stuff that matters.
Re:PHP in 2020 by guggle on Wednesday January 22, 2020 @04:59AM (#22116098)
What you describe is certainly how people used to work with PHP two decades ago, however things have changed a lot:

> Want to use a relational database? You don't need to install a library

These are optional packages in most distros, so you (or your admin) effectively need to install a library.

> Want to get things out of the HTTP request? PHP has already parsed everything into the `$_REQUEST` associative-array (map/dictionary).

And yet we have PSR-7 (https://www.php-fig.org/psr/psr-7/) which define HTTP messages and most frameworks comply with it.

> Most of the time if you want a library, you can download a directory of files and then use `require` or `include` to bring it in using relative paths. No worrying about environments or installing things. Just copy a folder!

There are gazillions of libraries at packagist.org, meaning these are installable via composer. Many of these expect composer to resolve dependencies. Major frameworks can't practically be installed without composer.

> PHP let me get something for $5/mo and just stick files on a server that someone else admin'd that would just work.

There are cheap cloud solutions for most languages...

> PHP also offers a dead-simple deployment. You put your files on a server with PHP installed and you're done.

... with push-to-deploy.

> Heck, PHP even simplifies templating because PHP is literally its own templating language.

And yet we had alternate templating engines for PHP since forever (remember Smarty ? know Twig now ?). Stuffing templates with "htmlspecialchars" or "htmlentities" is no fun.

> if you're looking to take a student with one CS course under their belt and give them some instant joy, PHP really hits the mark.

As stated, Javascript is better at this.

I could go on, but my point is that you're describing qualities that were competitive advantages in the past (somewhere between 1 and 2 decades ago), but are no more.

Re:PHP in 2020 by pjmlp on Wednesday January 22, 2020 @05:29AM (#22116237)
> And yet we had alternate templating engines for PHP since forever (remember Smarty ? know Twig now ?). Stuffing templates with "htmlspecialchars" or "htmlentities" is no fun.

One of the best decisions after I decided to stick with PHP for my web site was ditching all those alternatives and go with PHP alone, using functions as tag libraries.

Re:PHP in 2020 by guggle on Wednesday January 22, 2020 @06:30AM (#22116584)
> using functions as tag libraries.

Care to post an example ?

Re:PHP in 2020 by pjmlp on Wednesday January 22, 2020 @06:59AM (#22116764)
Basically you split the PHP code into three layers, trying to do a kind of bare bones MVC.

You have the PHP business logic code as usual.

Then instead of doing

    <a href="http://somewhere">A link</a>

You have a view function that does that for you

    function web_link($url, $title) {
        echo "<a href="$url">$title</a>";
    }
And then on the HTML markup, you place those calls as tag libraries in other similar frameworks,

    web_link("http://somewhere", "A link")  
Very low tech, but does the job similar to JSP tag libraries and provides some organization.
Re:PHP in 2020 by krapp on Wednesday January 22, 2020 @07:39AM (#22116993)
It seems too low tech to be useful for any project of any complexity. Existing HTML template frameworks do a lot of things like character and syntax aware data escaping (and avoiding double-escaping), template caching, plugins, code generation, tag extension, filters, etc.

Other than being slightly more concise and appearing more functional, I don't see the benefit of this over something like Twig or Smarty. At some point you're going to wind up re implementing features that already exist in a framework anyway.

Re:PHP in 2020 by pjmlp on Wednesday January 22, 2020 @09:23AM (#22117744)
Naturally if one is doing it at scale, this is NIH.

I used it only for my web site, and many alternatives did not exist back when I did this.

Re:PHP in 2020 by stef25 on Wednesday January 22, 2020 @07:20AM (#22116876)
Re:PHP in 2020 by pjmlp on Wednesday January 22, 2020 @07:37AM (#22116974)
Yes that is the idea, it just did not exist in 2003.
Re:PHP in 2020 by guggle on Wednesday January 22, 2020 @07:06AM (#22116798)
Low-tech is fine, however I'll assume your example has been excessively simplified for the sake of brievity because as-is it's prone to break your page.
Re:PHP in 2020 by pjmlp on Wednesday January 22, 2020 @07:37AM (#22116978)
Yes, I was making it basic, just describe the idea behind it.
Re:PHP in 2020 by stef25 on Wednesday January 22, 2020 @07:17AM (#22116858)
Maybe PHP is a shitty language if you're coming from a CS background but Javascript is absolutely not better at "looking to take a student with one CS course under their belt and give them some instant joy". It's FAR more complex than PHP
Re:PHP in 2020 by guggle on Wednesday January 22, 2020 @07:23AM (#22116890)
I won't argue about the complexity and I'm not a fan of JS either... but surely you can agree that firing a browser console and do live dom manipulations can bring instant joy ?
Re:PHP in 2020 by stef25 on Wednesday January 22, 2020 @08:39AM (#22117400)
Yeah, I even demonstrated this hacking tool to a friend to show I could (temporarily) change the content of any website