Live data from Hacker News

PHP 8.4

php.net

241–250 of 337 posts

Re: PHP 8.4

#241
post #6

These days, I am super torn about what language to use for new web projects. PHP: - Easy to deploy: Upload files, done. - Easy to develop: Reload page, see changes. - Lots of HTTP tooling built in. - Fast. Python: - Great language. - Great code reuse system: Modules. - Nice framework: Django. - Less breaking changes in recent years.

The PHP framework slim is x1000 better than Django and is quite popular.

https://www.slimframework.com/

Re: PHP 8.4

#242
post #220

Earlier quoted context omitted.

This would be a valid point 20 years ago. PHP functions can be namespaced. I can just write myLib\array_find, otherLib\array_find. You choose what implementation you want when importing. IDE will pick the correct one. So, zero chances of collision.

Read my comment and all previous comments again. Don't write such meaningless words and waste your and other people's time when you don't even understand what people are talking about.

Your previous comment makes little sense and your reply is just angry and explains nothing.

A tool to avoid collision was introduced decades ago. This tool was made proeminent by the language and the ecosystem (PHP-FIG, frameworks, books, popular PHP celebrities).

You literally have to had stopped programming PHP more than a decade ago to not understand namespaced functions.

https://phptherightway.com/#namespaces

This problem of collision was seen miles ahead, and people were gently introduced to the idea that the global namespace belongs to PHP builtins and you should not pollute it even further.

I would say it is consensus for the PHP community that if your code broke because you defined array_filter globally before 8.4, then your code sucks and you don't know PHP.

Re: PHP 8.4

#243

If you want any evidence that terrible language design is alive and well in PHP, look no further than the new array_find function. Not only is it yet another global function in a namespace already chock full of random array helpers, it is extremely similar in both name and usage to array_search - a global function since PHP 4. Except, of course, that in typical PHP fashion, array_find’s argument order is ($array, $fi…

array_search() has the same needle, haystack order as in_array() or array_key_exists(). array_find() has a callback and takes the same order as array_walk() or array_filter(). It's just array_map() that's different, but that's because it can take multiple arrays. And writing your own function with a prefix already used by PHP in the global namespace is just not a very good idea.

Re: PHP 8.4

#244
post #11

Earlier quoted context omitted.

Don't forget Laravel for PHP.

It’s difficult for me to trust a framework backed by venture capital ( https://blog.laravel.com/accel-invests-57m-into-laravel ). There are too many incentives to prioritize making money, which makes it easy to overlook developer experience. I rather use Symfony instead.

Symfony took venture capital years ago, it's no different really: https://www.sourceguardian.com/blog-symfony-gets-boost-from-...

Re: PHP 8.4

#245

I'm just a PHP programmer for work, but I worry about the orientation PHP has chosen. As French people say: better is the enemy of good (Le mieux est l'ennemi du bien). The two new language features bring a higher language complexity for dubious gains. I hope I won't have to work with these. Property hooks mean that some language magic will turn a property access into a call to methods. It implies that `$this->x` has…

I agree with what you wrote and I am familiar with that saying.

PHP to me, professionally, is nothing without Laravel. So as long as Laravel doesn't become more obtuse than it already is, it's all good.

I really dislike getters and setters, particularly when they allow async code. Now all the sudden you have a massive performance risk, it's all too typical to see junior devs doing expensive stuff in getters and now the whole application, exponentially, becomes slower.

Anything that _may_ involves magic is dangerous in large code bases.

Re: PHP 8.4

#246
post #159

Earlier quoted context omitted.

Every step on the path to bloat is justified.

And yet in this wonderful laboratory of a multitude of languages the growth of a language doesn't destroy as much as it offers a larger variety of choice - with good features being stolen by other languages and less good features remaining niche and unique.

Look at C++ or Perl, languages with many features that are quite frequently hated. When you add features, you force users to learn those features. It is not just a "variety of choice" because you know that other people will also take some of those choices and you'll probably have to edit their code at some point. Features are not just added to the language, but imposed on its users. The need to add features to a language is a sign that what you already have is insufficient. Features should be added to the bottom of a language, increasing its expressive power, rather than to the top of the language forming cruft around the edges. It would be much more productive for us to collectively abandon PHP in favour of sane languages, ones which don't require the continual addition of more features to cover their foundational shortcomings.

Re: PHP 8.4

#247

For how many years will it get support, security and bug fixes?

If needed you can get LTS from Zend. They still offer security fixes for 7.2 until end of 2026 and 8.3 is supported until end of 2029. But that's just if upgrading every second or third year is too expensive to you.

Re: PHP 8.4

#248

Earlier quoted context omitted.

That is a fine argument for setters, but I still don't see the connection between that, and the desire to disguise properties as setter methods.

Some light weight ORMs do not require you to define all the properties ahead of time. They pull the field names from the table and generate the model record on the fly for you. This generally lets you prototype really fast. Laravel's Eloquent is known to do this. It's also useful for derived SQL fields when you use custom queries or join from other tables. Also kinda fun to do it for properties backed by a method. As…

Is it possible to dynamically define methods in PHP?

Re: PHP 8.4

#249
post #237

Earlier quoted context omitted.

There are many times I would love to have an automatic backing field in C#. C# will do that if you use the default setter but in cases where that's not possible I dislike having to both declare a separate field and having it available to the rest of the class outside of the setter.

C# 13 has this via the field keyword (as preview feature): https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... It's pretty similar to what PHP provides here, except that PHP uses "$this->propname =" and C# uses "field =". Edit: As someone involved in the RFC, it's somewhat funny, because we considered a special variable like "$field" or "$value" too magic, and C# does just that with a field keyword.

The `field` keyword also already existed in C#, to add attributes to the backing field of automatic properties, so I think the argument was easier there.

I used it in Unity projects to have serialized/inspectable values exposed through properties:

    [field: SerializeField]
    public int MyProperty { get; private set; }

Re: PHP 8.4

#250

I was curious about why setting `$this->countryCode` inside the setter for `countryCode` didn't result in infinite recursion. Turns out this is spelled out in the RFC, but not in the docs: When a hook is called, inside that hook $this->[propertyName] will refer to the “unfiltered” value of the property, called the “backing value.” When accessed from anywhere else, $this->[propertyName] calls will go through the relev…

Funny world where a feature to prevent infinite recursion -- at a moment in the runtime lifecycle where that would make sense -- is somehow viewed as dangerous footgun magic (addresed to: several replies under this comment).
Post reply on HN