Hacker News new | past | comments | ask | show | jobs | submit login
PHP 8.1.0 (php.net)
335 points by AegirLeet on Nov 25, 2021 | hide | past | favorite | 273 comments



I've been using PHP since 5.x. Often had to work on older 4.x web apps. I find it interesting when I read people saying "PHP has come a long way. It's a proper language now, etc."

If you work long enough with a language and figure out most its quirks, it's a breeze. It's nice that they are adding all these new features, but they are hardly what makes it or break it for me.

Here is the one features that is taken for granted in "modern stacks":

Edit file -> Alt+tab ctrl+R. Oops, Alt+tab fix -> Alt+tab ctrl+R.

When debugging I can do that 50 times a minute. With my react app, I can do it maybe 5 times a minute. With my golang app I'm lucky if I can do it twice a minute.


I worked with PHP solely for years and always thought the language was good for me but that it made it easy for codebases to go to shit. I’ve worked with half a dozen other languages now and have realized all codebases just suck for the individual because like all things people are heavily opinionated about how the code should be organized.

As for react, I work with a medium sized code base in the hundreds of thousands of lines and all I have to do is alt tab since it hot reloads for me. Don’t see how PHP is any better since it isn’t even hot reloading. Also with react I can update css and it doesn’t lose the state which is nice for debugging style changes.


I wonder how much of the shitty code bases have more to do with the popularity of PHP (for web based applications) than anything else. I've seen plenty of shitty code bases fin just about any language. If there's more of something, there will be more of it that's of low quality.

Not denying your point though. There is some real awful stuff out there that could make a grown man cry.


You can use a live reload tool, e.g. BrowserSync, to automatically refresh webpage after source file change. Put your browser on half of screen if you have big enough monitor, or even better - use dual screen setup. And if your IDE supports automatic saving, you are down to single step: "Edit file".


That's still much slower with JavaScript. We use both in php land.


In Javascript I don't compile or transpile Javascript during development so my src chagens are loadeded in chrome really fast. I suggest you to try snowpack or create your dev code test stream in fashion that do not require src code transformations.


What monsterous golang app are you running that takes 30 seconds to compile?


More interested in what meaningful fixes can be done in some fraction of the 1.2s RTT of this rapid-fire style PHP development.


Output to html, meta refresh page every second. Pretty much real-time results.


> Pretty much real-time results.

This to me feels really underrated nowadays - at best, you shouldn't always have to reason about your code inside of your head and try to figure out how it'll work in detail, or read API docs for all of the obscure frameworks that you're using.

Test things in real time at first and in the cases where they don't, continue doing so, but with a debugger and stepping through everything bit by bit, or read the docs, or whatever the non-trivial cases will demand.

In my eyes, that's the exact same thing as autocomplete in IDEs - instant feedback, to free you from having to think about yet another mundane level of abstraction or API details, instead letting you solve the actual problems that you're faced with.


I think the problem is they haven't set up tools to make it really quick. Even if the compilation only takes a few seconds, they are probably switching to a shell, firing of a make command, maybe restarting the server etc. All stuff that could (and should) be automated and available at the press of a keyboard button. In my emacs setup, any language that requires compilation I bind the key C-c C-c to "build the app now". So then compilation literally takes a few seconds not a few second plus ten seconds of overhead.


With a proper type system you don’t need to run your code 50 times a minute.


Code that passes type checks can also fail to solve the user's problem, make 10,000 database calls, or render a page that is completely unreadable.

The human in the loop is a good thing. All things being equal, the type system is also a good thing, but what usually happens is that you end up checking your page once a minute or once every 10 minutes, not 50 times in a minute. That difference can make or break a project.


It depends a lot on what you're working on. If you are building a front end with PHP as your templating language, then yes, the ability to instantly see your changes is huge. In my experience, when working on back end, the difference isn't that significant because you really want to be using unit tests anyway, not constantly interacting with the front end to test your work. In those back end cases, having a strong type system makes a huge difference.

I'm working on a project that has a legacy PHP code base and a new JVM code base. What kind of naturally happened is that we end up doing most of our front end work in PHP and all of our new backend work on the JVM.


I've rewritten a ton of legacy PHP services / page generation code into NodeJS over the last couple years. I know PHP inside-out and love it the way you love... um, something fugly like an old futon. It's really nice to be working in Typescript on both ends now, to have share modules and data models between server and client codebases. But one thing I do miss about PHP is not needing to make sure the server restarts on every backend code change. Nodemon and PM2 are both pretty good about this, but it's that one out of ten times they don't restart and I spend a minute or two wondering what I missed before realizing they didn't restart; happens a few times a week and drives me up the wall.


Yeah I definitely agree that it's domain specific, and I was really talking about front ends (hence "checking your page").

User interfaces, data science, and security/reverse engineering work are three domains that really require tight feedback loops. The work I did on parsing shell [1] is basically a kind of blackbox reverse engineering, and was done with < 100 ms feedback loops.

[1] https://www.oilshell.org/blog/tags.html?tag=parsing-shell#pa...


And for those cases you should use tests, not a manual procedure.

Of course you will need some manual procedure, and e2e tests, but not “50 times a minute”. That is just frustrating.


Well php has strong typing built in now and they have been iterating on it every release. It's well ahead of native js. I can't imagine having any real complaints on using 8.x php for a back end these days.


I still dislike the constant $ and ->, today it just feels like extra typing. Otherwise I agree with you.


I'm with you. This is the only complaint I have about the language itself.


Trying to imagine php without $ and all I can think is... :o


I never seen any practical proof of that often repeated claim. Unless you define "proper" in an absurd way that has absence of bugs as the part of its definition, I've seen roughly as many bugs and as much time spent debugging in strongly typed languages as I have in weakly typed ones. Sure, some kinds of bugs go away, but they're replaced with different ones.


Just try it out.

I am not saying that a type system will find all bugs. It will stop you from running incorrect code “50 times a minute”. Then you should have tests. Lastly you must also do some manual procedure (or run slower e2e tests).

Doing all this yourself constantly is just frustrating.


I did. I've been doing it for over 3 decades, and worked with all kinds of languages. Of course, it's only my own anecdotal data set, but no, "once you try strongly typed language you'll see how magnificent it is" doesn't work anymore. I tried, and it's not that it's bad - it has its advantages - but it's not the bugless paradise that fanboys promise. And also I learned that running incorrect code 50 times a minute is not bad at all - actually, it's a pretty good rapid prototyping technique. Some people never launch their code until they are sure it's 100% perfect, I am not one of those people.


As someone who isn't perfect, it's nice to be able to quickly iterate on ideas.


You still can. It’ll just stop you before you get to a running web application that may be doing something wrong with the data that goes through it.


Iterating on ideas is much quicker when the compiler tells you when you made a mistake or failed to change your code after changing your mind.


Honestly, I don't see much difference. You learn either way. People may have preferences, that's fine. A compiler isn't a magical tool that creates bug free code.


A compiler with a good type system catches a mistake instantly instead of at runtime.

The difference in time it saves the dev can be anywhere from a few seconds to minutes per mistake.

Multiplied by hundreds of mistakes, it makes a huge difference. And that's not even getting into the advantages of better autocomplete for external libraries.

As someone who has written many thousands of lines of PHP, JS, TS, C#, Java, and Python, I now find it baffling that someone would start a project in 2021 without a great type system as a safety net.


The difference is massive. Computers are many orders of magnitude better at this kind of thing than humans, especially in a large application where changing the shape of a single data structure can have cascading effects throughout the entire code base; you simply will not catch things a typechecker will.


An IDE does provide some help. Certainly, I'm not arguing against compilers. I was merely commenting on the "iterating on ideas is much quicker".


Hello me! Nice to meet me!


Show me a practical type system that rejects all programs with logical bugs.


When working on PHP only I didn’t care at all for the quirks or missing features. When going back and forth with other languages, PHP getting better becomes a huge quality of life improvement, the mental load we need to keep gets much lower.

PHP has always been a powerful language where the burden of making it work properly 250% relies on the dev. Stuff like enums should significantly reduce that ratio, it’s a big deal I think.

On the debugging part, I found something like ruby’s pry to be the easiest and fastest option. I wish PHP had something similar.


Tight feedback loops are a very good thing.

It's probably part of the reason for the success of PHP and similar.

However, being able to have a "compile" step that does a lot of work to make things faster is also very useful. The key is being able to switch between them easily.

In PHP for example there is the code cache (added later but basically standard now), and assuming it's a web app you probably want to crunch the images and CSS in production.


Tight feedback loops are great, but even as an experienced dev, I still make minor mistakes that the ide doesn't pick up, and even with tools like psalm, you will still encounter type error.

One of the reasons I use golang where possible, I feel more productive in golang because any mistakes you are make are almost always logical issues with the code, rather than language error and usually works first time.


> When debugging I can do that 50 times a minute.

