PHP in 2024
stitcher.io
stitcher.io
With PHP to move my code to a production system I just need to run `git pull` and the new codebase is instantly live. No builds, no server updates.
The Markup system of PHP is also very very handy. No more messing with handlebars or external libraries.
Realistically you can start a small site with PHP and HTMX and no external PHP package dependencies in an evening.
> designed to be practical and useful, rather than attractive.
It gets the job done. Really well.
definition of "functional" is "designed to be practical and useful, rather than attractive"
But thanks everyone, for the dictionary definition lookup.
I spend most of my time writing GO now.
Go + htmx + tmpl is all you need for a basic site. The go runtime produces binaries... While you're still installing php and a web server, my binary is already running and in systemd.
Need validation, grab validator. Need a DB, grab sqlc and write sql and then have the code for your API calls generated for you!!! (This bit of code generation feels like magic candidly)
Need a command line tool? GO.
Have to build a Key Value store? GO
Want to build a database? GO
Do you need a container deploy system ... well Kubernetes is already in GO...
There was a magic to LAMP and PHP 4... it was the right stack at the right time. When I work in go now I feel all that magic again.
It’s basically Java 1.2, sold in “Unix-flavor”, somehow making it acceptable to the people that otherwise hate to touch anything non-C (and in extension, never having used anything more modern)
I like Rust, and zig. Both end up with better performance than go. All three will output portable binary.
I like Ruby and Django. I can get a V1 site out faster than I can with go.
Java is java. Its great if its huge, but hard to do "simple" in java... and the specter of "is this the year oracle fucks every one" looms large in the java ecosystem.
The compile/test loop for GO is stupid fast. How go deals with dependency is fist class. Go nailed concurrency model has found a sweet spot between safety, ease of use and developer performance that is unmatched.
Go is the "brutalist architecture" of programing. Most people look at it and go "why" but if you embrace it, and adopt it, there is an effective sensibility that you're not really getting elsewhere.
On another note, whether or not I can make a database in Go is irrelevant. We're talking about replacing PHP, a web language. Why would I need my web language and database language to be the same?
Well over a decade old.
>> If third party libraries are important to you, it's hard to recommend Go over PHP.
There are plenty of third party libraries for go. This is where most of Go departs from PHP/java/ruby. Php/ruby you might look to something like larval or rails. Java had spring/hybernate/struts/grails (there's a lot there). Is there A framework you're going to jump on in Go? No, Go isnt Rails, it isnt omakase. Go has a ton of parts that "just work" and work well together.
You can pick an ORM (gorm) or use code generation like SQLC (magic!). There is a clean validation implementation that covers 99 percent of your use cases and is easy to extend. If you hate that there are 3 solid alternatives. Do you want a custom router, there are lots of choices but the standard library is good enough. How about logging? Works fine out of the box but plenty of choices here too. Auth, Identity and Access control what do you need there is a middle ware for it already or you can build one in 10 minutes. Are you parsing massive JSON files? hey if the standard lib is too slow there's 4 other choices depending on your use case.
Want to recycle all your code for CLI tools or service workers ... go is a hell of a lot more elegant than ruby or PHP for this (better concurrency primitives).
> On another note, whether or not I can make a database in Go is irrelevant.
I have a little project: the web server, the DB the, images, everything. One simple binary, one config file. Im not installing web servers, run times, databases. It's clean simple and out the door. Im playing with a search engine in go that looks like it could be mixed into that same binary and be 75 or 80 percent of what a solr/open search server would be.
Would rails or larval be faster to launch. Sure. Are they going to keep getting features out ahead of go after 6 months or a year. No things are gonna be really even. And when ruby or PHP hits the wall (and they have a point where scaling them stops making sense) then what do you do? Port to java... or go? You could just pick go from the start and scale it all the way out. Binary blob monolith to scaled services you can just stick with go....
As a side note, golang doesn't seem to offer anything even close to what other ecosystems offer for Auth without using a third party service. They have some pretty basic libraries from what I've seen, but I could be wrong. These are not things that you're gonna roll in 10 minutes.
When working for clients, and they need to connect to an obscure payment processing service, you could roll your own. But I don't want to be the one to tell them why we can't connect to these services without writing these things ourselves when their competitors can because they chose a language like PHP
https://awesome-go.com/authentication-and-oauth/
Theres ORY if you want your own in house auth zero...
There are piles of other things out there.
>>> They have some pretty basic libraries from what I've seen, but I could be wrong
Basic, maybe... Minimal closer. I like to think of go as brutalist architecture its so drab and functional that it feels ugly, void, and lacking.
Look at go's standard library. It's complete, but there isnt a lot of flash there. Good go packages maintain that stance. They give you enough to finish the job. Your not gonna find a package with a lot of "utility" functions in it, your not gonna find a lot of "left pad" like micro libraries.
And when you adopt this sort of thinking you dont really need as many choices. When every thing is boiled down to "this is functional/working" it doesn't leave a lot of room for implementation details or interfaces as distinguishing features.
Now it's really hard to fix. The std lib already does implicit nulls all over the place.
Kotlin kind of fixed it for Java, and it really helps us.
PHP is old, and makes it easier to forgive it's mistakes. But Go?
They relied on decades old insights of persons who worked on C and Unix. That said, I'm honestly still on the fence about if nil checking is really braindead, or just what it boils down to in the end and the rest like exceptions and Options/Result is just theatrical.
What I don't get is that they are not more pedantic about checking nil errs in the compiler. They error hard during compilation on unused variables, but err checking is simply not done.
The simple stuff is just too boring once you are an expert in the subject.
Later they started to move away from all that with PSR, typed object layer and more es6/py3 set of features.
If you're very much into art, you've probably seen the simple stuff already, and you would prefer to see something that surprises you or makes you think instead of the nth iteration of the same tropes.
But PHP is a tool, and you want your tools to be boring and reliable. (Whether PHP fits the description is a different discussion.)
For example instead of just doing something there are multiple levels of indirection and instead of simply operating on a variable they tend to setup overly complex types that get passed around. Obviously sometimes you need that, but I'm talking about adding this complexity when it's not necessary.
But I would guess that a majority of developers that are not CS researchers value simplicity over complexity, at least in theory. After all they’re just trying to get shit done.
Okay fair enough...
> > I was never able to move from PHP to something else.
But that's why people like PHP, they have little exposure to something else.
People that have experience with langs like Rust, Java or C#, Kotlin, Haskell or Elm, OCaml of F#, they usually do not like PHP. Why would that be?
People who only every have used PHP (and maybe some JS) they are usually the only ones raving about the language.
If you have seen a lot of movies (critics usually have) you are better at judging the merits of movies. Same for languages.
> are better at judging the merits of movies
Their definition of "merit" is "surprises me and brings something new to the table", while a regular person wants "is entertaining". i.e. they are better at judging the merit of something not actually wanted.
Those hinted types are than enforced through an IDE.
Thats just horrendes langauges missuse / misdesign.
If you like strong typing, great, but many popular languages have weak types and dynamic types by design. It’s not some horrendous oversight.
But just because PHP apparently added reasonable typing in >7.2 still makes it a ranchy languages for most of its lifetime.
Anyway ranting about it doesn't imply that i hate it or that i haven't used it. Its one of my first languages, but from my personal view, php is a shitty language in comparision to most others
Then we got Javascript and Node, with even less sensible types (no integers!) so you have to use Typescript and lots of tooling to get what PHP offers.
In enterprise environments Java and then C#/.Net dominated and did have strong typing, but that’s not the world of PHP.
Comparing PHP from a decade or longer in the past to Go et al. hardly seems apples to apples.
So if you want to dismiss PHP as “shitty” compared to “most others” define shitty and identify the others.
And im pretty sure that the history of PHP is still everywere inside PHP, like php function inconsistencies across the board.
Or whats the current situation on unicode support?
When i started with PHP4 and Lamp, what a great time. JavaEE was bloated, not a lot of good free webservers available, granted.
But while PHP5 was great and had a loooong shelflife, JEE became much cooler and had fundamental critical things like CDI and really good CDI Frameworks.
Eclipse Java IDE was always really good, something PHP hadn't had for ages.
And if you look at the fundamental difference between lets say java and php: In Java you have specs and reference implementations (partially also thanks to oracle, you now have mulitply companies having their JVMs) which made the JVM very robust and fast.
When Facebook did the hhvm/hack stuff, that was great and pushed enough nerves to rethink the performance of PHP but the performance gains were stupid crazy. Thats a very good indication when a language with so little money and support has such a huge performance gain after such a long time existing.
The fact that Facebook than threw the PHP community under the bus with hhvm/hack didn't make it better.
Eclipse supported PHP from 2007, and the PHPStorm IDE from JetBrains dates to 2010 or 2011. Java has always had better tooling because of the enterprise focus. PHP IDEs are very good today.
PHP 7.x and 8.x have seen big performance improvements. I haven't seen hack/hhvm get much traction outside of Facebook but maybe it did.
This...doesn't seem particularly reasonable?
You're not required to like PHP, and you don't need a reason why things you dislike are objectively bad in order to be allowed to dislike them.
Its hn, i think its reasonable to discuss asthetics of langauges?
But yes the history of PHP is murky and i do believe, that a few small changes could have big advantages for PHP and because PHP was one of my first languages and i also developed for it for a few years, i do have some type of connection to it.
Just imagine having a more community / sig driven approach defining a spec first, than having a reference implementation and opening it up to others.
And a PHP base rework would also help. Rethinking the architecture and code, cleaning it up and fixing issues which are still there because of it like unicode support.
Even for arrays?
You can describe the expected value or key/value types of an array in PHP doc comments for IDEs and static analyzers, but PHP won't enforce those.
Types are great and they have downsides. Perl, PHP, Python, Ruby, JS, Lua, lisp, objective c are proof that you dont NEED them to have working code.
And what did you mean with "no server updates"? PHP has to be updated and the server processes has to be restarted.
The markup of PHP is a mess, OK js is not much better :D
Sure you can start PHP without any dependency, cause it has a "million" dependencies included.
And yes, i use both. The right tool for the right job.
This is exactly what good/great languages are doing: providing a standard large standard library.
Perhaps what you refer to are great ecosystems of programming languages?
This is not true. You can update a PHP file without restarting your server, and it will run your updated code.
Make sure your .git folder is not "instantly live" as well...
However, it might be a good idea to try languages, that are encouraging different paradigms, belong to another family of programming languages, or are often used for other things than PHP usually is. Try a Haskell, try an Erlang, an Elixir, a Scheme/Racket, a Rust. Languages so significantly different, that they add value for your learning experience as well as enabling you to do new things and get to know elegance in programming language design.
The whole "no build step" was the most underrated factor for its success, because it was such a low-skill tool to pick up.
The tightness of that edit-test-move loop was why I used it, even if the "edit" included "sftp it to a vhost".
That bit is what made it successful & I can't think of anything I've used in the last decade which felt as easy as PHP for that particular style of self-taught programmer.
I have a hard time with people joking about PHP because while it wasn’t perfect back in the day, it’s probably the culminating point of the non elitist computing. PHP was accessible to anyone who had the basics of creating an HTML website (which was a skill any random person could acquire in a day or two).
Also, the people making those jokes are most of the time working on projects with micro services and SPAs everywhere for a boring business app with CRUD and forms. Which I find pretty ironic since a single PHP monolith solved this exact use case 20 years ago.
Nowadays we tend to bring up a whole virtual OS.
An interesting direction in this area might be GraalOS, which might allow running multiple applications in a single OS process, doing the necessary isolation itself. (Not affiliated)
PHP has libraries for compiling SCSS and minifying JS, and filemtime() is very fast. So if you wire them together in just the right way, you can edit any script or stylesheet under the project hierarchy and have them compiled, minified, and bundled together on the fly. Cache the bundle until you edit one of them files again, and automatically bust the cache once you do.
No need to build anything whatsoever, both on the frontend and on the backend. It's like REPL over HTTP.
I use this in production for a system with 3k requests per second that runs in a single Apache+PHP web server and a single 80GB MySQL database. Never needed to optimize anything.
You have no idea how happy it makes me to see someone else was bold enough to try this and it worked for them too.
Simple, maintainable, instant SCSS and JS build pipelines with all the benefits and no drawbacks! Plus any junior can understand and change it in minutes.
If you do compiling and minifying, that's a build step.
Web browsers can't understand SCSS natively.
To be truly extreme (performance), devs should consider tree-shaking unused CSS and JavaScript. This may require using Vite (Rolldown is in the works/Rollup) if there are no other options or it makes no sense to serve bloated resources. That's the reason, I chose Astro as I care about users, not prioritse the developers' minimalistic workflows.
I prefer Tailwind because it allows me to avoid duplicating classes (mine and vendors), which is an advantage over other approaches.
I did dogfooding in Go development.
While it was always easy to debug java based apps and the debug support is great (remote connection, drop frames, all types of breakpoints etc.) people struggled with this in php.
I showed a professional a few years back how to debug with php, after 2 weeks he stoped using it...
To build anything useful you quickly discover that it's hard to build from source (both the lang and extensions), some parts unmaintained for years. There are many counterintuitive idiosyncrasies you must deal with to be productive. The ecosystem suffers from the overuse of indirection and reflection. Php only looks easy, but the rabbits hole goes deeper than most other langs.
Sure but the important part here is it’s also easy to deploy to the internet for free or a few bucks.
All you said is right but still, I don’t think there is anything comparable nowadays and if I had to explain to my son how to create a basic non static website without using proprietary PaaS, I’d have a hard time (without PHP).
Was it the best option when you were a company building a product ? idk but at least it was a viable option. Was it the best option for any kiddo wanting to learn creating things on the internet ? Totally and we never got anything better for this since PHP.
Can you give examples of counterintuitive idiosyncrasies you must deal with to be productive?
Nothing comes close to it in Go, Ruby, JS (Node), Python; from what I've seen. Laravel is one step ahead.
Every language is...
I'm familiar with Livewire and have used AlpineJS, but I plan to adopt Qwik (Resumability) as a component in Astro, which addresses frontend performance. One step ahead of others now that I don't have to maintain Go language as a backend which took me months to migrate to TypeScript for a medium size platform.
And then, you'd need to have an ecosystem as strong as Laravel which... wow... would take a _lot_ of investments.
As far as I know, the bulk of this effort has been one developer pushing it along. I wouldn't personally use it but it _does_ exist.
It's also worth noting that these older frameworks all come from a different era of development - nowadays most newer devs seem to want to build microservice-after-microservice, where these don't quite fit into the picture.
I can't really agree with that when Express and Django exists in this world. But Laravel is indeed amazing piece of software
If you run `laravel new my-app`, you got an application with caching, database, queue, views, translations, whatever else you can think of, ready to use with things like Oauth / Payments / E2E Testing / Feature flags / Search... a command away.
You don't get that with Express, you don't get that with Django, from what I've seen (but I'd be very happy to be wrong!)
But yeah Django is nearly perfect, my dream framework is Django officially typed in a world where the python community get its shit together with type checking.
We are not far but I miss having good IDE auto completion and not having errors in my IDE as a reliable source of confidence.
I mean, with Django, literally just defining your database models in models.py and not touching anything else is enough to have a working application with a full featured admin backend with authentication already built in.
If you define your models correctly with the good constraints you are literally left with writing your HTML views and/or API endpoints, adding permissions and call it a production app.
I’ve never touched Ruby but it also sounds like we shouldn’t discard RoR in terms of productivity.
I'm doing some Ruby for work and I hate it with passion every time i have to touch it.
Official tutorial-style documentation for Ruby is largely non-existstant (except for a book from 2002 that teaches outdated stuff from ruby 1.3). Learning ruby is 99% monkey learning, as in reading some random tutorial off the web and then doing some monkey-see-monkey-do. It's awful and it's frustrating.
Python on the other hand is extremely well documented:
* Tutorial: https://docs.python.org/3/tutorial/index.html
* Standard library reference: https://docs.python.org/3/library/index.html
* Language reference: https://docs.python.org/3/reference/index.html
Guess which language is thriving and which is slowly losing relevance?
Laravel is miles ahead of Django, in every single aspect. The template system is incredible while the django one is stuck in the 90s. The integrated job queues, scheduling, asset bundling, etc, etc. And yes, you also have Admin interfaces for Laravel, both paid and free, and they're as good or even better depending how you look at them. Community is also a lot bigger which means more packages and better maintained.
RoR is insanely productive.
I also found, that doing my own plain PHP imports/requires worked better than what WordPress by default wants you to do for example, so I can well imagine, that something similar can happen with Laravel.
Edit: Link that shows only PHP repos: https://github.com/aaviator42?tab=repositories&q=&type=&lang...
iniSettings();
enforceHTTPS();
session_start();
Global state things directly exposed to the user (programmer in this case). The problem here is, that this kind of thing immediately fails, when things start to use concurrency of any kind, because suddenly one has multiple processes concurrently setting global settings, without any kind of mutex in between. But this seems firmly part of the language??? That is worse! Because it encourages people to use global state just like this. if(isset($_GET["m"]))
Apparently it is still common practice to have such "if bla is set, when do blub" everywhere in ones code? No functions with decorators or a similar or alternative concept? I would think there should be some kind of easy to use mechanism in place, that tends to avoid forgetting these ifs.There are ... 60 lines of global logic, that is not encapsulated in any function or so?
Some of the functions are quite long. But I think mostly because they render out HTML.
At line 107 with the procedure printHeader starting, what I call PHP nightmare starts:
Switching back and forth between PHP, HTML and HTML with integrated JS (!!!) and CSS. All of course without syntax highlighting, but that is a minor issue. The major issue is treating HTML and JS and CSS as mere strings, instead of structured data, and the very bad readability of having procedures suddenly "end" and spit out some wild HTML, then suddenly continuing again, because some server side logic/decision is required at some place in that stream of unstructured data, whether some part is to be included or not, then the stream continues and then at some point one needs to actually check, that one did not forget to truly end the procedure. This has some of the worst readability. Maybe C code with bit magic is worse.
One can find this kind of approach in many, if not most, Wordpress plugins. What's more is, that this is also terrible for writing tests. The procedures do not return a value to check against. All is a side effect. Perhaps there is some PHP library that manipulates the PHP system, so that one can at least do string comparisons on the side effects. Like mocking, basically. But still terrible for testing.
For a comparison of how it should be done instead, check any templating engine, that at least separates template files from PHP code. Better, checkout SXML libraries, that treat HTML as structured data, a tree that can be traversed and pattern matched against, without pulling out arcane string manipulations or regular expressions. And then consider how one could write tests based on such structured data.
If this "HTML is a string, even on the server side before sending it" kind of approach is how a language treats HTML, then the language is not suitable to be directly used for HTML templating, without any additional library. This alone has caused uncountable security issues in so many projects.
I realize, that this is probably kind of a "one off script" and may not reflect other kinds of PHP code.
I did all of those things myself, years ago. And when I already had moved away from such an approach, I had to maintain a project, that was written this way. It had no tests of course. No fun. It has not that much to do with you personally being a good dev or not. I think it has to do with the ecosystem encouraging you to do these things. Outputting HTML like that should be declared illegal and should be impossible.
https://github.com/aaviator42/StorX/blob/main/StorX.php in comparison looks much better. It seems it does not output things directly. Everything seems wrapped nicely into methods. One obvious footgun seems to be another global state thing, that I really hope is not a thing in PHP itself:
const THROW_EXCEPTIONS = TRUE;
Please, please tell me, that this is not an official part of PHP itself.> enforceHTTPS();
> session_start();
> Global state things directly exposed to the user (programmer in this case). The problem here is, that this kind of thing immediately fails, when things start to use concurrency of any kind, because suddenly one has multiple processes concurrently setting global settings, without any kind of mutex in between.
No offense but I take it you don't have much experience with PHP (and that's fine).
Because your complain is exactly one of the beautiful things in PHP.
It's all per request.
It doesn't break.
You don't have to think about mutexes.
That said, I do have some book recommendations and some useful links.
Books:
* PHP & MySQL: Novice to Ninja by Tom Butler
* PHP 8 - Quick Scripting Reference by Mikael Olsson
* PHP 8 Objects, Patterns, and Practice by Matt Zandstra
* Programming PHP (2020) by Kevin Tatroe and Peter MacIntyre
Links:
* https://www.php-fig.org/psr/
* https://web.archive.org/web/20230110234256/https://www.cases...
> The only real difference is that Python will freak out over any small thing, so that developers can be super sure any potential issue or edge-case is caught, whereas PHP will keep on processing unless something extreme happens, at which point it will throw an error and report it.
Wtf. The real difference is, that in the real world people will ignore notices, because they are "merely notices" and because "it works right now", when there surely is a code path, that will rely on the variable being defined and that will catastrophically fail at a later stage or point in time, when the issue is much bigger than right when the undefined variable usage was introduced. How the F is this not an exception. If it can lead to errors and wrong results, which it both very realistically can, it should prevent people from continuing to run it. What happens instead is, that people will obliviously go on with broken code, possibly getting wrong results for years, before someone fixes it. Do not forget the manager people breathing down ones necks when things "work" but one still wants to "improve" things.
The statement is so disconnected from reality, it really makes me doubt the quality of rest of the content. Like a thinly veiled justification saying: "Oh but this is not actually an issue, believe me, all is fine!" when the house is on fire.
PHP is used by so many beginners, but actually due to all the foot guns is more suitable for mature developers, who are very vigilant and strict with themselves, to avoid these foot guns. Basically you cannot let a beginner anywhere near PHP, without a tonne of project setup to safeguard against all of this stuff.
> it really makes me doubt the quality of rest of the content.
I have not read all of it, all I know is that I have found some parts informative, but I have not used this website as my major source. It was mostly the books I have mentioned, especially the first one.
Nor PHP 4 for that matter.
IMO what PHP has going for it is: (1) no build step, and (2) built in templating. Ease-of-use very high in terms of web development.
I am interested how PHP and frontend tooling will work out in the future. Nobody is compiling JS/CSS with PHP (as far as I see). That is usually done with Node.js. Livewire (and Inertia.js) are bridges. Sometimes PHP becomes a backend to provide an API for an SPA frontend.
Python, C#, C++, and JavaScript are super popular. Ruby, Go, and Kotlin have been getting more popular. Etc.
I know people who are just now getting into Laravel and I'm sure it will remain a valid framework for years. That said PHP's popularity has only been going down since it peaked around 2010. This is reflected in all metrics you can think of.
https://www.tiobe.com/tiobe-index/php/
https://trends.google.com/trends/explore?date=all&q=php&hl=e...
https://insights.stackoverflow.com/trends?tags=php
Ironically, PHP is a pretty awesome language now compared to the days of v4 or v5.
The one area where PHP is useful in 2024 is for prototyping a website quickly. As a one-person team, PHP without a framework (and without OOP) is the fastest way to build a fully-functioning complex site. I built a massively complicated site this way, in very little time. This is great because if it ever becomes popular, I can simply hire developers to rewrite it in the latest framework du jour (probably Next/Nuxt/whatever)