Hacker News new | ask | show | jobs
by edsrzf 1158 days ago
The world that PHP grew up in has changed. The language and community have matured, and in the process PHP has lost most of its competitive advantage: low barrier to entry.

It used to be:

  * Moving from static HTML to dynamic server code was a matter of changing file extension and adding PHP tags.
  * Many shared hosting services supported PHP.
  * Deploying was a matter of copying files to the server.
Projects that started from HTML + PHP tags grew and became unmaintainable messes. The PHP community learned from this and evolved in a different direction. You can still _write_ PHP code in the old way, but it's strongly discouraged and (rightfully) seen as a bad practice. You don't even use PHP as a templating language anymore. Symfony and Laravel have their own templating languages that dynamically compile to PHP.

Modern PHP code looks very much like Java or C# -- classes, OO design patterns, and so on. Except in most ways, it's worse than Java or C#. Why would anyone start a new project in PHP?

Deploy models have also changed. You're usually not copying files to servers, but deploying Docker images or other formats. PHP has no particular advantage in this new world.

If PHP wants to turn things around, it needs to figure out what makes it unique or better than other languages. Right now, there's really nothing.

5 comments

Every time someone says there’s really nothing that stands about php I roll my eyes. Php usually competes with JavaScript and python, all three being dynamic languages.

First of all, php is faster than python, and ruby and probably most dynamic languages except JavaScript.

So in terms of performance, modern php is ahead of the other languages and it scales well.

Regarding features, php has the best support for classes and types out of the three languages. So if you want to design a classic oo system, php has the best features language-wise.

Php also has a great community (good ides, good package manager, good open source libraries and frameworks).

What do other languages offer that php doesn’t have?

To be honest apacha/nginx + php with laravel is probably few of the most stable web serves I've build. IMO it's still a lot lighter and easier then Java or C#. But yeah the old script kiddie days were great. And I do thing we should encourage users more to be more wild for small projects and just build something without a framework.
I am a ruby dev but I build all my side apps in PHP even though I don't know it well.

It's hassle free to host on a shared host and it'll be there forever

I actually want a more refined version, with better ( or different ) syntax of old PHP.

And I really like you touch on low barrier to entry. Right now, in my likely controversial opinion, modern Web Dev is a huge pile of excess complexity.

The web has always been inherently complex, so it is only logical that frameworks for building things on the web have evolved to tackle all the possible complexity. Of course also the introduction of handheld devices and duplex multimedia features has made the web more complex, but mostly we just didn’t care 20 years ago, because we could get away with less. Now, more and more things are exposed to us every day, requiring us to grok it all to be able to make day-to-day decisions.

No wonder so many people turn to magical thinking, cargo cult coding or Uncle Bob -like messiahs.

I think one potential improvement for PHP is to make PHP templating usable again. This is something that could have a low cost of implementation but a big win.

Example on improvements

1) auto-escape output - one of the biggest reason not to use PHP for templating is that you need to manually escape your strings to avoid XSS, whereas a dedicated templating library can do this for you. This could be done with a either a special opening and closing tag or let you register a tag hook.

2) today you can use the alternative syntax for if, while, for, foreach, and switch

https://www.php.net/manual/en/control-structures.alternative...

This could be expanded for match expression, closures, and other block expressions.

3) custom HTML tag support, register a HTML tag like <my-form> and implement it thru an API, perhaps a class that implements an interface. And now you can do much better reusable components that can automatically close them selves instead of multiple calls.

e.g instead of

  <?php open_form() ?>
  <button type="submit">Buy</button>
  <?php close_form() ?>
you can do

  <my-form>
    <button type="submit">Buy</button>
  </my-form>
In the first example you need to always match one function call with another function call ( manual work), in the latter example you HTML just needs to be valid, which many editors can detect for you.

And it would be easy to share these custom components on github with composer.

They’re solving problems for people who are stuck using PHP, not trying to find a market niche.
That can work for a while but it doesn’t attract new developers, and it tends to have legacy projects be replaced outright with new ones in better languages.
If anyone needs a quick scripting language, there’s JavaScript or Python.

There’s no niche that PHP needs to fill except for “a language for people who don’t want to move off of PHP.”

That’s roughly what I was thinking, yes. There’s still a certain appeal to the easy install process but the gap is a lot lower now, the classic PHP way famously lead to security issues, and there’s a vicious flip where once you need to customize anything it goes from easier to harder than the average containerized Node/Python deployment since you need to learn how to run things like FPM rather than just installing a web server package. That also shows up with Composer - the standard library is big but once you need something else, the experience is worse than NPM or PyPI.

The fatal flaw in my opinion was not taking the language itself more seriously 20 years ago. The culture of laxness around things like type coercion, ignoring errors by default, being inconsistent about positional arguments and typing or nomenclature, etc. is so deeply ingrained that major improvement are much harder and will likely require advanced automated tooling. I left the community in the mid-2000s after getting burned out by the endless stream of security and correctness bugs caused by the language and culture – my favorite was the time a detailed bug report for functionality not matching the documentation was WONTFIXed since it was working as the core developers intended & they didn’t feel like updating the docs – but having had the misfortune of being involved with a PHP project again, the only big improvement I can think of was that register_globals isn’t the default. You still routinely see bugs caused by e.g. inconsistent array function parameter ordering causing errors which are silently suppressed despite our configuration having logging enabled for that class of error and the built-in linter won’t report. There was no reason to waste time on that in 2003, much less 2023.

PHP is great actually. Im not a php dev but the eco system is amazing and development is fast.