Most active commenters
  • phplovesong(5)
  • deaddodo(5)
  • pjmlp(4)
  • johnisgood(3)
  • danaris(3)

←back to thread

PHP 8.5

(stitcher.io)
202 points brentroose | 47 comments | | HN request time: 0.833s | source | bottom
1. darkamaul ◴[] No.45990664[source]
PHP's evolution since PHP 5 has been substantial, and I think this is a real problem. As someone who learned the language years ago, the pace of change (generics, attributes, match expressions, typed properties) makes modern codebases genuinely difficult to follow.

I suspect this affects many developers who cut their teeth on PHP but haven't kept up. The language has become a different beast, which is a strength for the community but a barrier to re-entry.

replies(12): >>45990804 #>>45990834 #>>45990835 #>>45990949 #>>45991400 #>>45992500 #>>45992620 #>>45992776 #>>45993443 #>>45993687 #>>45995052 #>>45995108 #
2. gramakri2 ◴[] No.45990804[source]
IMO, newer PHP is still very readable. I programmed with C++ for a decade, but I can safely say that I cannot understand a modern C++ code base anymore.
replies(1): >>45993606 #
3. phplovesong ◴[] No.45990834[source]
PHP has no generics? I read somewhere that is was "too hard" to get right in PHP land, mostly because of how primitive the typesystem is.
replies(3): >>45991417 #>>45991444 #>>45992643 #
4. johnisgood ◴[] No.45990835[source]
I think PHP is way better now than it used to be. Learn PHP 8 and you are good to go.
replies(1): >>45993127 #
5. pjmlp ◴[] No.45990949[source]
This is true for most languages though, compare C# 14 with C# 1.0, Java 25 with Java 1.0, C 23 (plus common compiler extensions) with K&R C,....
replies(2): >>45991209 #>>45991349 #
6. ffsm8 ◴[] No.45991209[source]
I think he's thinking more along the lines of PHP 5-8.5

That version 1-latest is understandingly highly different, but these are all decades old languages, which barely changed for some time, but are now all introducing new syntax.

Which I think makes sense, but it's obviously going to leave 9-5 devs behind that don't particularly care for coding and want to invest as little time as possible into their language knowledge.

replies(1): >>45991499 #
7. deaddodo ◴[] No.45991349[source]
C hasn’t changed all that much, and someone who coded in C99 would take about 30mins to catch up to a modern C23 codebase’s changes. Famously so, as conservatism to change is the main friction in the community for about two decades now.

If you pull out examples of the earliest C, sure, it looks weird. But that C was already obsolete in 1989. Since then, it’s had a minor iteration (e.g. five-eight additions/modifications) every decade-ish (99, 11, 17, 23). Has it changed? Sure. Can it be compared to the iteration and speed of things like C#, Java, C++, etc? No way.

replies(4): >>45991842 #>>45992272 #>>45992334 #>>45993480 #
8. ivolimmen ◴[] No.45991400[source]
Most likely this can be said about a lot of languages, most languages are being maintained and improved. I am an hired expert in Java and I needed to explain some new languages features to some colleagues that have been introduced recently, I only mention them if they actually improve readability though. I think PHP might be slightly different than other languages as a huge amount of people use this to create their first website as a hobby.
9. dreadnip ◴[] No.45991417[source]
If you're interested about generics in PHP, you can read this blog post by the PHP foundation: https://thephp.foundation/blog/2024/08/19/state-of-generics-... or this PR by Nikita: https://github.com/PHPGenerics/php-generics-rfc/issues/45.

TLDR: The PHP compiler isn't really suited for the job, it would introduce a lot of complexity to an already complex codebase and the memory/performance hit would be substantial.

replies(1): >>45991973 #
10. deaddodo ◴[] No.45991444[source]
It has nothing to do with being “too hard”, and everything to do with not making sense to the type system. PHP is weakly-typed and heavily reflection-based (so everything is aware of it’s and each other’s type at all times).

