r/PHP • • Dec 29 '24

What is PHP lacking in comparison to Nodejs / Golang / Java?

[deleted] — view deleted post

88 Upvotes

213 comments sorted by

View all comments

5

u/Miserable_Ad7246 Dec 29 '24
  1. Async - solvable with swoole
  2. Proper compiler to catch issues. Compilation is such a cheap and quick thing, not having it is a pain.
  3. Generics
  4. Proper strict typing
  5. PHP still runs on a lot of indirection, which makes it unsuitable for a lower latency scenarios
  6. Persistent memory - also solvable
  7. Ecosystem is bad. Where are a lot of drivers for example which either run out of process (slow) or do not have connection pooling (uter shit).

All in all PHP lacks a lot of things for high perf, low'ish latency web. For small sites and sites where perf and latency are not important php is fine.

Please do not go - but facebook, but 90% of web and so on route.

4

u/felipefrancisco Dec 29 '24

re: compilation, the best alternative (and covers everything in this aspect, imo) is phpstan and psalm, the static analysis does a lot of the checks that a compiler would

2

u/Miserable_Ad7246 Dec 29 '24

It does, but it also does not. Its a step behind. Also PHP allows you to write code which is can not be statically checked no matter that. Under normal circumstances you should not do it ofc.

Honestly a similar issues can happen with complied languages if reflection is used, its just that in PHP "normal" code can lead to this.

But sure it can be almost as good.

1

u/Useful_Difficulty115 Dec 29 '24

Relying on external tool where the language itself should do the job is not a good DX

Look at Elm compiler messages, Rust, Gleam, etc. Every modern language offers this natively.

2

u/felipefrancisco Dec 29 '24

Precisely why I said it’s an alternative, I do agree something similar should be built-in

1

u/Useful_Difficulty115 Dec 29 '24

My bad, I misread your comment !

5

u/Holonist Dec 29 '24

What makes it worse is that even ignoring everything you mentioned, PHP is also less ergonomic and requires typing much more code than modern alternatives like Scala, Kotlin, TypeScript or even Java.

People think a proper static type system makes it harder to code, when it's really the opposite.
And yeah there is a reason why FB had to create their own entire new language called Hack, with static types among other things to cope with the absolute tech debt they incurred on themselves.

3

u/Miserable_Ad7246 Dec 29 '24

Well to PHPs credit they are moving forward. Enums got added in 2024 (!), where are serious talks about generics, lambda functions are less cumbersome. Give it 5 years and it will be fine. But even after that some core issues will remain, like ZValues. No matter how you dance this will always going to handicap PHP for more serious bespoke scenarios.

Also if you think about say Java or C# or Go, you can write everything in your company using that one language (except web UI, because javascript), with PHP you will eventually be forced to adopt another language for ETLs or to do something PHP was never meant to do.

Long running async php stuff remidies that issue some that. But it creates another one. Namely drivers. Somone who writes some driver related to IO is kind of forced to assume non long running environment. So you run into issues, with having async, but not having drivers.

99% people here will start talking about - but mariadb works and what not. Where are plenty of other dbs which just do not have good drivers for PHP, in some cases do not have official drivers at all, because they assume that PHP will not fit the scenario anyways.

Those type of issues can not be solved by PHP foundation alone, whole community has to switch their ways, and PHP community (not everyone, but most in my experience) is known to be stubborn and ignorant repeating same mantras again and again. Once people here realizes that php-fpm must die for php to advance it will have a really good chance to be more than wordpress or a best way to make e-shops.

5

u/rsmike Dec 29 '24

Enums got added in 2024 (!)

Enums got added in 2021, Mr. Expert

-3

u/Miserable_Ad7246 Dec 29 '24

Potato potato. In my company only now php devs started using them, it took a bit to update projects.

0

u/[deleted] Dec 29 '24

[deleted] — view deleted comment

2

u/Miserable_Ad7246 Dec 29 '24

This is true, but due to dynamic nature of php that unboxing and working with pure values is more complicated. Like copy on write. 

And yes generics would help a lot, will be interesting to read about internals once its implemented.

1

u/obstreperous_troll Dec 29 '24

Most useful unboxed values (save perhaps packed arrays) are likely going to be allocated on the stack, so no refcounts needed and no COW happening. Some objects could potentially live on the stack too, but practically speaking PHP would probably need a new Record type with value semantics to achieve it. That's a topic that comes up every now and then but it's never gotten to the RFC stage afaik.

1

u/Miserable_Ad7246 Dec 29 '24

This is one of those areas I know little about. Do you have any sources to read about such as unboxings?

When I think about key issues of zvalues for me its all about arrays. You want that in heap and have values raw to leverage cachelines.

2

u/okawei Dec 29 '24

Proper strict typing

Technically you can enforce this on your project if you set strict_types = 1

2) Proper compiler to catch issues. Compilation is such a cheap and quick thing, not having it is a pain.

PHP is not a compiled language so I don't even know what you mean here. Wouldn't a standard linting library work for this?

Agree with everything else though.

3

u/Miserable_Ad7246 Dec 29 '24

>Technically you can enforce this on your project if you set strict_types = 1
Can I write that function returns string[] without extra lines of code and hints? I can not. Until when its not strict typing.

>PHP is not a compiled language so I don't even know what you mean here.
Its like saying I'm not in shape and its fine. Which is true, but does not make stuff better from the perspective of a fit person.

Advantages of "scripted language" are no longer relevant in modern web development (or at least benefits outweigh the cons). PHP could be compiled and would be better because of it. A lot of people will going to argue about this, but they also have not worked with modern compiled stack.

I for example deploy C# app faster to production than PHP people, because my tests, lint, coverage and other CI/CD things run faster on same agent. It takes me about 1 minute less. PHP app does roughly the same steps and is roughly the same complexity, but has few hundred more tests (which in C# would add ~10 seconds to runtime of pipeline).

Not a difference that matters (it does not), but still its ironical.