In interviewing, I've seen a few candidates re-run their application after making single statement changes. They'll rename a variable, re-run. Change a conditional, re-run. Introduce whitespace, re-run.

These people aren't even confident in renaming variables!

PHP enables this type of underestimation in your own abilities. You don't need to distrust yourself so much.

Don't think you have to do this.


>PHP enables this type of underestimation in your own abilities. You don't need to distrust yourself so much.

That might be true, but sometimes it happens that you overestimated and introduced a breaking change 20 changes ago and now you have to rewind your steps back to find the exact place. If an iteration can be done in less than a second, it's probably cheaper (and less stressing) to just check every single change like this. This is what many coding editor integrations actually do for you.


> PHP enables this type of underestimation in your own abilities. You don't need to distrust yourself so much.

I've even had IDE refactoring tools fail on me whilst doing this, in type checked Java codebases, with reflection in place and annotations, which predictably caused problems down the road. At this point, i'll take any and every method that can help me in development, especially in the face of meaningless cruft and unreasonable complexity.

I'm actually writing this in my 5 minute break after being stuck at work 1 hour past my official work hours, due to some stupid bug where one service ignores a client certificate from service A, but not from service B on the server in containers.

The opposite end of this spectrum (my current circumstances) is completely unreasonable IMO - a change in code needs an app recompilation and a push to the container registry before it's deployed on the server (cannot reproduce locally, possibly proxy configuration is to blame, but it's so simple it should not be possible), whereas configuration changes need the Ansible playbook to run to the end, which also takes time.

Thus, my feedback loop is ~10 minutes for seeing a new way in which the app will fail to do something supposedly simple. Even in normal circumstances, local app reboots still take at least a minute or so, since JRebel and code hotswapping just doesn't work a lot of the time with the frameworks we're using. I'd take being able to see the changes in my code every X seconds over every X minutes any day of the week.

Even if i trust myself, i still want that freedom and speed of development and checking why everything breaks.


>Here is the one features that is taken for granted in "modern stacks":

>Edit file -> Alt+tab ctrl+R. Oops, Alt+tab fix -> Alt+tab ctrl+R.

Yeah, this is pretty much what the Common Lisp and Smalltalk people have been doing since mid 1980s. Except that they're not limited to web applications. And also python people to some extent, with ipython. And Haskell people with ghci.

The value of less friction cannot be overstated in coding work.


> Except that they're not limited to web applications

With PHP, you're not limited to web apps as well. The same rapid-fire style development can be applied when building CLI applications.


That's news to me. Does PHP have a REPL now with module reloading with lingering state?


> Edit file -> Alt+tab ctrl+R. Oops, Alt+tab fix -> Alt+tab ctrl+R.

> When debugging I can do that 50 times a minute. With my react app, I can do it maybe 5 times a minute. With my golang app I'm lucky if I can do it twice a minute.

Hmm... when working on React stuff I don't even have to do the ctrl+R stuff. Hot reloading in the browser is a thing and works quite well. When working with Django it's very close to being the same as the PHP experience thanks to automatic server reloading. I worked with PHP extensively back in the day but I never miss the tight feedback loop (although maybe this experience is why I always make sure I have such a tight feedback loop in whatever I do, I guess you don't always get it by default).


You can do this in Golang as well. Just put all of your business logic inside template/html.


Yeah, you could, but should you? ¯\_(ツ)_/¯


It really depends what you call a language. I find it interesting how developers can be to 3 different things with the word language : the actual language, the language + standard library or even the language + standard + ecosystem. So a sentence like "PHP has come a long way. It's a proper language now, etc." will mean very different things to different people.

The heart of PHP (not the standard library binding C libraries part) do have come a very long way. Even the things that look the same to you on surface have change under the hood and are way more performant thanks to it.


The idea that development in golang is slow is funny.


Same folks say Perl is unreadable because the syntax for certain aspects of the language is unfamiliar to them.


There might be more to it than that...

https://news.ycombinator.com/item?id=19576425


Going from PHP to jinja templates in python is also pretty terrible. But I guess that's more of a hobbyist problem, than large commercial web-app problem.


Good point. One can read it as "making 50 mistakes per minute", I read it as "wait only 1.2 seconds to see the effect".


Is oopsing 50 times per minute a good thing?


No, not just oops. I get to see the state of the entire application with different values.


If you're doing iterative development, why not.


Less oops and more "let me try this out"


Of course not, it is just a way to show how fast things can go with PHP.


I just run go test. No need for alt+tab. Why reloading anything when testing the backend code?


Perhaps it's not a SPA but has traditional backend-side templates for pages.


What's the problem having a HTTP client running in tests?


Nothing but not really a substitute for looking at the page.


You don’t need to recompile for template updates.


Once you throw that stuff in K8s, you’re back to 10seconds.


If I throw my dinner in K8s, will I get back filet mignon?


Nope, you get Vienna sausage


Accurate.


Do you debug your apps in a K8s environment? Why?


To be clear, I’m not saying this is a good reason, but I’ve been doing it lately because otherwise the browser security features prevent a local auth service from passing tokens to the backend app via the browser. I need to figure out a way around this because the iteration loop sucks; probably I’ll add a flag to disable auth on the backend app so I can test non-auth-things locally.


Sometimes in that scenario my approach is to ssh into the app container and make the changes in there, moving the fix to version control when it is in a shipable state.


Yeah, that’s not a bad idea. I considered that but it seemed like a lot of work to set up the container to run an SSH daemon and work out the forwarding, but maybe I’m overestimating the work involved?


Usually a docker exec will do the trick. I do a lot of that when exploring an application that's new to me - where it keeps logs that don't trickle up to monitoring and stuff like that.

If you find Emacs in a container, it's probably me ;-)


I don’t think that would work because you would need to drop in the new binary and restart the program and as soon as you kill the program it will kill the container and bounce the pod. Moreover, my app is just a static binary with some certs on a scratch image, so I can’t even `kubectl cp` the binary because that depends on a tar binary on your container.

I think I would need to run some sshd program on the binary and use a reverse SSH tunnel from my laptop, but that requires me to expose an SSH port on the pod which isn’t a big concern, but it’s just a grind to get it all working end to end.


Everyone laughing at PHP hasn't tried it for years, I'd bet. It started clumsy, true, but it became a solid and quite elegant way of doing things.

And by things I don't mean just web development.

The current limitations I see in PHP is that there is not an official multi-core coroutines solution.


"Everyone laughing at PHP hasn't tried it for years, I'd bet."

God I wish that was true...

It's not that the language is necessarrily bad. It's the sludge of legacy code I've had to deal with and teams treating it as the hammer for every problem that they think they must treat as a nail.

Efficency be damned.


Elegant is not the word I'd use to describe PHP. Solid, perhaps. Undoubtedly useful. But if there is elegant PHP, I haven't seen it.


Have you looked at any Laravel code? As someone who has worked from small startups to FAANG and inbetween, Javascript to PHP to Python to Go, I haven't found anything more elegant.


I have. Elegant it is not. Actually, it smells like Enterprise Java code, which made me flee from the Java ecosystem. To each his own, but this is not an elegant event listener (copied from the examples page):

  use App\Events\ArtistInformationFetched;
  use App\Services\MediaMetadataService;
  use Throwable;
  
  class DownloadArtistImage
  {
      private MediaMetadataService $mediaMetadataService; 
  
      public function __construct(MediaMetadataService $mediaMetadataService)
      {
          $this->mediaMetadataService = $mediaMetadataService;
      }
  
      public function handle(ArtistInformationFetched $event): void
      {
          $info = $event->getInformation();
          $artist = $event->getArtist();
  
          $image = array_get($info, 'image');
  
          if (!$artist->has_image && $image && ini_get('allow_url_fopen')) {
              try {
                  $this->mediaMetadataService->downloadArtistImage($artist, $image);
              } catch (Throwable $e) {
              }
          }
      }
  }
Source: https://laravelexamples.com/example/koel/events-listeners


It's interesting to me how to show your example you chose something from a 3rd party, non Laravel site (just because it has a laravel in the name doesn't), and chose something which inherently doesn't follow PHP or laravel coding standards (snake_case variables, for instance), when you could easily pull something from the main Laravel website?

https://laravel.com/docs/8.x/container#introduction

Or, if you wanted something perhaps at least use one of their featured partners for real code? https://github.com/tighten/jigsaw/blob/main/src/Jigsaw.php

I also would argue that the majority of code I see in other languages is equally or worse than the example you gave.

You can write terribly in any language, Laravel included.


I think most people outside php have no idea what Laravel is, while anyone working in php is using Laravel so basically our viewpoint is Laravel = php. I don't know what it is about the normal personality that anyone using something you don't understand just be "doing it wrong"


I see php sort of like a trusty hammer. It's a hammer. Doesn't have to be elegant. It's a hammer.

The nails are http requests and PHP is a damn good hammer.


