[HN Gopher] PHP 8.1.0 Release Announcement ___________________________________________________________________ PHP 8.1.0 Release Announcement Author : AegirLeet Score : 181 points Date : 2021-11-25 18:39 UTC (4 hours ago) (HTM) web link (www.php.net) (TXT) w3m dump (www.php.net) | rbanffy wrote: | 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? | tarokun-io wrote: | I haven't written PHP in years but I get the feeling from this | release that they are taking inspiration from TypeScript and | JavaScript. | wvenable wrote: | 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. | dubcanada wrote: | That's a funny thing to say, considering those took inspiration | from other languages. | agumonkey wrote: | _they all lifted stuff from ml /scheme in the 80s_ | jonwinstanley wrote: | Definitely some JS influence plus a little Swift and Java. PHP | seems to be evolving faster than it has in years | pirate787 wrote: | It's actually becoming a problem keeping pace with PHP major | updates | mschuster91 wrote: | 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. | nicoburns wrote: | I think 8.0 had a bunch of relatively major/annoying | breaking changes, but that's the first time since the 5.x | era. | blowski wrote: | 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.) | wwweston wrote: | 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. | firefoxd wrote: | 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. | butz wrote: | 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". | CodeWriter23 wrote: | Same folks say Perl is unreadable because the syntax for | certain aspects of the language is unfamiliar to them. | throwamon wrote: | There might be more to it than that... | | https://news.ycombinator.com/item?id=19576425 | fourseventy wrote: | What monsterous golang app are you running that takes 30 | seconds to compile? | bch wrote: | More interested in what meaningful fixes can be done in some | fraction of the 1.2s RTT of this rapid-fire style PHP | development. | goalieca wrote: | Once you throw that stuff in K8s, you're back to 10seconds. | rbanffy wrote: | Do you debug your apps in a K8s environment? Why? | bovermyer wrote: | If I throw my dinner in K8s, will I get back filet mignon? | djbusby wrote: | Nope, you get Vienna sausage | the_gipsy wrote: | With a proper type system you don't need to run your code 50 | times a minute. | Implicated wrote: | As someone who isn't perfect, it's nice to be able to quickly | iterate on ideas. | rbanffy wrote: | 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. | smt88 wrote: | 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. | djbusby wrote: | Hello me! Nice to meet me! | chubot wrote: | 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. | Lhiw wrote: | With a proper type system you can't. | | What a useless thing to say. The ap is talking about a tight | feedback loop and you decide to make a condescending comment | about type systems. Go back to twitter. | makeitdouble wrote: | 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. | wutwutwutwut wrote: | Is oopsing 50 times per minute a good thing? | selfhoster11 wrote: | If you're doing iterative development, why not. | firefoxd wrote: | No, not just oops. I get to see the state of the entire | application with different values. | helloguillecl wrote: | Of course not, it is just a way to show how fast things can | go with PHP. | pdenton wrote: | 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. | jdjdjrj wrote: | 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. | 0x4d464d48 wrote: | 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... | EGreg wrote: | 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 | = ''; } | hu3 wrote: | 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... | [deleted] | exitheone wrote: | An annotation syntax no outside of doc strings. Something PHP | desperately needed. | | Very similar to Java annotations. | codazoda wrote: | Just going to link to this from earlier today. | | https://front-line-php.com/cheat-sheet | | It's covered under "Attributes". | bilal4hmed wrote: | 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. | marcodiego wrote: | Still holding the web. Happy to see it is continually evolving. | DaiPlusPlus wrote: | 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. | mmaunder wrote: | 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. | tored wrote: | 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. | DaiPlusPlus wrote: | 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? | marcodiego wrote: | 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. | DaiPlusPlus wrote: | 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? | Gigachad wrote: | 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. | simonw wrote: | 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. | rbanffy wrote: | > allow blocking and non-blocking implementations to share the | same API | | Sounds like an excellent way to create weird concurrency | heisenbugs. | jeltz wrote: | Ruby has the same design where async is implemented on top of | fibers. | Ralfp wrote: | 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. | simonw wrote: | 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. | pachico wrote: | 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. | [deleted] | IshKebab wrote: | 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. | n42 wrote: | Phabricator is not written in "modern PHP", so your | experience is not surprising | wutwutwutwut wrote: | Can you link something written in modern PHP? | allan_s wrote: | most of projects based on Laravel/Symfony that are < 5 | years old | n42 wrote: | 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 | AegirLeet wrote: | 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. | jdjdjrj wrote: | 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. | johnny22 wrote: | 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. | JimmyRuska wrote: | 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. | blowski wrote: | 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. | holoduke wrote: | 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. | blowski wrote: | I'm sceptical that's a large proportion of PHP projects, | and thus comes under my caveat of _some_ projects. | Koffiepoeder wrote: | 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. | blowski wrote: | 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. | jeltz wrote: | 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. | krisrm wrote: | 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. | rhengles wrote: | 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 | KerryJones wrote: | 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. | Lhiw wrote: | Elegant PHP is an API with each endpoint ending in .php and | query Params that look like ?hello=world. | | I don't know why pretty urls or magical regex routing matter | so much to people but to me it's a huge waste of time when | PHP and your webserver already do all that you need. | | The result is an API with extremely obvious and easy to work | with code, every change to endpoint code is unable to blow up | the whole site, library code is still a risk but things are | far more isolated. | 0x4d464d48 wrote: | "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. | PostThisTooFast wrote: | I wasn't laughing at it until I tried to follow this link and | the server was down. | Gigachad wrote: | 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. | maxpert wrote: | 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. | s-xyz wrote: | Who is still using PHP anno 2021? | duiker101 wrote: | Considering just WordPress powers something like 40% of the | whole www, I'd say quite a few people! | jeltz wrote: | But how much of that is just fake SEO websites? Virtually all | the fake sites use Wordpress. | ArtDev wrote: | 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! | kgeist wrote: | 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". | allan_s wrote: | 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" | codegeek wrote: | I.personally avoid "Shiny Language" developers. | g8oz wrote: | https://slack.engineering/taking-php-seriously/ | philippta wrote: | This post is 5 years old. Slack migrated from PHP to Hack. By | now you can not run PHP code in Hack anymore. | hu3 wrote: | In August I did database related consulting for a client which | is build 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. | human wrote: | Everyone. | tdrdt wrote: | 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 | EUR 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. ___________________________________________________________________ (page generated 2021-11-25 23:00 UTC)