Adding generics to PHP would make CS fundamentalists somewhat happy, but do nothing to change the fundamental design of PHP nor offer any of the traditional benefits that generics offer to strongly-typed and compiled languages. And would be a massive headache to implement, while bulking an already heavy VM implementation.

replies(1): >>45991948 #
11. rytis ◴[] No.45991499{3}[source]
And what exactly 9-5 has to do with caring for coding or time investment in language learning?
replies(1): >>45992238 #
12. pjmlp ◴[] No.45991842{3}[source]
I am quite sure many people would fail Pub Quizzes related to C, when taking into account the whole language alongside compiler extensions, regardless of the compiler.
replies(1): >>45992088 #
13. phplovesong ◴[] No.45991948{3}[source]
> And would be a massive headache to implement

Exactly. The type system was never built for anything even slightly more complex. Its basically annotations for primitive types and classes. PHP has always had an weak type system, so adding generics will most likely never happen.

> Adding generics to PHP would make CS fundamentalists somewhat happy

PHP has really only one collection datatype (the infamous array), so having generics would be tremendously useful, as an example you cant return an typed array from a function, witch is just really bad.

For an counter example, Python managed to do this, while also being a dynamic language, although having a stronger typing than PHP.

replies(4): >>45992880 #>>45992994 #>>45993750 #>>45994285 #
14. phplovesong ◴[] No.45991973{3}[source]
Yup, this was pretty much what i recalled. The typesystem, while being incredibly "unintelligent", somehow still is so complex that generics are not going to happen.
15. deaddodo ◴[] No.45992088{4}[source]
To learn all of the common GCC and MSVC extensions would make up a fraction of the language features of C# or Java. You’re really overstating the complexity to make some invalid point.

“Actually, one of the most notoriously conservative and simple (in feature set) languages is really super complex and has evolved a ton because it has _Generic and varargs now, and __packed__ exists as a compiler feature.”

And to further double down, that minor evolution is over 36 years (arguably a decade longer, but I’m being generous with your argument). Not the 12-16 years (depending which 5 point release you wanna start with) that PHP has morphed into an entirely different language.

replies(2): >>45992707 #>>45992845 #
16. monooso ◴[] No.45992238{4}[source]
Not GP, but I assume the suggestion is that it's difficult to stay abreast of new developments within the constraints of a typical work day. Especially if your job utilises older technologies, as most do.
17. ◴[] No.45992272{3}[source]
18. rini17 ◴[] No.45992334{3}[source]
You can learn everything about undefined behavior in 30mins?
replies(1): >>45992744 #
19. woodrowbarlow ◴[] No.45992500[source]
but would you even be considering re-entry if it hadn't improved dramatically?
20. jm4 ◴[] No.45992620[source]
To be fair, that’s true of many languages and programming domains. The web, in particular, is one where you have to keep pace or end up out of the field.

Java and C# are a couple other popular languages where the same is also true.

21. senfiaj ◴[] No.45992643[source]
You are probably talking about this: https://stitcher.io/blog/generics-in-php-3 . If I remember correctly, the author claims it will either cause runtime overhead or extreme memory overhead. The best solution is to introduce a typed superset of PHP like TypeScript was done for JavaScript.
22. johnisgood ◴[] No.45992707{5}[source]
Yeah, it does not take a long time to learn GCC / Clang extensions, IMO. Have an LLM give you a list of these with examples, really. :P
23. deaddodo ◴[] No.45992744{4}[source]
It's moot to the aforementioned point. Undefined behavior wasn't introduced as a new language "feature" between C89 and C23; it's existed the whole time. We're talking about specification deltas, not the entire corpus.

But, if you want an answer to your question:

You can learn to avoid undefined behavior in about 30 seconds.

If you're purposefully fiddling with undefined behavior, it's because (ideally) you're A) an advanced developer and you know exactly what you're trying to achieve (and inspecting the generated code) and/or B) you're using a specific compiler and don't plan on porting your code elsewhere.