Cue the infamous double-claw hammer meme. I'd agree PHP is quite useful for web work, especially backend. And like a specialty hammer it wouldn't be useful in a lot of situations such as desktop apps or DB procedures.


Hello World in PHP is literally

    Hello World
I know no other language that elegant.


If programing stopped there we wouldn't have an argument, its when you design high performant code that is maintained for over 10 years etc.


From the top of my head, Javascript and Common Lisp will also work with "Hello World" (with quotes).


I can’t speak for Lisp, but JavaScript isn’t going to write that to standard out, it would just be a statement that didn’t do anything.

You would need something like

    import { stdout } from 'process';
    
    stdout.write("Hello World");


Fair enough. On the client (just opening dev tools) it would return the string, but as you say, it depends on what we count as valid (repl, server-side, client). Probably the closest would be

    console.log("Hello World")


Being able to do a trivial hello world doesn't make a language elegant.


The easiest Quine imaginable!


m4


This depends a little on the taste of each person, but personally the most elegant way of doing PHP apps I ever found is with Siler: https://siler.leocavalcante.dev/v/main/ and Create Siler App: https://github.com/leocavalcante/create-siler-app


PHP is elegant and useful. The spread operator is ...$array is elegant. $var ? "not found"; is really elegant.


It’s also about ten years later than everyone else to get those splat and null coalesce operators so it’s not like that elegance is unique or even timely for PHP.


Your post is 10 years too late because we are talking about php today. PHP was elegant in different ways 10 years ago.


I think you meant ?? or ?= ?


One comment I heard at a programming meetup recently was "I hate how frameworks like laravel have brought PHP back in to popularity when we had the chance to finally kill it off".

I do wonder if there really was value in salvaging PHP when we have a wealth of other languages and frameworks that do a perfectly fine job without any of the legacy mistakes sitting around.


There isn't a language that can replace php in 2021. Javascript doesn't have the size of build-in library. Golang is compiled and limited, blank spaces/tabs will kill a Python program. Ruby /rails is slower. All are harder to host. What could you replace php with?

The tales of legacy mistakes holding back php are things with no basis in reality. What legacy mistake holds php back? Method names/parameter ordering?

When I started with php in 2001 those elite programmers at meetups were looking down at php because Java was cool. In 2003 those elite programmers thought php should die because asp took over. PHP kept going along quietly taking over the web until the facebook movie came out making PHP cool for a moment. Those elite programmers decided PHP was too mainstream and the why PHP sucked movement started. The elite guys moved to Ruby On Rails then node/MongoDB, angularjs, React, Nextjs leaving each ecosystem for the next hoping that one day they will strike gold.


Honest question: what are people using if not PHP? Node? Python? The 80% of us who aren’t FAANG and are writing CRUD apps. I’ve tried researching the pros/cons and all I get are low quality listicles.

Nobody can tell me why PHP is “bad” or what Python does that PHP can’t. Inconsistent params are the only argument I’ve heard. Which my IDE solves. What about JavaScript splice vs slice. I look it up every time.


I write PHP for my job almost every day, and have for the past 4 years, and there's some truth to what you say: anything you can write in another language, you can also write in PHP.

Personally, I can't stand writing PHP, because, sure, I can write secure, testable, safe code in any language, including PHP, but, how do I say this, PHP is the only language that feels actively hostile to my attempts to do so. The house style at my current company could be boiled down to "Check 3 times that there are no PHP footguns present in this code. We have been burned before." The developer experience and tooling is far behind comparable languages. I feel like I have to put my sysadmin hat on to fix anything that goes wrong with my environment.

When I write Javascript or Python, I have complaints and issues, but I enjoy writing code. I think PHP, for many programmers, including myself, is just a hostile and unenjoyable experience. If you enjoy writing PHP, I have nothing against you and am certain you will remain employable, there's a lot of PHP out there.

> Honest question: what are people using if not PHP? Node? Python? The 80% of us who aren’t FAANG and are writing CRUD apps.

Python, Node, Java, .NET, Ruby. MVC CRUD apps are pretty similar in all of these (also in PHP). All of those languages (including PHP) power many many many software companies (including FAANG, who use a lot of Java and C++, and Facebook famously was built on PHP).


> When I write Javascript or Python, I have complaints and issues, but I enjoy writing code. I think PHP, for many programmers, including myself, is just a hostile and unenjoyable experience.

Surely JS has at least an equal amount of foot-guns to PHP. I mean, at least PHP (to my knowledge) never had a meta-language written around it that compiles to PHP to make it safer.


Did Hack start that way, or am I misremembering?


IIRC Hack transpiles to C++ with an intermediate build step. So not exactly the same.


What footguns would that be?


When picking server language for web development I think it is more important to look at how the platform works rather than language features.

This is important

  * memory model (shared, per request, etc)
  * request model (by the app or by the web server)
  * compilation/build step
  * deployment 
  * hosting
  * tooling (IDEs, linters, testing, package manager, etc)
  * how to scale
  * available programmers
  * community
This is not important

  * $ in variable names
  * arrows (->) for accessing object members
  * argument order in standard library
  * not elegant enough


Out of date but this is the classic anti-PHP polemic. https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/


Can we _please_ stop posting that link, in 2021? It's very, very outdated.


I warned it was outdated and it has a date. Nevertheless, it's a classic piece and a number of the criticisms are still true. I don't see what makes it any worse than linking to the Unix Hater's Handbook, which is also outdated in many respects and yet still considered a classic for a reason.


It was out of date when it was written.


People are using Node. And they move a lot of the processing to the front end with things like React.

They have trouble grokking that there is a method of dev in which the server is not the language parser, so all other languages feel like a wrong step.

Here on HN someone just asked why anyone would write in anything except JS [1].

Now, Node has it's advantages, and so does PHP. My personal preference is PHP. But in mindset, Node is far ahead of anyhere that Rails or Django ever got in their respective waves.

[1]: https://news.ycombinator.com/item?id=29321426


Golang.

Static typing, concurrency, blazing fast, single binary.


Statistically PHP software has the most vulnerabilities. They are also quite different when compared to other languages. Language has many features which might be used unintentionally by programmer, leading for serious bugs. Not a good language to start with.


What features are used unintentionally leading to serious bugs?


The ease of the "just put it on the filesystem and it can be run!" system also opens up security vulnerabilities when people want to enable file uploads, for instance. I think the proliferation of places you can put configuration for the runtime is also a potential source of issues, as are various forms of string escaping that should be avoided.


Take a look for https://book.hacktricks.xyz/pentesting/pentesting-web/php-tr... for example. (Note also, that is the only programming language specific list, which is one mile long.)


These are older issues. When you see comments like: This bypass was tried apparently on PHP 5.2.5 and I couldn't make it work on PHP 7.3.15) I'm not sure these apply anymore. The loose == vs strict === exists in many languages. You can make the same mistake in Javascript.


> Javascript doesn't have the size of build-in library. Golang is compiled and limited, blank spaces/tabs will kill a Python program. Ruby /rails is slower.

I have once heard an ancient prophecy (I think it's Greek) that says "Debating around PHP online summons the ghost of the dark behind your back" or something like that (I don't speak Greek, sorry).

In the Client/Server world now days, the most of the time you only need one or two languages, one running on the Client side (JavaScript for example) and one running on the server (**, Go, Java, JavaScript etc).

In that setting, JavaScript comes with the hard advantage of both-end compatibility, that gives you something like Server-side Rendering, which no other backend-only language could do, at least not "natively". If you have a foundation this good, people will build the library themselves when the language/runtime don't have it built-in. (the same is true when it comes to Swift/Dart/Kotlin. I bet there is someone/company out there writing both their app and their backend in Swift/Kotlin)

For "backend-only" languages, it's largely down to personal/team preference. Some needs performance, some wants "write-friendly" (contains many factors). But the problem is, the market now days is saturated with better options that also do more things (often in a better way). When you bring all the options on the table, then suddenly that-language-the-name-we-shall-not-say started to look way less attractive.

It's just that, comparison/competition kills things, no elite required.


Server-side rendering is what php and these other backend frameworks do when responding to a request. If the output is html a browser will read and display that. Whether it comes from node or php that hello world h1 tag looks the same to your browser.

The problem with swapping out php on the backend for node is now you have to maintain a node server, manage long running processes. If you make a change to a node file you have to restart the server. Where php is running under apache or nginx and files can be dropped in without taking down the site.

That's why everyone is going serverless.. who wants to manage a node server.


It exist multiple libraries/frameworks that allow you to write modern dynamic applications with server side rendering only, like Hotwire, Livewire, htmx and unpoly, thus the need to write a large amount of JavaScript for the frontend is no longer needed.


> Server-side Rendering, which no other backend-only language could do

Isn't it the definition of a "backend-only language" that it renders server-side?


I think they're referring to server-side rendering of SPA templates, which is something you get basically for free if your backend is written in NodeJS.


