19 ms·
PHP 8.1.0
- EGreg 5y agoWhat 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 = ''; }
- codazoda 5y agoJust going to link to this from earlier today. https://front-line-php.com/cheat-sheet https://front-line-php.com/cheat-sheet It’s covered under “Attributes”.
- hu3 5y agoThese 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.php https://www.php.net/manual/en/language.attributes.overview.p...
- deleted 5y ago[deleted]
- exitheone 5y agoAn annotation syntax no outside of doc strings. Something PHP desperately needed. Very similar to Java annotations.
- pluc 5y agoDoctrine 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.10/reference/annotations-reference.html https://www.doctrine-project.org/projects/doctrine-orm/en/2....
- tarokun-io 5y agoI haven't written PHP in years but I get the feeling from this release that they are taking inspiration from TypeScript and JavaScript.
- dubcanada 5y agoThat's a funny thing to say, considering those took inspiration from other languages.
- agumonkey 5y agothey all lifted stuff from ml/scheme in the 80s
- jonwinstanley 5y agoDefinitely some JS influence plus a little Swift and Java. PHP seems to be evolving faster than it has in years
- pirate787 5y agoIt's actually becoming a problem keeping pace with PHP major updates
- mschuster91 5y agoPHP isn't Linux with its strict "never break userspace" dogma - but for real, a PHP version upgrade should not be that bad to follow.
- bilal4hmed 5y agoI 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.
- message 5y agoSame, but it looks like they are trying to make Java out of it.
- marcodiego 5y agoStill holding the web. Happy to see it is continually evolving.
- DaiPlusPlus 5y agoWhat'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 5y ago80% 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.
- marcodiego 5y agoThere'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.
- simonw 5y agoFibers "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 https://github.com/python-trio/unasync which can code-generate the non-async version of a library from the async version.
- Ralfp 5y agoBut 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 5y agoI wrote a bit about that pattern last year: https://simonwillison.net/2020/Sep/2/await-me-maybe/ 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.
- jeltz 5y agoRuby has the same design where async is implemented on top of fibers.
- rbanffy 5y ago> allow blocking and non-blocking implementations to share the same API Sounds like an excellent way to create weird concurrency heisenbugs.
- pachico 5y agoEveryone 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.
- PostThisTooFast 5y agoI wasn't laughing at it until I tried to follow this link and the server was down.
- IshKebab 5y agoI'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 5y agoPhabricator is not written in "modern PHP", so your experience is not surprising
- wutwutwutwut 5y agoCan you link something written in modern PHP?
- allan_s 5y agomost of projects based on Laravel/Symfony that are < 5 years old
- n42 5y agolike 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 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
- s-xyz 5y agoWho is still using PHP anno 2021?
- aimor 5y agoI use PHP for my personal sites.
- human 5y agoEveryone.
- duiker101 5y agoConsidering just WordPress powers something like 40% of the whole www, I'd say quite a few people!
- emodendroket 5y agoI'd say there's a difference between choosing an established product like WordPress or MediaWiki and looking at a greenfield project and choosing PHP.
- jeltz 5y agoBut how much of that is just fake SEO websites? Virtually all the fake sites use Wordpress.
- ArtDev 5y agoConsidering 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!
- g8oz 5y agohttps://slack.engineering/taking-php-seriously/ https://slack.engineering/taking-php-seriously/
- philippta 5y agoThis post is 5 years old. Slack migrated from PHP to Hack. By now you can not run PHP code in Hack anymore.
- firefoxd 5y agoI'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 5y agoYou 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".
- 0x0nyandesu 5y agoThat's still much slower with JavaScript. We use both in php land.
- fbn79 5y agoIn 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.
- fourseventy 5y agoWhat monsterous golang app are you running that takes 30 seconds to compile?
- bch 5y agoMore interested in what meaningful fixes can be done in some fraction of the 1.2s RTT of this rapid-fire style PHP development.
- pdenton 5y agoQuestion: 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.
- TazeTSchnitzel 5y agoThere's already kinds of classes that can't be instantiated, why would this specifically be a breaking change?
- pdenton 5y agoIf 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.
- francislavoie 5y agoI 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?
- jdjdjrj 5y agoSay 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 5y agoSay 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...
- stefanos82 5y ago...so it basically is `0 == ![]`, in other words, `[].length` which is `0`, thus becomes `0 == false` which returns `true` with loose comparison?
- 0x4d464d48 5y agoYep. 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.
- npteljes 5y agoWhat is this argument for, or against?
- maxpert 5y agoFibers!!! 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.
- gmfawcett 5y agoI 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.
- donatj 5y agoAsync/await isn’t something to hope for. It’s a terrible pattern languages should work hard to avoid.
- tehbeard 5y agoCare to explain why?
- gmfawcett 5y ago"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-your-function/ https://journal.stuffwithstuff.com/2015/02/01/what-color-is-...
- tehbeard 5y agoWhat 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.
- tdrdt 5y agoI 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.
- rbanffy 5y agoGenuinely 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?
- iamphilrae 5y agoIf 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.
- rbanffy 5y agoTrue, but that’s self reinforcing. The more you use a hammer, the more confident you become in everything being nails.
- iamphilrae 5y agoAnd 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.
- rbanffy 5y ago> 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.
- 5y ago
- shruubi 5y agoAs 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.
- pluc 5y agoThis is relevant: https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundation/ https://blog.jetbrains.com/phpstorm/2021/11/the-php-foundati... Automattic is now more involved in PHP so hopefully that'll enable some collaboration
- gregmac 5y agoPHP 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 https://www.php.net/releases/4_2_0.php [2] https://www.php.net/releases/5_4_0.php https://www.php.net/releases/5_4_0.php
- VMtest 5y agoReading 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 https://news.ycombinator.com/item?id=29343773 [1]: https://news.ycombinator.com/item?id=29344427 https://news.ycombinator.com/item?id=29344427 [2]: https://news.ycombinator.com/item?id=29344704 https://news.ycombinator.com/item?id=29344704 [3]: https://news.ycombinator.com/item?id=29345986 https://news.ycombinator.com/item?id=29345986
- francislavoie 5y ago> 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 https://reactphp.org (which is an event loop runtime, similar to Node), and https://amphp.org https://amphp.org (also event loops), and Swoole https://github.com/swoole/swoole-src 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.
- conradfr 5y agoNot all PHP is behind a web server. Think long running workers, queue consumers, daemons etc.
- ittan 5y agoExcuse my intrigue. Is this topic biased to language design or experience using php?
- josephcsible 5y agoPHP 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.
- scrapcode 5y agoI 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.
- Snelius 5y agoSetup ur apache first, lol
- lifeplusplus 5y agoPHP devs make less and have to learn JS anyways.
- fart32 5y agoI 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.
- exikyut 5y agoYou technically can use getters and setters in PHP, albeit with a noteworthy bit of extra implementation associated with wiring up __get() and __set().
- fart32 5y agoSure 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).
- briimannen 5y agoStill no unicode support? LOL! How about starting there and stop with trying to make PHP into some weird Java clone.
- laacz 5y agoJudging 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.