Live data from Hacker News

PHP 8.4

php.net

321–330 of 337 posts

Re: PHP 8.4

#321
post #318

Non PHP expert here, can someone explain to me the line get => \sprintf("%s_%s", $this->languageCode, $this->countryCode); in the first code example? Is it a lambda?

Yes, you can read about it the rfc under "Abbreviated syntax" https://wiki.php.net/rfc/property-hooks It follows the syntax of arrow functions https://www.php.net/manual/en/functions.arrow.php

Ahhh, and the backslash is the global namespace, as I just figured out: https://stackoverflow.com/questions/4790020/what-does-a-back...

Re: PHP 8.4

#322

Earlier quoted context omitted.

Fair enough, you're right! Anyway, it _could_ have been namespaced. It _should_ have been namespaced. I'm sad for the app author, but he should have seen that coming. His app was developed well after namespaces were introduced. You're making impossible demands. PHP has chosen to be backwards compatible _to a certain point in the past_, and it is generous in what it decides to keep working. To expect that 8.4 will car…

8.4 is not even backwards compatible with perfectly working code written to target 8.x . It doesn't materially matter that the code is written in "5.2" style if it was meant to run on only 8.x. Even that style point is arguable. The author uses Composer! And Laravel! And mostly does use namespaces, outside of a few useful helper functions that are reasonably global so they don't keep needing to import them or use nam…

What you are saying makes no sense.

"The author uses Composer! And Laravel"

So what? Can you explain what this means in this context?

To me, it looks like you're defending shitty code just to be able to attack PHP.

Re: PHP 8.4

#323

Earlier quoted context omitted.

> - Easy to deploy: Upload files, done. Sure, it works for simple/less important cases. But it also means that your application code is inconsistent while the files are uploading. Stop your service, upload the files, start the service: safer. For a Django app you would upload files and ask Gunicorn to graceful reload... similar, just cleaner.

Most PHP apps use a deployment method where a symlink gets set to a directory with a new version of the code. Because of how opcache works this has no impact on running requests, while new requests get handled with the new code.

That sounds pretty neat.

Re: PHP 8.4

#324

Earlier quoted context omitted.

I need to worry about it if I'm using it in an app. In what job you don't need to worry about what code are you executing? This is the whole point. It makes my job much harder to do, much more hidden and arcane - not worth it to save few characters. Yes, reflection is a mistake. It's a hotfix for problems caused by OOP. It's not actually necessary. TypeScript is a good example. Some people write it like Java/C#, with…

> In what job you don't need to worry about what code are you executing? Worry about? Or understand the fine minutia of how every property you fetch or store is handled? > It makes my job much harder to do, much more hidden and arcane I don't know how you do your job, but seeing a real (i.e. not a faux property handled by __get/__set) class member's implementation is literally 1 click away in any decent IDE. Clicking…

Of course it's applicable, it means "I read the data out of my runtime". Doesn't mean it's what you should do. Like GOTO, mutable variables in global namespace, and so on.

Re: PHP 8.4

#325
post #314

Earlier quoted context omitted.

Can you elaborate? I'm not sure what you mean, but IDEs definitely make reading code easier. IDE does code formatting, highlighting, argument hints, jumping to methods, declarations, and various hover effects on variables, methods, and classes. Some IDEs offer call graphs and other more advanced tools. Not to mention static analysis that works out of the box in PHPStorm (and I'm sure it can be set up in VSCode).

I mean that no matter what you do, the arguments will always be shown in an inconsistent order and you’ll have to mentally swap them around. You probably could configure your editor to visually swap them, but that sounds like a really bad idea.

If the argument order is a problem for you, you can use named arguments.

Re: PHP 8.4

#326
post #278

Earlier quoted context omitted.

That only works if your application has reasonably few users. Otherwise, your upload will result in some requests hitting a partially completed code base overwrite, that is, only some of your changes have been uploaded at request time, possibly leading to an error. This is a nice strategy for a hobby project, but it plain does not work for a business.

That's not true. For mission-critical apps we route the traffic to the stable version while uploading the new version. This may be similar to what most CI tools do but it doesn't change the fact that we just upload the files and can do it as we see fit. Another good solution is to simply switch off a feature for maintenance while uploading it's files. If your software is well planned, that's a breeze and still keeps…

Well, you’re shifting the goal posts. The original scenario was simply uploading files to the application folder on production servers and reloading the page.

Of course there are viable strategies to avoid this specific issue, but they all introduce complexity of themselves.

Re: PHP 8.4

#327

Earlier quoted context omitted.

The more I program the more I realize that we are all blind men feeling out an elephant. It sounds like you got the gist but somehow you are in an area of programming where getter/setters aren't useful. That's fine and okay. Part of growing up as a programmer is realizing your niche. Most of the advice out there is deep, not broad. It's deeply connected with our niche and not necessarily broadly applicable.

Getters/setters are just as easily associated with hidden behavior that makes systems worse. The only sibling comment of yours that bothered to even show code just demonstrated how they turned user.lastPost into a method that makes a hidden DB query. Yet the benefits are supposedly so nuanced and hard to get across that merely asking about it gets a "you'll understand when you get some real experience ;)" comment fro…

Haha as someone who doesn’t understand getters/setters as a pattern I’m bewildered by this subthread.

Re: PHP 8.4

#328
post #14

Earlier quoted context omitted.

Wikipedia is still on php 7.4.33 so don't feel too bad if you are behind.

For a project like Wikipedia, stability and continuity are far more important than latest and greatest feature support; in fact, there's an argument to be made to avoid newer language features to ensure consistency, that is, if new features are used, they should be used everywhere at once. Else you end up with frankenstein code where every file could use a different style.

For most projects outside of hobby projects, I feel this should be the default case, unless there are just some huge costs savings like “improved performance by 50% and now you can save money and scale down your AWS allocations!”

Re: PHP 8.4

#329

Earlier quoted context omitted.

You could prevent the recursion without this magic, by making the access a compiler error.

404 ComPHPiler Not Found

Whatever you want to call the code that parses the file and emits a syntax error.

Though what would you personally call "the thing that turns it into bytecode"?

Re: PHP 8.4

#330

Earlier quoted context omitted.

It’s interesting to consider the “magic” criticism in the context of languages like Zig, where devs actively want no hidden control flow. And Properties beyond simple { get; set; } are definitely hidden control flow. But as you said — it’s been there in C# for a while and imho it’s a good abstraction over getters and setters. Even 2005-era IDEs could manage it fine, making it easy to access the property’s get/set cod…

> Maybe it’s a culture thing — most C# devs use IDEs. Not sure what PHP devs use, but I suspect tools like PhpStorm will make this easy to work with somehow. Devs using no-LSP editors will likely have a different view. This is probably one of the big factors. I am also not a huge fan of “magic” even though I use IDE (vscode). I started off as a PHP dev, directly editing files on production server using vi. Any “magic…

At my first job, I largely used Notepad++ and grep, and the result tended away from object-oriented code and code paths tended to be not much more than `require_once("common.php");`

The second job introduced PHPStorm, and a single page load can bounce through dozens of files and classes; it would probably be untenable without modern tooling.

Post reply on HN