I've been working with php since 2001 and that whole time I've been cleaning up bad ruby and nodejs and PHP implementations and knowing JavaScript well enough to code in whatever front end nonsense comes out from PrototypeJS to jQuery to ExtJs to angular to react on and on ad nauseaum. Throughout PHP was my actual workhouse. It's kinda frustrating when I meet someone super into JavaScript as a backend because I still choose PHP even though I have 20 years of JavaScript under my belt and love Es2015+ promisable JavaScript.

I'm not even really sure why python is so popular for DevOps cause I do everything in php and it's unit tested and works well with reproducible results.


> blank spaces/tabs will kill a Python program

That's a lousy dig at Python. Stuff you solve with a free text editor and 15 seconds worth of configuration aren't real problems.


other than Phoenix framework maybe are there any others with as much included as laravel has?

caching, jobs, docker via sail, authentication and authorization, one command to have a full multi team/tenant SaaS app template via jet stream.

even rails doesn't have this, as you need to choose your own implementation for auth and access control, something like sidekick for job queue etc....

plus the ecosystem. I've tried so hard to like other frameworks and some I really do (like remix.run) but the lack of real momentum and community hurts most anything else and just doing everything as serverless micro services isn't always preferred or using micro frameworks.

I'm excited for the new features and with octane you can get more reqs per second than Phoenix framework which should make it easier to scale apps with less resources.


.NET has most of this. Love it.


Which ones would that have been? Perl? Python? Java? JavaScript?

Among that choice set, PHP is definitely the best contender.


I would say that Ruby on Rails is a pretty good candidate to completely replace PHP with.


I think you (and to be fair, many people) are missing a huge part of why PHP is still popular. Saying Ruby can replace PHP sounds to me like saying that Ruby can replace Excel. It's fundamentally misunderstanding _why_ it's popular in the first place.

I have a HTML page. How do I add a hit counter to it with Ruby?

I can do it right now in PHP with zero dependencies and it'll fit in this comment:

    <html><body>
        <p>You are visitor number: 
    <?php
    $count = file_get_contents('hit_count.txt');
    $count = $count + 1;
    file_put_contents('hit_count.txt', $count);
    echo $count;
    ?>
        </p>
    </body></html>
Is it shit? Yep. Does it (mostly) work? Yep.

When you want to do something, you can just copy and paste a handful of lines of PHP into a file and rename it from .html to .php and it'll basically work anywhere. You don't need to worry about frameworks or anything. Routing is handled by the web server. Hosting is handled by someone else. Deploying is just FTP'ing a .php file off to a server somewhere and then requesting it.

But when you are ready to get into "real" programming, that's all there too. PHP has a true learning _curve_. Every bit of complexity is only a small step from the previous. Getting started does not require a ton of background or knowledge. You can start out copying and pasting some code into the middle of some HTML and a year later end up working within once of the nicer, more comprehensive frameworks managing your dependencies with a relatively decent package manager... and still hosting it all on your $3/mo shared hosting.

If every professional developer stopped using PHP tomorrow, we'd still end up back exactly where we are as a bunch of people found PHP as the most accessible and direct solution to the problem they have.


This example seems to be a great demo of why people do not like working with PHP. PHP makes the shit method the massively simpler way and the good method much harder. Now you open yourself up to risks like what happens if we accidentally let some user input change the file opened as well as the content written.

While with rails, to do basically anything, you already have a full db ready and incrementing a counter using the ORM is even easier than opening a text file. So people avoid PHP because it most likely involves dealing with absolute crap code written with no understanding.


I don't find these kinds of what-ifs very useful. I haven't used Rails, but does it somehow prevent you from accepting user input and programming it to go where you say you want it to go? Isn't there an element of "holding it wrong" with any language or framework?


Rails actually does do a good job of treating user input as dangerous and it can often detect when user input is being used in the wrong places like directly in to sql. And with industry standard tools like brakeman, you can have CI alert you of most cases where user input is not safely handled.


That's way too complicated for the person just starting out and wanting to add a counter to his small website. Nobody starting out with programming today will start with Rails. They might start with Javascript, but more than likely they'll start with PHP. It's accessible and SIMPLE.


>PHP makes the shit method the massively simpler way and the good method much harder.

How it makes it harder? Or you compare PHP a language with Rails a framework? Maybe shut up if you have no idea or show us a pure Ruby code that does the same thing. Or install the most popular PHP framework, really learn that and then tell us that PHP made things harder. I don't know Ruby or rails so I can't shit on that like an idiot.


Please refrain from name calling and phrases like "shut up". They don't really add to the conversation.


I apologize and I will try to do better.


This makes my eyes bleed.


Inline PHP reminds me JSX. Everything old is new again.

<? include '../menu.php' ?>


Except in-line JSX runs in the browser and is not very exploitable.


JSX certainly does not run in the browser.


does rails come with a generator to create a teams based multi tenant SaaS app with authorization and authentication and job queues without extra setup? (ie without decide and sidekick?)...

can rails compete with the performance of octane using swoole with 8k reqs per sec?

rails is the first framework I ever learned in 2012 but I kept jumping back and forth until laravel basically started lapping rails in terms of baked in goodies.


I’m not sure why this really matters. You can set all of that up in rails in under an hour. And almost every company uses exactly the same libraries for it all. It’s been so long since I even created a rails app because it’s almost always already created when you start the job.


Doubt there was a chance to “kill it off”, doesn’t it run over 50% of all websites?


It's a CRUD staple. There's no other language so well suited to easily building CRUD services (of which WordPress is one). It's a big cherry on top that the language has gotten better and dramatically faster over the last several years.

There was no chance of it being killed off rapidly as the author was perhaps implying. It might have slowly rotted away, had the maintainers not stepped up with v7 and hit a home run.


PHP powers a couple of the software packages used by over 50% of websites. Mainly being Wordpress. Impossible to know but I would guess that new development of PHP sites is not such an impressive stat.


PHP runs the long tail of the internet. And somewhat accidentally, it also runs Facebook :-D


I used Symfony and it was fine but there are some challenges:

1. The combination associative array/array data type is weird and I feel like the performance is not predictable unless you devote time to learning specifically about it

2. You're still stuck with all the weird legacy stuff, even if you don't use it, because someone else might bring it in

3. The OO stuff is basically like an old version of Java and a bit tedious to write. An IDE is definitely required

4. Many PHP developers formed their ideas about coding in the bad old days and will resist efforts to make code more testable or whatever because it's "too complicated."


> The OO stuff is basically like an old version of Java and a bit tedious to write. An IDE is definitely required

The OO 'stuff' in PHP is far better. Notably, Traits, Statics and Testing.