24. segmondy ◴[] No.45992776[source]
It's a real problem with almost all software today, nothing ever gets done. they just keep piling unto it no matter how great it was. the idea of simplicity as a goal and feature is lost on this generation.
replies(1): >>45993475 #
25. pjmlp ◴[] No.45992845{5}[source]
A pub quizz would consider more than GCC and MSVC, and still I would bet many would fail if talking only about those two.

And I would double down on my bet regarding ISO C related questions, as I have met a few folks that contrary to myself as language nerd, hardly know what is written there or have even opened the PDF drafts at least once in their life.

replies(1): >>45992911 #
26. ◴[] No.45992880{4}[source]
27. deaddodo ◴[] No.45992911{6}[source]
A pub quiz isn't a developer, a codebase, nor an objective measure.

If you want to use your own head canon benchmarks to prove your obviously off-base point and tell yourself you're "correct", go for it.

replies(1): >>45993872 #
28. duckerude ◴[] No.45992994{4}[source]
Python managed to do this by not actually checking the types at runtime. If you declare a list[int] return type but you return a list[string] then nothing happens, you're expected to prevent that by running an offline typechecker.

PHP chose to check types at runtime. To check that a value is really an array<int> the runtime could have to loop through the entire array. All the types PHP currently implements are simple and cheap to check. For more elaborate cases you need an offline checker like PHPstan and comment-based type annotations. (PHPstan catches 99% of issues before the runtime gets to it so for my own code I'd prefer the Python approach with its cleaner syntax.)

The runtime checking seems the key difference, not so much the historical strength of the type system. Python's language implementation does very little typechecking itself and PHP's third-party offline typecheckers are respectably advanced.

replies(1): >>45993947 #
29. erickf1 ◴[] No.45993127[source]
Until two years later the same thing is said about PHP 9, 10, 11. Constant change is not good.
replies(1): >>45993354 #
30. johnisgood ◴[] No.45993354{3}[source]
People still complain about PHP saying how it is not secure at all, how shitty of a language it is, and so on, because they are stuck at PHP 5. Everyone should just start from PHP 8.

I have no clue what the future brings for PHP, but PHP 8 is definitely a good start, and we should put PHP 5 to rest.

PHP 10 might not be that different from PHP 8 for all I know.

We do not know if there will be "constant change". Out of curiosity, what programming language do you use that you also love?

FWIW, if by "constant change" you mean improvements or bug fixes, then I do not see why we should not have those. I do not even mind breaking backwards compatibility if the reasons for breaking justifies it, but it has to be a really good reason.

31. tehbeard ◴[] No.45993443[source]
You can still write php 5-esque slop and have it run... mostly (some particulars like the half dozen ways of interpolating a variable into a string have been paired down, some extensions left in the dustbin, but the fundamental "shit out a script and run it" capability still remains doable).

non of the "modern" things are particularly taxing to teach someone with more than two braincells. If they don't understand them then they haven't kept up with ANY programming trends in the past decade and are best placed infront of the TV with an iPad than left to mess with the possible critical infrastructure of a business.

32. tim333 ◴[] No.45993475[source]
Simplicity may often get ignored but I think it's been a big reason for Python's success which has gone from about #10 on the TIOBE language list to #1 since when I started learning it, which was probably around when the XKCD "everything is so simple" cartoon came out. (https://xkcd.com/353/)
replies(2): >>45993579 #>>45993774 #
33. array_key_first ◴[] No.45993480{3}[source]
C, as a language, is very simple. Which leads to horribly complex and monsterous code, especially in large projects. The language makes even simple paradigms impossible to represent, forcing you, instead, to just remember what to do and then do that every time, forever.
34. segmondy ◴[] No.45993579{3}[source]
I have been programming in python since the 90's too. The success IMO is still that it retains the simplicity and CFFI. Moving up TIOBE is more of CFFI and the ecosystem.
35. idoubtit ◴[] No.45993606[source]
Are the new features really readable? I have no idea what this code from the OP is meant for:

    #[SkipDiscovery(static function (Container $container): bool {
        return ! $container->get(Application::class) instanceof ConsoleApplication;
    })]
    final class BlogPostEventHandlers
    { /* … */ }
