17 ms·
What's new in PHP 8?
- NickSharp 6y agoHooray! Named arguments finally!
- superasn 6y agoThe thing I love most about PHP is that regardless of the new features they seldom break backward compatibility. I have a site created with PHP 5 that runs absolutely fine with PHP 7.0 and I don't remember we had to ever update anything in that huge codebase. It's a pretty big achievement and avoids a lot of hassle for users as you don't have to maintain different versions of programming languages on a server.
- systematical 6y agoLikewise. I built a whole back-end in PHP 5 back in 2009 for a client. His front-end has changed a ton in that time, but the backend is still chugging a long in PHP 7 with no problems.
- john-shaffer 6y agoI've had the exact opposite experience. It's unusual for an upgrade to not break something. There are dozens of breaking changes in this release alone: https://github.com/php/php-src/blob/96c7d42a3ca9d822a08b3dd48060abca8240413a/UPGRADING#L20 https://github.com/php/php-src/blob/96c7d42a3ca9d822a08b3dd4... Some of the changes are sadistic. "The precedence of the concatenation operator has changed relative to bitshifts and addition as well as subtraction." Have fun debugging code that worked perfectly well for years and now produces unpredictable results.
- alganet 6y agoPHP7 will still be supported for a while. Debian will probably support it even further. You'll have a long ass time to fix these. Even if you wanted to push the 8.0.0 to production as soon as it came out, you'd still have until November to run your tests on the RC branch and report any mishaps to the development team. The backwards compatibility is mostly targeted to major platforms (Wordpress, Drupal, Magento, Symfony, etc). > Have fun debugging code that worked perfectly well for years and now produces unpredictable results. This describes my everyday experience with any language or codebase. The cause for the unpredictable results are often human-related though, not version-related. > Some of the changes are sadistic. "The precedence of the concatenation operator has changed relative to bitshifts and addition as well as subtraction." I would gladly remove any code that does concatenation and math/bitwise on the same expression relying on the operator precedence. Sadistic is the person who writes these. More than 2000 packages were analyzed and only 5 instances of that particular use were found[1], all bugs. This is a good change. [1]: https://news-web.php.net/php.internals/105442 https://news-web.php.net/php.internals/105442
- john-shaffer 6y ago> > Have fun debugging code that worked perfectly well for years and now produces unpredictable results. > This describes my everyday experience with any language or codebase. That is horrifying. That should absolutely not be normal. I don't know what you work with normally, but it's clear that we are working in completely different worlds.
- alganet 6y agoI don't know any programming context immune to human errors. Stuff just breaks. Sometimes I get lucky and the guy before me wrote a cool test that prevents me from having to start a debugger, but the contrary is often the reality. OSS stuff is usually better, but not much better (OS upgrades always break, for example).
- wvenable 6y agoYou're not likely to have something like the concatenation operator mixed with bitshifts. Most of the changes are more likely to be bugs in your code that remain undiscovered rather than things that worked perfectly fine before but are now broken. These changes reflect how people use the language or what they already believe it to do.
- john-shaffer 6y agoYou're talking about hypothetical code, but I am talking about actual code that worked fine but no longer works after an upgrade. Perhaps it was poorly written, but it was not buggy. I can't think of a single time that I've seen a bug exposed by language changes. I have seen dozens of bugs created by language changes, however. (Mostly crashes).
- wvenable 6y agoIf you're depending on very weird edge cases in PHP I'd consider that buggy even if it works.
- john-shaffer 6y agoThis is a completely useless discussion if you're going to assume that code depends on "very weird edge cases" with no idea of what the code actually does.
- wvenable 6y agoYou're welcome to post an example.
- idlewords 6y agoI love this too. Moving Pinboard from whatever flavor of PHP it was based on (in 2009) onto 7.3 only ran into two issues—something to do with the "explode" function, and requiring a certain kind of constructor in objects. All the rest of the migration pain involved libraries. Granted, Pinboard is just a wrapper around some SQL queries, but that's what most PHP apps are. It was a big relief to find the migration so easy.
- darthrupert 6y agoYou should really like Common Lisp, then :) The language hasn't changed since mid 90s or so and many of the widely used libraries have gone for years without needing any changes.
- rawoke083600 6y agoYou mean there is actually software out in the wild that is "done" i.e finished !
- iillexial 6y agoI with they don't do this. There are a lot of inconsistencies in PHP that should go away these days, but they still keep them because of backward compatibility.
- jgrpf 6y agoBut it does break a lot of times and still contains a lot of inconsistencies.
- kyleee 6y agofor some reason (probably a bad one) i love switch statements and i look forward to the match expression
- systematical 6y agonothing wrong with switch statements.
- zowanet 6y agoCoerced-typed (weak) comparisons and easy accidental fallthrough are the problems commonly associated with switch statements. The new match construct fixes both of these and is also an expression instead of a statement, allowing for more expressive code.
- __sisyphus__ 6y agofor whatever reason (also probably a bad one), i hate the syntax of switch statements, and for that reason i almost never use them. the match expression though, i'm actually very excited about. i quite like the mapped look; it seems more intuitive to read.
- overgard 6y ago"This RFC fixes the very strange case in PHP where 0 == "foo" results in true. There are some other edge cases like that one, and this RFC fixes them." It's good they fixed it I suppose, but yikes. As much as people say PHP has advanced from its fractal of awfulness days, a lot of those fixes are shocking if you come from other languages.
- neals 6y agoWhy does 0 == "foo"?
- tyingq 6y ago"If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number" And a string that doesn't look like a number at all is converted to 0. No, I'm not condoning this madness.
- coldtea 6y agoWell, in C you can cast any random set of bytes to an int, so there's that...
- overgard 6y agoSure but in C you usually do that explicitly, on purpose. Here it's almost certainly not what you wanted or expected.. Also, C is 20-30 years older and I don't think I've ever read anyone really compliment its type system in any way other than saying it's simple.
- andreygrehov 6y agoIf one doesn't know the language, they can write shitty code, regardless whether it's C or PHP. Any decent PHP programmer knows about the `===` operator that doesn't do any type juggling.
- dgb23 6y agoI'm eagerly looking forward for union-types since I heard first of them. PHP APIs (both core and frameworks) suffer greatly from inconsistency. Union types in function/method signatures can greatly help static analysis. It is great that PHP gets this built in.
- zeroimpl 6y ago> Right now PHP 8 is in feature freeze, meaning no new features can be added anymore. > Starting with new features, remember that PHP 8 is still in active development, so this list will grow over time. Something doesn't seem right here :)
- kingkool68 6y agoI'm most excited about str_contains(), str_starts_with(), and str_ends_with(). Call me simple but I'm so glad I don't need to come up with weird work arounds for those functions.
- totony 6y agoFor those who need them EDIT: Actually, there are polyfills here: https://php.watch/versions/8.0/str_starts_with-str_ends_with https://php.watch/versions/8.0/str_starts_with-str_ends_with
- systematical 6y agoI like the constructor property promotion, union types, improvements to exceptions and try/catch. Lots to like here. Attributes worry me. Annotations are generally an eye sore to me, but in some places could be justified. For the most part, outside of Symfony, they were not used much. I'm worried that some developer will go bonkers with them, create a nightmare, and that will be the next legacy code base I inherit 5 years down the line. Named arguments is okay I suppose, but IDEs solve knowing the order of arguments. I guess the IDEs will implement an auto complete for named arguments? I guess thats okay, but it will require more vertical code if you care about your lawn and keep your code in the PSR margins. All in all I think this is a solid major, not the quantum leap we got from 5 to 7, but these are good additions. I'm sure we'll see plenty of decent additions in the minors.
- duskwuff 6y ago> Named arguments is okay I suppose, but IDEs solve knowing the order of arguments. Named arguments are incredibly helpful for functions with a bunch of optional parameters, like setcookie() -- instead of setcookie("cookiename", "value", 0, "", "", false, true); to set httponly (the last argument), you can now skip over the unused parameters and write: setcookie("cookiename", "value", httponly: true); Not only is this more concise, but it's also self-documenting!
- donatj 6y agoI would have personally been happy with setcookie("cookiename", "value", , , , , true); As I used in VB.Net 15 years ago, I have no idea if other languages (C#?) support that
- mjrpes 6y agoName parameters can benefit when you are reviewing code, beyond just when writing code; it makes clear what every parameter is for as you scan through code. This is most helpful with function calls with lots of optional parameters. Another benefit is name parameters can replace the current pattern of passing a "parameter bag" array. Code checkers can catch mistakes here at time of compile, rather than runtime. The negative of named parameters as implemented here is that the names are defined by the variable names in the function definition. So, renaming variables in the function definition will break code that calls the function using named parameters.
- Snelius 6y agoAn ancient evil is awakening
- dpcan 6y agoPHP was just PHP for years. Now I don’t even recognize what’s going on when reading code in a language I’ve used for my entire software development career. It’s like a new language. I want to be done with tech some days. I just want to do my job, not relearn a language I’ve used for 20 years.
- pastapaste 6y ago>I just want to do my job, not relearn a language I’ve used for 20 years. Good thing is you usually don't have to, languages like php really try and makntain backwards compatability, so you _can_ keep doing what you're doing. Even with some changes, companies rarely ride the wave and come onboard much later when major issues have been ironed out. Hell, there are PHP4 apps still out there
- jgrpf 6y agoBut that's a problem: it maintains backwards compatability with a LOT of well known problems/inconsistencies while introducing more features/inconsistencies for which you can just hope they don't mess up this time. It's a bit of good and a lot of bad from both worlds. I'm just so glad I don't have to use PHP anymore and no amount of a swine's make up will change this.
- etxm 6y agoKeep writing php5, It’ll probably be the high paying FORTRAN gig of the 2040s
- tonyedgecombe 6y agoIt seems every language has a group of people with an unrelenting urge to turn it into Java.
- karlerss 6y agoAs long as weak typing is not abandoned, the Java-like language features are great. I am really looking forward to generics in PHP.
- dilutedh2o 6y agoI dont see the big deal to be honest. If youre using == you're probably approaching the conditional too sloppily to begin with
- The_rationalist 6y agoThat's some huge release feature-wise.
- sir_pepe 6y agoAs someone who wrote their last lines oh PHP in something like PHP 5, this list tickles my desire to take PHP for a spin again. Not only does the language appear to be much improved, but also the frameworks look so appealing! I'm seriously over dealing with all the low-level plumbing that comes with building Node/REST SPAs just for what's essentially a bunch of forms.
- deleted 6y ago[deleted]
- obayesshelton 6y agoLaravel is a great framework to work with, I would seriously recommend giving it a try. As for NPM and the JavaScript packages, this is a flipping nightmare and I hate working with it!
- azangru 6y agoI hate to state the obvious, but it's the matter of familiarity. I've been working almost exclusively with javascript and typescript for the last 4-5 years; so that now, while trying to write an amateurish Symfony project (because shared hosting) and appreciating the maturity of Symfony, I still hate almost every moment of it and hope I could have used typescript. Anyway, what's wrong with npm and how is it so different than composer?
- flamemyst 6y agoOne that I can think of: The way npm install always check latest package version and use them, even if package lock already exists. Which broke apps build many many times due to developer does not recognize this behavior. I know there are npm shrinkwrap and npm ci. Its just other package manager usually follow lockfile on install and have other command to upgrade the lockfile. Also npm install download gazilion file for each dependencies. With deep directories. In the past, there are problem because npm way of installing dependencies and hitting this infamous windows file path length limitation. All are now already fixed or have alternative. But at that time, composer definitely much simpler and reliable.
- zaarn 6y agoMy prediction is that Annotations will be a game changer for PHP-based frameworks. Finally people will get something like in JAXR in Java, just being able to write @@Path("/users") over their listUsers function to have it be called when someone accesses the URL "/users" on the host. Having to setup routing the cumbersome way has been the bane of being productive in Laravel.
- julianorinyol 6y agoWas it really cumbersome to declare a route in laravel? Isn't it just one line in a web.php file where you associate an endpoint to a Controller function?
- zaarn 6y agoThe issue is that routes are declared in web.php. In some cases, web.php routes aren't automatically updated if you use `artisan serve`, so you have to restart that sometimes. And of course, it means there is a lot of distance between the file in which the controller and function are defined and the route definition. The route definition is in "routes/web.php" and the controller will likely sit in "app/Http/Controllers/Something.php", so if your Laravel project is moderately sized, you'll be scrolling a bit if you don't find the editor tab.
- pyr0hu 6y agoOn the other hand, I don't think it's a good idea to mix the controllers with the route definitions. How I configure or set up the routes should not be in the controller classes, that should be a separate thing. It's easier to see all the routes in that file instead of searching for them in the controller, especially as you said, in a moderately sized project, I can't be bothered to search or check the controllers. (You can counter argue that I can just Ctrl+F it). When you open up the routes file, you can see all your definitions in one place, which might ease the onboarding of new devs for example.
- zaarn 6y ago
- continuational 6y ago> Note that void can never be part of a union type, since it indicates "no return value at all". The empty set is the identity element for set union! It seems very weird to exclude it.
- choult 6y agoBut "void" is not an empty set, it is no set at all...
- uryga 6y agoif we want to squint and talk about sets and functions from sets to other sets... function voidy() : void { return; } echo json_encode(voidy()); // -> "null" so i'd say that for most purposes void ≡ {null} a singleton set, more or less[1], sometimes called a "unit type". that's because a void function does return something, it's just entirely uninteresting :) that's different from an "empty" type impossible ≡ {} // or ∅ with no values. there are no values of type `impossible`, so `foo() : impossible` can never return anything at all, like this: function foo() : impossible { while(1){} } see mypy's `NoReturn`, Rust's `!`, Haskell's `Void`. it's used for giving a type to functions like `exit()` [1] kind of, because it won't let you `return null` explicitly.
- obayesshelton 6y agoI would love to see PHP get some more/new love, it has a great community, fantastic tutorials and the package manager (composer) well just WOW!
- richardwhiuk 6y ago> The JIT — just in time — compiler promises significant performance improvements ... There haven't been any accurate benchmarks done at this point, but they sure will come. They wrote a new compiler, for performance reasons, and don't have any accurate benchmarks? Really?
- brendt_gd 6y agoThe only benchmarks done before adding it to the core were on maths-heavy code samples, something PHP is seldom used for. You can read about it here: https://stitcher.io/blog/php-jit https://stitcher.io/blog/php-jit
- NationalPark 6y agoI'm confused about this feature in general actually. Isn't the whole point of PHP's "simplicity" that each request creates a new interpreter process? So you're always in a "cold" state?
- mjw_byrne 6y agoI used to use PHP as a web backend and then moved to Go. Forgetting the debate about the actual languages, it makes so much more sense to me for a web app to be a full-fledged, self-contained program which happens to listen on a network interface and respond when things make HTTP requests at it. The old-school style, where routes map to scripts or parts of scripts and a separate web server like Apache or Nginx sits in front of the app, feels harder to reason about (does this thing persist across requests?), harder to debug (where did that error message end up?) more brittle (did this fail because of my script or my web server config or something else?) and more dependent on configuration magic (i.e. various text files lying around governing the behaviour of things). So although some of these changes look cool, I don't think it's the language itself that most needs improving.
- waheoo 6y agoInteresting take. I don't really agree, php routes are handled natively and very simply and easy to reason about using the .php extension. Its the frameworkers that broke that design with clean urls and fancy complicated routers. Php behind Apache or nginx is incredibly simple and easy to reason about. Browser loooks up this file url, this file url runs as a script and its output is returned. A bug in one file isn't propogated to all others so you can have highly reliable services with only partial failures from time to time. Whereas a bug in one route of a golang server may take the entire service offline. I do much prefer the deployment and shipability of a golang service, so much I am willing to give up the simplicity of PHP.
- sergiosgc 6y agoFunny. I completely disagree, and actually find it odd someone actually wants desktop style application state on web apps. One of the beauties of the PHP style of app execution is that application state is a lot simpler. Instead of having a running application server-side, which can be in a continuum of states, PHP forces you to start every request with a blank slate. Application state must be explicit (with serialized server-side sessions or browser-stored cookies). This makes it trivial to reproduce requests, trivial to debug, trivial to scale horizontally. To each his own, I guess. I just find your position genuinely surprising.
- qalmakka 6y agoAfter years of being a laughing stock, it's nice to see PHP finally becoming a nicer language instead of basically being the "three languages in a trenchcoat" of programming.
- watersb 6y agoOh I read this as “What’s New in PDP-8?” Was hoping for some awesome mods for a refrigerator-sized computer...
- G4BB3R 6y agoI've used PHP for many years, but decided to stop in 2018 for my sanity. Surprised it has basic pattern matching now, it is good for people to stop using imperative and mutable code where it isn't needed. Anyway, since I started to play with FP languages such as Clojure, Elixir and Elm, I am not interested in most of OO/procedural languages anymore.
- halfmatthalfcat 6y agoAny appetite to try Scala?
- tpetry 6y agoWhen they add generics there will not be anything i really miss from other languages when writing php. Ok tuples or simple struct types (type enforced arrays?) would ne useful too, but phpstan/psalm can solve this problem too
- nickjj 6y agoYou know, I used PHP back in the early 2000s and sometimes I miss it after having worked with Python, Ruby and Elixir over the years but it's not necessarily related to the language itself. I use this one program called Sendy (a PHP app) to help manage my email list. It's a typical LAMP set up. It's been running on a $5 / month server uninterrupted for 905 days with no down time related to the app malfunctioning. The whole system uses around 300mb of memory. Yesterday I decided to spin up a new server to finally retire the old one since it was using Debian Jessie that just went EOL 2 weeks ago. This required migrating a ~3 year old version of Sendy to the newest one (dozens of database schema changes included) and export / import my entire database. Everything just worked and all I had to do was rsync the PHP files to a directory and access the site in a browser, and it was upgraded and ready to go. I even ran into what I thought was a bug because my existing forms weren't working, so I looked into the single PHP file that was the form's action and within 5 minutes determined I was missing a hidden field (something Sendy added in a recent version). That was the first time I ever looked at its source code and PHP in a long time. It very much reminded me of my PHP cowboy days. No complicated build process, no dependencies (the whole app uses PHP's standard library), no having to restart the server between deploys, etc.. I know there's downsides to that and I'm very aware of them, but after having worked with increasing complexity for the last 10 years of web dev, man it felt nice for a change.
- stephenr 6y agoSendy is without a doubt one of the worst written pieces of software I’ve ever had the displeasure of (a) supporting in product And (b) having to patch. I would quit working in software dev and become a fucking gardener before I would work on Wordpress projects all the time, and Sendy makes Wordpress look well written. Edit: cowboy is a very apt term for Sendy. If the cowboy were drunk, and tried to make babies with the cows.
- nickjj 6y agoI didn't carefully analyze the code base but in my mind it's a victory if I can skim code in an unfamiliar code base / language and within a couple of minutes figure out a problem (not a problem with the code, but how I was using it). Did you run into bugs with it that required patching? I haven't to my knowledge.
- dynamite-ready 6y agoI've never quite understood the common reasons for bashing PHP. When I first got into web development, it was effectively the only real choice available. What it offered the beginner over the likes of Java and ASP (at that time) was ease of setup, a coherent model for simple data driven web page development (especially when compared to the likes of JSP), a great suite of built in functions, and comparatively excellent documentation. If I had to teach someone how to code now, I'd probably still consider PHP for the reasons above. Though Python has probably eclipsed PHP for many novice friendly reasons (docs and built ins).
- mekster 6y agoWhat is the point of "Non-capturing catches"? These kind of features would make debugging harder as people just ignore the actual error object and write weird common error message which could be useless.