Java (and JUnit) do not work well with static methods/classes, when it's unironically the most effective way to limit state. In PHP you can create a static class, that has static utility methods. Now you can ensure you have no side effects - unless accessing static properties somewhere, ofc. Then PHPUnit has no trouble helping you test these. It's a huge improvement over the acrobatics of booting up Spring to manage a singleton (which isn't the same thing as a static class) whenever you want access to those real static methods.


I'm not sure what about Java is stopping you from making static classes.


> I'm not sure what about Java is stopping you from making static classes.

I didn't imply that you couldn't make a static class in Java. There are lots of ways to make something like a top level static class (nested static, Spring singletons, et al), which works against the explicitly stated purpose of limiting state involvement.


Those limitations are a little annoying but I'm not sure how they're preventing you from doing what you want to do, and having top-level statics wouldn't limit someone from just sneaking global state in there either.


    @Test
    public void testSomeMethod_FromStatic() {
        StaticWrapper1 staticWrapper = new StaticWrapper1();
        int mockInput = 1;
        RegularClass rc = new RegularClass();
        int expected = 2;

        int ret = staticWrapper.someStaticClass.someMethod(rc, mockInput);

        verify(staticWrapper.someStaticClass, times(1)).someMethod(rc, mockInput);
        assertEquals(expected, ret);
    }


    public class StaticWrapper1 {
        static class StaticClass {
            public int someMethod(RegularClass foo, int val){
                return foo.someAddMethod(val);
                /* it's not practical to chain, eg
                   staticWrapper2.someAddMethod(foo, val);
                   because you end up with circular dependencies or passing large numbers of deps around, which you can't verify in tests anyway */
            }
        }
    }
You cant do this (verify the static call) by default nor anything more complicated than this (with Mockito Static mocking) because JUnit cant track deps through statics for testing. If you have multiple static objects that have static methods, you end up with brittle chains of instances that might need to refer to (either passed in or member instances of wrappers) just to call other static methods. This is inferior to PHPUnit.

Making syntactical boilerplate "just because", which also requires instantiation breaking DI (ostensibly, all you have to do is boot up Spring IoC container and it's there are runtime), is inferior to PHP.

Maybe one day Spring will be baked into Java, but that's a one-ton runtime workaround for a small mistake in the core philosophy, ie you can put a non-static function around a static function and treat it as the static, so it's a JVM problem. Pushing explicit instancing to the code is bad design from a makeshift solution to get Java working on older platforms, quickly. Now java does prechecking of memory anyway, so the way you have to do static implementation is an extraneous legacy limitation.


Right, I mean, if you need to mock it a singleton would be a better choice; that's kind of the point of the pattern. Personally, though, I feel like if you frequently find yourself needing to mock these static classes, then they're not really as effective at avoiding statefulness as you claim -- if they're side effect-free, it should be safe to just use the implementation.


You need to mock them because you are asserting that it is the correct thing to use. Verification testing has nothing to do with state, per se. Having a static instance a wrapper just to use another static is java forcing unnecessary state. Forcing a singleton to instance another singleton at runtime is idiotic, which is why spring proponents avoid it and java is still a syntactical dinosaur. When we see proper modules (including static refs), java will be better fir it.

PHP is better with how it deals with statics today, which bleeds into other areas like testing.


Not intended as a plug but you can even use php for network automation. I cobbled this together:

https://github.com/epiecs/phpmiko for connecting to devices and https://github.com/epiecs/mikodo for inventories and concurrency

The multi core coroutines comment is true but there are ways (to hack) around that.

The way I solved concurrency is just by forking and using sockets: https://github.com/epiecs/mikodo/blob/6bdcebe9fa7f44ffdedd82...

I use it at work atm does what it's supposed to. I also use Python as well but I wanted to know if it could be done in php :D


I’ve been writing PHP since the 3-4.X days (over 20 years). I’ve written tens of thousands of lines of PHP, in several fairly large-scale server systems.

I’ve never learned to like the language, but have gotten pretty proficient with it. I don’t claim to be a PHP maven, though. I know that my style is fairly “primitive.”

I tend to use it for my backend work. It’s quite performant, has huge infrastructure support, and it’s entirely possible to write safe, high-quality, low-level systems in PHP. I’m a good engineer, and do a decent job; regardless of the tool I use.

C++ is the same way. People have been hating on that language for even longer than they have, PHP. C++ is still used for many major infrastructure projects, though; because it’s the best language for that kind of thing.

If you give a kid a chainsaw with the guard removed (as most arborists do), don’t be surprised, when the screaming starts.



Multi core support is an issue I’ve tried conquering with php, but went down a rabbit hole of running JS on a GPU instead.


> It started clumsy, true, but it became a solid and quite elegant way of doing things.

No. Just no. PHP will not be solid and elegant by evolution. It might have become an excellent tool for the area it's supposed to be used in, but the only way it could ever become elegant is if it had its python2=>python3 sort of moment. They would need to break it to fix it.

I don't think they'll do that, since I think they understand that it doesn't matter at all that the language sucks.


I don’t think breaking python2 did a lot to improve python 3.


That's probably because python2 wasn't that broken to begin with. But fixed character encodings was totally worth it. I think the only mistake they made was related to how long they kept supporting python2 -- but I'm sure there were good reasons for doing that.


I used PHP about two years ago and I was not impressed at all with the improvements. Yes, some of the issues had been fixed, but many of them remained. I cannot see any reason for using it over JS, Python or Ruby.


I've used PHP recently to work on Phabricator, and the whole "yes it sucked but now it's good" narrative did not match my experience at all. Sure it might have added modern features but the core is still rotten.

The alternative would have to be TCL levels of bad to make me choose PHP.


Phabricator is not written in "modern PHP", so your experience is not surprising


Can you link something written in modern PHP?


like the sibling comment said, web apps are written in Symfony/Laravel, but the framework abstractions with web apps might not paint you a clear picture of how the core language has improved. it will give you a good idea what it's like to build applications.

my favorite part of modern PHP is how nice writing libraries is. so it might not be what you're looking for, but I remember being pretty impressed with the code quality of the Amp PHP library recently. the v3 branch is 8.x only and (I believe) is targeting the Fibers feature just introduced in 8.1

https://github.com/amphp/amp/tree/v3

one of the best things to come with PHP are the community standardizations around things like interfaces for HTTP requests, logging, DI containers, and even code style standards. it makes for a very consistent experience when developing (at least when you're in the "new world"), since most newer libraries are all written in a similar style using common interfaces


most of projects based on Laravel/Symfony that are < 5 years old


Phabricator, much like WordPress, kind of lives in its own world and hasn't adopted most aspects of modern PHP. Even as someone who works with PHP and enjoys it, I wouldn't want to use Phabricator.


Wordpress has taken great strides to comply with the latest PHP standards so I'd say that's not quite fair to include it here.


I’d disagree, Wordpress is very difficult to work with when you’re used to modern ways of doing things.


I would say some contributors comply with standards - but the stuff coming from Automattic is scary.

I ended up in a position where I've become responsible for a very high volume WooCommerce/Wordpress store and the things that I've seen in _brand new code_ is mind boggling. Their new, branded, in-house paypal plugin/integration is currently at 1.5/5 rating on the wordpress plugin marketplace [0]. It just doesn't work for various reasons for various people. It's 2021, how do you screw up a payment gateway for wordpress when you _are_ wordpress? But wait, there's more. They already had PayPal integration, built into the core and already included in all WooCommerce installs. So what to do? Force disable the already existing, working-properly, integration and recommend their new plugin to be used. [1] This is hostile.

If your woocommerce webhook delivery fails 3 times in a row, woocommerce will just turn off that webhook/stop delivering them. Silently. No option for any sort of alert to be sent/logged, no way to store/replay the missed webhooks. Just off. This is irresponsible.

Our installation happens to have a lot of details that go into each line item on an order - which, in turn, turns into many rows of meta data. Woocommerce doesn't rely on dedicated tables for orders or related metadata, it's all stuffed into 'posts' and 'post_meta'. It doesn't scale well, terrible really. It's a large enough problem that LiquidWeb starting working on a fix for high volume sites that end up getting crushed with database/performance issues related to these tables/the way the order data is stored. [2][3] This was supposed to merged into the WooCommerce core but that seems to have stalled/fizzled.

I was able to reduce response time on an API request to get_order() from 3-5s to 0.25s by adding an index to the meta table mentioned above. (The query wasn't using any index) This likely isn't the case for the vast majority of installations, or it doesn't matter because the databases are small enough. But things like this indicate to me that the test suite/benchmarking is seriously flawed - or they're not doing things like testing and benchmarking against real-world databases.

Taking a look at various release notes the types of bugs seem to indicate to me there's not a lot of automated testing going on or that things are so convoluted/messy that it's become too complex.

All in all, for the people behind the PHP workhorse (the hero we deserve...) it's all pretty scary. The code quality, quality control and just about everything leaves a poor taste in my mouth. I'm not a big "Team PHP" guy - I like the idea of using the right tool for the job and the scary thing is that Wordpress is the right tool for the job for a lot of people. (WooCommerce, these days, is basically never the right tool)

This is a terrible look for PHP.

Laravel/Symfony on the other hand... take my money. It's a pleasure. LiveWire, tailwind, oh my.

There's still a place for Wordpress - it's not going anywhere... but it's got a long way to go before I'd say it's anywhere near ok. Let alone approaching latest standards (even despite it's supporting older versions of the language). Can we get first-party/first-option composer support? Why, again, is it another company driving Wordpress forward? [4]

[0] https://wordpress.org/support/plugin/woocommerce-paypal-paym...

[1] https://developer.woocommerce.com/2021/07/12/developer-advis...

[2] https://github.com/liquidweb/woocommerce-custom-orders-table

[3] https://stevegrunwell.com/speaking/woosesh-2019/

[4] https://roots.io/


> Woocommerce doesn't rely on dedicated tables for orders or related metadata, it's all stuffed into 'posts' and 'post_meta'.

While I agree this is an antipattern it appeared to be the recommended way when I first got into WP plugin development. IIRC because one cannot guarantee hosting will backup all tables of the DB, and some DBs mix other non-WP stuff.


Ok, going to say you reminded me and I agree now. I was thinking solely of WP core, but if you are to include all of the official plugins and Woocommerce, then yeah I can see the issue.


i just helped my father with a wordpress site, and it sure doesn't use modern php. It runs on modern php, but it does not seem to actually USE it.


PHP at its core is the best part. A whole bunch of optimized and well tested C functions that are typical of backend functionality.

If you can do as little as possible in PHP and rely on the low level functions to stitch together what you need, deserialize and render data in the front end, use front-end templating, then PHP is insanely fast, practical language.

The issues with PHP are usually when people build out giant frameworks in PHP, rather than using PHP as a higher level glue language for the built-in fast C functions.


I've worked on _many_ PHP projects. Unless it's a small single-purpose script, if you tell me it doesn't use one of the standard frameworks, I'm going to assume it's an absolute unholy mess of spaghetti.

Laravel and Symfony are both extremely good, and the only reason people don't use them tends to be out of misplaced arrogance. Unsurprisingly, they end up building their own awful framework, and at some point the project either dies or someone says "Erm, we should put this in Laravel".

There are some people who've built great projects without these frameworks, and there are many projects in these frameworks that are terrible. But in terms of probabilities, you've got a much better chance of a project being well-built if it's in Symfony or Laravel.


I have seen plenty of PHP projects without any frameworks used. Big ones as well. One of these projects is automation for a complete manufacturer factory. Robot controllers, Serial hardware drivers written in PHP, Realtime application with PHP instances running for multiple years. No frameworks used at all. There is more than only webapps.


I’m sceptical that’s a large proportion of PHP projects, and thus comes under my caveat of _some_ projects.


To be honest, I quite like modern PHP. On the other hand, I tend to stay away from it, exactly because of the big prevalence of spaghetti code projects.

There just is so much legacy in the PHP world that separating the wheat from the chaff in itself becomes tedious. And don't understand me wrong: legacy in itself is not a problem. It's the combination of PHP being easy to pick up, lots of outsourcing, people writing procedural code without any notion of code readability, lack of tests, use of global state, etc that usually just make me cry and move on. For me the percentage of worthwhile PHP projects to chase is too low in comparison with many other technologies.

Even though PHP was what got me into programming in the first place, I nowadays thus chose to pick other battles. But every once in a while I still nostalgiously float back in time to my childhood days, enjoying every line of the almighty 4MB imagemagick monstrosity scripts I conspired. And then I'm happy that you nor I have to solve these enigma puzzles.


I started with Ruby, and I imagine my code there was just as bad. But I totally agree about the prevalence of bad PHP projects. My theory is that it’s the dominant language and so there are just more projects, and (like the opposite of survivorship bias) shit codebases are often looking for good developers to save them which is why you see so many of them.


I use C#, Javascript and PHP a lot.

PHP always wins when it comes to deployment and productivity. In my opinion that's the power of PHP.

It's also versatile. I used it for small projects, multi-million € projects, COM-port communication, API communication, prototyping and what not.

The syntax is not great, but to me PHP is this multi-tool that just gets the job done and will run reliable for years.


Fibers "allow blocking and non-blocking implementations to share the same API"

That's an interesting contrast to Python where the need to use "value = await fn()" v.s. "value = fn()" depending on whether or not that function is awaitable causes all kinds of API design complexity, all the way up to the existence of tools like https://github.com/python-trio/unasync which can code-generate the non-async version of a library from the async version.


But if you are writing framework or library that has to deal with both, its:

    result = fn()
    if isawaitable(result):
        result = await result
And turns out isawaitable is not that fast so things like GraphQL libraries that run above logic thousands of times per request get noticeably slow.


I wrote a bit about that pattern last year: https://simonwillison.net/2020/Sep/2/await-me-maybe/

I didn't realize it had a significant performance overhead though, I should look into that.


Ruby has the same design where async is implemented on top of fibers.


> allow blocking and non-blocking implementations to share the same API

Sounds like an excellent way to create weird concurrency heisenbugs.


PHP has a lot of warts, and I mean a lot, but one thing I really like about PHP that virtually no other Web languages offer is that I can just drop code in my Web server's document root, go to that path in my browser, and it runs, without needing to deal with frameworks, boilerplate, compiling, etc.


I see this being echoed in many different ways. For myself, this aspect of PHP is how I was able to get into software development for fun in my younger days. "Change this, save it, refresh and see what happens" was amazing for motivation at one point in time.


As someone who has worked in a lot of languages and now works in PHP, I think that while PHP still has some of the same warts it did in the old days, I am also understanding that given PHP is, for better or worse, a fundamental piece of web infrastructure, and that providing an upgrade path while also ensuring that they don't just break a large chunk of the web is less a matter of "software conservatism" and more a responsibility of the dev team.

And, if we're being honest, the reality is that for that chunk that would break, most of them would either not have a developer on hand to fix it, or would be what I call a "Wordpress cowboy" who has a WP site they set up five years ago that they never update, and the sum total of their development experience is installing various WP plugins until the site vaguely does what they want it to do.

It's hard, because on one hand, if we didn't have things like Wordpress, then PHP would be in a position to undertake more breaking changes that would overall give the language and its libraries the much needed quality improvements. On the other hand, without things like Wordpress, it does become somewhat questionable as to whether PHP would have survived the dark days of PHP4 and the early versions of PHP5.

In saying all that, the work that the dev team have done to add great features and solid performance, alongside the community which has done a lot of good things like PSR's and the PHP League libraries to me, is one of the key things that makes PHP still an attractive environment to work in.


PHP has done pretty big breaking changes in the past, the thing that immediately comes to mind is register_globals (there are probably others, but my PHP experience is mainly from a decade ago).

Originally GET/POST, cookie and environment values automatically became variables. This means page.php?id=123 gave you a variable $id. Along with no variable declarations, this was intuitive and was probably one of the reasons PHP was so popular with beginner developers. Unfortunately it was also the cause of untold numbers of security bugs, because people would write code like:

    if (securityCheck()) { $isAdmin = true; }
 
    //.... 

    if ($isAdmin) {... }
Someone making the request page.php?isAdmin=true would totally bypass the intended check.

So in April 2002, PHP 4.2 [1] was released that disabled this by default -- but so many (badly written) applications relied on this that it was not until March 2012 -- 10 years later! -- that PHP 5.4 [2] finally removed this option entirely.

[1] https://www.php.net/releases/4_2_0.php

[2] https://www.php.net/releases/5_4_0.php


This is relevant: https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundati...

Automattic is now more involved in PHP so hopefully that'll enable some collaboration


I haven't written PHP since the 5.0 release but its amazing to see how it has grown over the years. Seems to have picked up a few nice things and is still enjoying usage even today.


Same, but it looks like they are trying to make Java out of it.


Genuinely curious: who here thinks PHP is a good choice for a new project and also has experience with other languages such as Scala, Kotlin, Python, or JavaScript and their respective web frameworks?


Honestly laravel is one of the best dev experiences. Having used Django, fastapi, and built a custom server with golang, its still my go to for off the shelf fullstack crud apps.


Kotlin is for Android apps. Scala is a Java replacement. Those frameworks are unrelated.

Are you talking about building an Android app?

I've built app in different Javascript frameworks. Angular, Vue, React.

If I was building a website I would use PHP over Python, Golang or Javascript frameworks because what you get out of the box doesn't compare.

Each language does something well. If I was building AI python would be my first choice.


> Kotlin is for Android apps

Welp, guess all my Spring Boot web apps in Kotlin have actually been Android apps in disguise all this time..


Indeed. A lot of the criticism is from people who never used the language (which seems to be true for any language/framework). This is why I'm very cautious when making assumptions about PHP's suitability - I haven't used it in the longest time and, when I did, I used it the same way one would use ASP or JSP - as a template engine that can do some logic before or after rendering a page.


> Kotlin is for Android apps.

I have used Kotlin for web services and, while I prefer Scala or plain Java for that, some of my colleagues prefer the Kotlin syntax and features.

> what you get out of the box doesn't compare.

Would you like to elaborate here? I have used Rails and Django and they get you a lot out of the box.


If it is what you/your team are most confident in and it is suitable to solve the problem (i.e a typical MVC web application), then yes, it is a very sensible choice. If your confidence lies elsewhere, then no, choose that instead. End of the day you’re just solving a problem using code.


True, but that’s self reinforcing. The more you use a hammer, the more confident you become in everything being nails.


And that’s when you become a master of your tools and can wield immense power with them! But in all seriousness, PHP is a good language, and coupled with a modern framework like Laravel, it’s great to use.

I’ve used it since 2002, and have recently got back into it properly after a decade in architecture roles, and it feels very welcoming and love using it. And I _have_ tried the whole JavaScript thing, but simply find it’s ever changing build tools, package managers, etc a pain. Just my opinion though.


> And that’s when you become a master of your tools and can wield immense power with them!

That still doesn't change the fact that, when you master hammers, you still have no idea of how to correctly use a screw.

Every language comes with some blind spots. Learning different languages is often enlightening because it forces one to see the solution space with a different kind of glasses.


I am working with Kotlin for the last 2 years and have js / typescript / php experience. PHP is still a great choice to start new projects in for many web applications.


I started out with PHP, if I'm building an actual app though, Ruby on Rails is still my go to.


PHP is still used today because it needed good docs. Who's laughing now?


Question: does class_exists still return TRUE when given the QCN to an enum?

Because it's not possible to instantiate an enum, if one appears in the constructor of a class it'll break auto-wiring. I've written my own IoC containers and one fundamental assumption in them is that when class_exists returns true, it is what it says on the tin. Using a specialized factory would still be possible. I wonder if other containers would break on seeing enums as well, but I hope they fixed this because it's not mentioned in the breaking changes. The documentation for class_exists doesn't mention enum.


Internally, Enums inherit a lot from classes.

I wrote an indepth article about this: https://php.watch/versions/8.1/enums#enum-exists

There is an `enum_exists` function that only returns true for Enums. It's fairly unintuitive to combine class_exists with enum_exists to filter out Enums, I agree.


Isn’t that the same behavior/pattern for traits though? At least it’s consistent.


That was easy to test, and no. class_exists returns false for traits and they can't be used as parameter types. It throws a TypeError when I do that (even though the instance I pass uses the trait).


There's already kinds of classes that can't be instantiated, why would this specifically be a breaking change?


If by "kinds" you mean abstract classes, yeah. I just checked, there's no special handling for those since requesting them from the container makes no sense. I suppose a constructor could depend on an abstract type and expect an actual implementation, though. I haven't thought about that use case actually, but it's possible to configure a substitute for this case. Other IoC containers may handle this one better, since you may want to have different implementations depending on the current scope.

If you mean classes with private constructors, those are technically illegal. According to the PHP manual, constructors must be declared public. The fact that private constructors work at all should be considered an implementation detail.

Breakage occurs when something is said to be a class, yet isn't a class but still appears in the parameter list of a constructor. The container would instantiate a ReflectionClass of whatever is being requested and pass that around. At some point it'll call newInstanceArgs either with configuration-provided arguments or with auto-wired dependencies. The first case could still work, but foregoes auto-wiring.


I can't think of any situation you'd put an enum in the container though. Maybe I'm just too tired to think of a situation where that would be helpful. Can you think of one?


* A database abstraction layer that's instantiated with a certain access level

* A hydrator/extractor that changes the type of the value it handles

* A task or job that has a certain priority to it


Fibers!!! Who wants to bet we are a few releases away from async/await syntax now. Giving credit where it’s due Microsoft with C# pioneered the syntax and every classic (including a few modern) language has adopted the syntax.

I believe we are a few steps away from a fully builtin production ready server and db connection support.


I think the hope here is that you don't need async/await syntax. The fiber implementation is supposed to abstract over both sync and async implementations.


What usecase would async/await have in day to day PHP use?

I can see it being a boon for the esoteric stuff like ReactPHP, but for a regular MVC site it just seems like a unnecessary complication?

In JS land, it atleast makes interacting with the event loop and NOT blocking the UI thread easier.


Async/await isn’t something to hope for. It’s a terrible pattern languages should work hard to avoid.


Care to explain why?


"Async-await is nice, which is why we’re adding it to Dart. It makes it a lot easier to write asynchronous code. You know a “but” is coming. It is. But… you still have divided the world in two. Those async functions are easier to write, but they’re still async functions.

"You’ve still got two colors. Async-await solves annoying rule #4: they make red functions not much worse to call than blue ones. But all of the other rules are still there: ..."

You can continue the story at:

https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...


Judging from the comments, it looks that many negations stem from the "old PHP". I've been developing with PHP since late 90s. Oh, boy, I've created a lot of bad code during all those years. However, when doing new year's retro, there has not been a single time I would be able to say that PHP has not evolved. As well as my code.

Modern PHP might not have all the shiny features other high profile languages have, but it's getting there. It's slower than many would like because of much debt and legacy. But it'll get there.

Also, you can write shitty code in any language. I would bet that, if back then python was as easy to deploy, as PHP, we'd now be fighting about that the same way as we are about PHP.


Still holding the web. Happy to see it is continually evolving.


What's your estimate for PHP's long-term viability?

I'm asking, because it was the hobbyists and kids who got started in PHP mucking around in their everyday white-label cPanel/Plesk-based web-hosting accounts in the very early 2000s that really gave PHP the mindshare of enthusiastic users and thus its staying power. But it's 2021 now: all the kids are getting started with NodeJS for server-side web-applications, not PHP.

With the decline of traditional web-hosting as something that people have and might experiment with (replaced at the low-end by Wix and Squarespace, and major "Cloud" providers at the high-end), what opportunities does PHP have to attract new eyeballs?

Years ago self-hosted WordPress and phpBB installs would have been been a good gateway, but both of those are going out of fashion owing to the substantial maintenance burden that comes with self-hosting. Everyone I know that used to self-host WordPress (former clients, friends, local small businesses, etc) have all given-up and switched to WordPress.com's managed-hosting model or gone with the aforementioned Wix and Squarespace.

Ultimately PHP as-we-know-it will last as long as Zend (UPDATE: it's now owned by Perforce?!? wow...) can secure sales/support funding, which is predicated on their continued penetration of major enterprise customers - or indirectly through the continued popularity of WordPress and the like, even if it's hardly ever self-hosted anymore.

Personally, my money's on maybe 5-10 years' continued credibility, and then another 15 years of slow decline into irrelevance.


80% of the web is powered by PHP and 40% of that is WordPress which has continued to grow. 64% of CMS websites are WordPress. There’s what gets upvotes, and then there’s what is widely used, supported, easy to hire devs for and practical as hell. PHP, unlike Perl which I used to contribute to, is here to stay.


There's also Moodle which got extremely more important because of the pandemic. Nothing that ever becomes as popular as PHP and continues evolving for 2+ decades disappears quickly. I think 10+15 years... I don't know... I think it will last longer. COBOL and FORTRAN are still alive, there was more heavy money into both but there are more minds in PHP.


Ah, yes - Moodle.

My 6th Form experimented with Moodle when I was a student there - that was a loooooong time ago (2004? 2006?). I remember the staff weren't happy that Moodle allowed students to set their own avatars because too many kids figured out you could use animated GIFs as avatars, probably copied from eBaums or deviantArt; while others uploaded shock-images or just controversial content because I guess that's just funny to a bunch of 16yos.

The school ditched the experiment after a few months because Moodle simply wasn't delivering any real value: the teachers didn't want to have to type-up their handwritten lesson-plans and manually scan-in their existing non-digitized content, and those that did already have digitized content (those smug 6th Form computer science teachers, naturally) didn't want to have to "refactor" (I guess that's the right word?) their content to fit into Moodle's way-of-doing-things.

I think as the experiment came to an end we were only using it for ungraded quiz-taking - we weren't even using it for submitting homework (teachers still preferred e-mail for that: the 6th Form already had its own on-prem MS Exchange set-up that everyone used - and we could e-mail staff from our personal e-mail accounts too, which was nice - I know a lot of schools kept closed, on-prem-only, not-internet-facing e-mail systems to avoid spam - this was back when spam filters were awful and spam itself regularly included actual porn and other very-inappropriate-for-schools content, so I can understand why those other schools did).

----------

I haven't laid-eyes Moodle ever since then - every few years someone will mention it but I've never had a chance to speak to anyone who actually uses it to find out if it's actually any better than it was 15 years ago - and how it's changed at all. Can you fill me in?

And still far better than Blackboard?


My university is currently using moodle, as far as I can see it's working fine.

It's replacing and older custom application, built on liferay (or alfresco? can't really remember).

However, it's doing okay. And it's scaling fairly big (~40-45k users).


We used moodle in uni cca 10 years ago and it worked fine. Did online quizzes/exams, homework submission, forums, lecture notes, ...


PHP bigwigs just announced the PHP Foundation to secure PHP’s future.

Announcement

https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundati...

PHP Foundation

https://opencollective.com/phpfoundation

Accepts donations to help the development of PHP.


I don't think that's a good sign.

The community's complaints with PHP are far more concerned with technical matters relating to the language, runtime and libraries than how Zend etc have handled the usual issues in politics and project governorship. I don't think PHP has ever had a brouhaha anything like what happens in Java's JCP or the Oracle sale. Other platforms (like .NET) have their own foundations but they aren't taking seriously by the community because we all know the commercial companies that back the tooling are the ones that really matter.

...so what's the real reason for PHP suddenly switching to a Foundation-supported model? And why couldn't they entrust PHP with an existing and well-regarded foundation like Apache or FSF?


If you read the announcements it explains why they are doing it.

PHP is a community driven project, comparing that with C# or Java is a bit unfair because they are backed by companies worth billions.

What you describe about Zend I think that is more the old days before PHP 7. I don’t have the full picture of this but my understanding is that because of the failure of PHP 6 (never released), another group of developers from the community started to work with PHP 7 and I don’t think neither of them was from Zend.

Today there is an open RFC process and anyone can submit an RFC and then the core teams votes on it. If you contribute to PHP you can become a member of the core team.

https://wiki.php.net/rfc

If you want to be part of the discussion you can join the internals mailing list. Here you can read it without joining.

https://externals.io/

If someone is unhappy with direction of PHP my advice to them is to start contributing, bug fix, write documentation, translate, write RFCs, implement functionality, code review etc. Why? because PHP today is a community driven project.


Personally I am delighted that the low end has been replaced by fully managed platforms. The average small business does not have the ability to run a website. Actually building the site and getting it online is the cheapest and easiest part but its the only part these places budget for. Then the inevitable problems come when the site is 2 years old, falling apart, getting hacked, etc. Allowing these low end customers to just have something that is set and forget truly is an improvement.


My impression is that the market for PHP development is almost a separate ecosystem from other languages.


Reading some comments here and it does confuse me

Promises, async and await in javascript, coroutines and threads in kotlin, fibers in some language runtime (including this php 8.1 [0]), single process (nodejs), multi-process(php-fpm worker), single-thread, multi-thread, goroutines in go, multi-core coroutines

Googling the definitions and x vs y situation helps a little, the main confusion to me is why some people want this xyz feature in a language runtime and not the other, the pros and cons are seriously so confusing

I have probably used several, like promises, async, await, like others said async would be implement on fibers [1] (is php 8.1 implementation same as V8,spidermonkey,javascriptcore? or any other language runtime). And I have tried to understand kotlin coroutines as well

modern times to run php, people would use php-fpm with nginx, it is running multiple worker (single) process, so why would anyone [2], [3] wants multi-core coroutines in it? What does it even mean?

Writing this out ease my mind a bit yea, need to be able to communicate the confusion instead of just saying "programming is difficult"

[0]: https://news.ycombinator.com/item?id=29343773

[1]: https://news.ycombinator.com/item?id=29344427

[2]: https://news.ycombinator.com/item?id=29344704

[3]: https://news.ycombinator.com/item?id=29345986


> modern times to run php, people would use php-fpm with nginx, it is running multiple worker (single) process, so why would anyone [2], [3] wants multi-core coroutines in it? What does it even mean?

Not everyone does. There's also https://reactphp.org (which is an event loop runtime, similar to Node), and https://amphp.org (also event loops), and Swoole https://github.com/swoole/swoole-src (coroutine runtime, similar to Go).

Fibers are basically an API that event-loop runtime libs can use so that userland code doesn't need to use promises or generators to run non-blocking operations. Fibers are not useful for php-fpm or swoole users.


Not all PHP is behind a web server. Think long running workers, queue consumers, daemons etc.


I haven't written PHP in years but I get the feeling from this release that they are taking inspiration from TypeScript and JavaScript.


They take inspiration from everything! I think that's one of the most interesting aspects of PHP design since version 5.0 is that they sort of unpretentiously take the good concept and syntax ideas from any language that has them.


Definitely some JS influence plus a little Swift and Java. PHP seems to be evolving faster than it has in years


It's actually becoming a problem keeping pace with PHP major updates


PHP isn't Linux with its strict "never break userspace" dogma - but for real, a PHP version upgrade should not be that bad to follow.


I think 8.0 had a bunch of relatively major/annoying breaking changes, but that's the first time since the 5.x era.


They did give deprecation warnings in various version 7 releases, so they didn't come out of nowhere. (Not that you said they did, but for the purpose of other readers.)


That's a funny thing to say, considering those took inspiration from other languages.


they all lifted stuff from ml/scheme in the 80s


Probably FB’s Hack and similar efforts were influences first, since they predate the rise of TS.

On the other hand, though, PHP’s always tended to be a borrowing language that accumulates features from elsewhere, so there probably is some TS influence.


I sometimes wish I'd never learnt C#. I love property accessors, as I consider properties to be a part of public API and in PHP, there's no nice way around it other than the boilerplate getters and setters.

Also I hope we'll get generics at some point. I know there are some issues with their implementation, but even non-runtime enforced generics would be better then relying on a docBlock annotation.

Enums are neat, though.


You technically can use getters and setters in PHP, albeit with a noteworthy bit of extra implementation associated with wiring up __get() and __set().


Sure you can, the question is if you should. And you can't declare properties on interfaces (well, you can use @property annotation, but that's just... an annotation).


What is this?

  class User 
  {
    /**
     * @Assert\All({
     *     @Assert\NotNull,
     *     @Assert\Length(min=5)
     * })
     */
    public string $name = '';
  }
  PHP 8.1
  class User 
  {
    #[\Assert\All(
        new \Assert\NotNull,
        new \Assert\Length(min: 6))
    ]
    public string $name = '';
  }