As a side note, even PHP's official wiki cannot highlight correctly the multiline attributes behind a "#". See https://wiki.php.net/rfc/closures_in_const_expr
replies(1): >>45993865 #
36. danaris ◴[] No.45993687[source]
I dunno; I started with PHP 5 (actually, I think I started in late PHP 4), and I've only been happy with the changes as it's evolved.

The only one that's caused me any significant stress is the deprecation of the old `mysql` DB interface; I had to refactor a whole bunch of code for that, since I'm maintaining a codebase that's been in continuous use & development since 2001.

The additions to PHP since 5 add more things you can do, but they don't really change the simple things you can do to first learn PHP. You can still just create a .php file and start interspersing HTML and <?php script tags with basic operations.

37. danaris ◴[] No.45993750{4}[source]
> you cant return an typed array from a function, witch is just really bad.

Why is it bad?

In particular, why is it worse than not being able to declare a typed array in your current scope? (I understand the basic argument in favor of typed arrays, but I also understand why PHP would choose not to go that route; I'm not sure I see how it's worse to not be able to return one from a function, given that they don't exist elsewhere.)

replies(1): >>45993977 #
38. okeuro49 ◴[] No.45993774{3}[source]
Doubtful it is anything to do with simplicity.

Python's success is explained by it being the language of choice for AI.

39. TimWolla ◴[] No.45993865{3}[source]
The examples in TFA are terrible and I don't get why it was necessary to jump the gun by submitting that article instead of actually waiting for the release and the official release page with more carefully designed examples.

Given that the cat effectively is out of the bag, does the example on the release page (sneak preview) make more sense to you: https://www.php.net/releases/8.5/en.php#closures-in-const-ex...?

> As a side note, even PHP's official wiki cannot highlight correctly the multiline attributes behind a "#"

Yes, unfortunately the off-the-shelf software of the Wiki uses a custom-built highlighter instead of the `highlight_string()` function that is bundled with PHP: https://www.php.net/manual/en/function.highlight-string.php

40. pjmlp ◴[] No.45993872{7}[source]
It definitely is, because we are discussing knowledge of programming languages specification across their whole lifetime.
41. phplovesong ◴[] No.45993947{5}[source]
Precisely. PHP has tools for this too, but lack the syntax. Right now you need to to all typings in comments, and thats just as bad as jsdoc was in 2005.

This could be the way PHP could go, they just need the lexer to handle types, and not do any runtime checking at all.

But i guess that goes against what the php devs want, but it sounds so wasteful, to typecheck the same code time after time even if it passed some sort of initial "compile time step".

replies(1): >>45994268 #
42. phplovesong ◴[] No.45993977{5}[source]
I often return some collection of types in an array eg [User, Config]. Right now my return type is just "array". To get this to work i need to build yet another wrapper class and all that, and thats just wasteful and totally unnecessary.

A even more simpler example is An array of some sort of Item. I cant return array(Item), but i only can return an array.

replies(1): >>45994937 #
43. duckerude ◴[] No.45994268{6}[source]
The current amount of typechecking might be a net efficiency improvement AFAIK. It provides a hard runtime guarantee that variables are certain types while Python has to check whether something is supported at the last possible moment. But I don't know how much use the optimizer makes of that.
44. array_key_first ◴[] No.45994285{4}[source]
PHP typing is most definitely stronger than python overall.

Yes array is the evil collection type of everything, but that's how it's meant to work. Array is the quick and dirty 'throw everything in there' thing. PHP has classes and they're very full featured and offer lots of type safety - use those.

45. danaris ◴[] No.45994937{6}[source]
What do you mean, "to get this to work"? It's a PHP array. It will return whatever you need it to.

What is not working?

46. _DeadFred_ ◴[] No.45995052[source]
I used laracasts.com plus AI code assistants to bring myself back up to speed pretty quickly.
47. Capricorn2481 ◴[] No.45995108[source]
I work on projects from PHP 5.6-8.4 and I can't say it feels that different. It's mostly just type differences.

But PHP 5 was released 21 years ago and is unsupported. Companies using it are putting their customers at risk.