Live data from Hacker News

PHP 8.4

php.net

171–180 of 337 posts

Re: PHP 8.4

#171
post #135

I'm most excited for property hooks. Having getters and setters as part of the language syntax was something I dearly missed from my C# days, nearly two decades ago. In my projects I sometimes emulate getters and setters using `__get()` and `__set()` but that's heavy-handed and requires lots of PHPDoc annotation for type checking. Property hooks look awesome!

I'm curious, why do you like getters and setters? I know the textbook answer is so that every single possible property can become some mutable chain of events so you can swap names or side-effects without the caller knowing, but I've yet to find a use for that in real life. It just leads to builder patterns and other oddities like forced decorators like Java has everywhere. I felt like beans were the realization that…

They are used in ORMs to do property value conversions from PHP primitives to values a data store might actually want.

I wrote about it here https://technex.us/2023/07/php-attributes-are-so-awesome-i-j...

Re: PHP 8.4

#172

Earlier quoted context omitted.

I'm curious, why do you like getters and setters? I know the textbook answer is so that every single possible property can become some mutable chain of events so you can swap names or side-effects without the caller knowing, but I've yet to find a use for that in real life. It just leads to builder patterns and other oddities like forced decorators like Java has everywhere. I felt like beans were the realization that…

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.

This was weirdly condescending and content-free.

I've been programming for 30 years, and getters/setters are both pointless and anti-productive.

They hide (potentially a lot of) code from people reading the program, which leads to a lot of "wtf" moments later.

Magic in general is bad, and it's the kind of "look how concise and clever I am" thinking that leads to unmaintainable software.

If setting a property isn't straightforward, make it private/protected and add explicit getter/setter methods. It's more work today and much less work later on.

Re: PHP 8.4

#174
post #172

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.

This was weirdly condescending and content-free. I've been programming for 30 years, and getters/setters are both pointless and anti-productive. They hide (potentially a lot of) code from people reading the program, which leads to a lot of "wtf" moments later. Magic in general is bad, and it's the kind of "look how concise and clever I am" thinking that leads to unmaintainable software. If setting a property isn't st…

Every php ORM disagrees. Nothing about it is magic

Re: PHP 8.4

#175
post #32
post #11

Earlier quoted context omitted.

Don't forget Laravel for PHP.

I much prefer Symfony, but that's mainly because it's the framework I started with.

I was forced to move from Symfony to Laravel and I really dislike it. This experience seems to be very common.

Re: PHP 8.4

#176

Earlier quoted context omitted.

I'm curious, why do you like getters and setters? I know the textbook answer is so that every single possible property can become some mutable chain of events so you can swap names or side-effects without the caller knowing, but I've yet to find a use for that in real life. It just leads to builder patterns and other oddities like forced decorators like Java has everywhere. I felt like beans were the realization that…

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.

It sounds like you got the gist of the critique of getters/setters but just haven’t been exposed to the alternatives.

That's fine and okay.

Re: PHP 8.4

#177
post #133

Earlier quoted context omitted.

I agree. I think for largely cultural and timing reasons, and also its success, there are a lot more long-lived php codebases for this to play out in compared to most languages. I also think possibly node is our generation's php, with it being so fast-changing and there not being a community consensus about framework. So every complex node project is, like pre-laravel php, essentially a totally unique ad-hoc framewor…

T_PAAMAYIM_NEKUDOTIM, mysql_real_es ape2, parse_str, etc.

> mysql_real_escape2

Blame MySQL for that name, not PHP.

https://dev.mysql.com/doc/c-api/8.4/en/mysql-real-escape-str...

(And, if you're doing modern PHP, it's just PDO->quote().)

Re: PHP 8.4

#178
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.

Node: - easy to deploy: If you dont complicate yourself, with cpanel or plesk hosting is just matter of copy the files. - Terabytes of npm packages (even too much :)) - A non bloated and nice language (JavaScript) - Optional type checking with typescript if you want. - Non blocking IO

Re: PHP 8.4

#180
post #167

Earlier quoted context omitted.

I'm curious, why do you like getters and setters? I know the textbook answer is so that every single possible property can become some mutable chain of events so you can swap names or side-effects without the caller knowing, but I've yet to find a use for that in real life. It just leads to builder patterns and other oddities like forced decorators like Java has everywhere. I felt like beans were the realization that…

They are very useful when modeling CRUD-dy objects, because you can lazy-load infrequently-accessed child object using getters. It makes for a cleaner OOP-y interface in which the caller only cares about actually exposed properties and not methods to get and manipulate hidden properties . IMHO using properties directly is a much more natural way to talk about objects, than having a bunch of methods to get properties.…

I do not see any advantage here. All I see (or rather, what can't be seen) is hidden control flow. For what? To save a few characters?
Post reply on HN