An annotation syntax no outside of doc strings. Something PHP desperately needed.

Very similar to Java annotations.


These are attributes which add metadata that can be programatically acessed by applications and tooling.

That piece of code is about data validation.

See more at https://www.php.net/manual/en/language.attributes.overview.p...


Just going to link to this from earlier today.

https://front-line-php.com/cheat-sheet

It’s covered under “Attributes”.


Doctrine ORM uses Annotations to label SQL data, it's a pretty good example of Annotations in action: https://www.doctrine-project.org/projects/doctrine-orm/en/2....


Excuse my intrigue. Is this topic biased to language design or experience using php?


Say what you want about PHP, but here we are decades later. I'm still using it, it still works, and it's still getting updated and improved.


Say what you will about JavaScript...

I use it constantly not because it's well-designed but because TINA (there is no alternative).

[] == ![]; // true. Go ahead. Run it in your console...


...so it basically is `0 == ![]`, in other words, `[].length` which is `0`, thus becomes `0 == false` which returns `true` with loose comparison?


Yep.

Because an array is an object which has a 'truthy' value '![]' evaluates as 'false'.

Simplifies to a statement similar to 'false == false'.

A little useless arcana for those interested.

Well, not so useless if your expecting '!someEmptyArray' to evaluate to 'true'. Use '!someEmptyArray.length' instead.


What is this argument for, or against?


PHP devs make less and have to learn JS anyways.


Who is still using PHP anno 2021?


Rosaly.com (shameless plug) , the team of developer is 32 years old average, though we all come from different background and all used python/go/java/rust in some of our previous jobs or on our own opensource projects, we just want to get shit done.

  * it has its quirks but we know them and each newer version fix more of them.
  * its damn fast (more than python or ruby)
  * its type system is better than python (trait/interface , union type <3 , and now intersection type ! ) 
  * symfony/laravel have evolved over the last 10 years, most of the things you knew 10 years ago are still true now
and as a result it tends to attract people with the same mentality, my experience with recruiting php developer is that you have a much clearer clivage of "wordpress website maintainer" and "people who want to get shit done"

you will not find for example "genius developer, that write code faster than you think, who writes all his project in rust but is now thinking to switch to haskell and will leave your company as soon as it find a company that use it"


I.personally avoid "Shiny Language" developers.


If you ignore things like Wordpress, my guess is that today it's often used by organizations whose flagship product was originally written more than a decade ago, back when PHP was the go-to language for web development (see: Facebook, Wikipedia, Tumblr etc.) and now that there's an ecosystem around this flagship product, new projects/services may as well be started in PHP, because that's what everyone is comfortable/familiar with. Otherwise, it looks like PHP isn't a very popular choice nowadays for new projects, especially if it's a new company.

Take our company for example, our flagship web product was developed more than a decade ago, and, well, today we still use PHP, because rewriting everything in a different language is a gargantuan task. It's not only about the language itself, but also about all the tooling/best practices etc. around it, which you have to replace, and it's costly. We do gradually modernize our code to remove all the PHP5-era warts, and it's much easier to accomplish than switch to a different language entirely. Modern PHP7+ with Symfony is very pleasant to work with, and in my opinion, from the productivity standpoint, there's really no reason to switch to anything else. Also, PHP7+ seems to be faster than Python/Ruby in raw interpreter speed. However, we realized that we can't scale further if we stay with our PHP/Symfony monolith for everything because of Symfony's considerable startup overhead, so we now try to write new services in Go (request processing is usually 10 times faster for our loads), and seems like the combo PHP+Go is very popular among PHP developers in general.

So, I'd say, PHP isn't "dead" and is still widely used in 2021, however, in my opinion, its usage is indeed dwindling, because there seems to be a trend even in our own PHP community to gradually supplement/replace/augment parts of our projects with services written in Go, and PHP is more and more frequently equaled to "legacy"/"monolith".


In August I did database related consulting for a client which is building a large CRUD'ish application in Laravel. I was intrigued with their decision and they said the tech stack was chosen based on speed of iteration and developer availability.


Everyone.



This post is 5 years old. Slack migrated from PHP to Hack. By now you can not run PHP code in Hack anymore.


They've got an article about that too for those interested. https://slack.engineering/hacklang-at-slack-a-better-php/


Considering just WordPress powers something like 40% of the whole www, I'd say quite a few people!


But how much of that is just fake SEO websites? Virtually all the fake sites use Wordpress.


I'd say there's a difference between choosing an established product like WordPress or MediaWiki and looking at a greenfield project and choosing PHP.


Considering how popular Drupal is with large government applications, PHP is going to be around a long time.

PHP has become better and better over the years!


I use PHP for my personal sites.


Me.


all my projects using PHP ¯\_(ツ)_/¯




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: