Ancestors

Written by Greg Korba on 2025-01-21 at 08:22

Interesting #PHP RFC: data classes 🤔. With data modifier, such classes would have been compared by values they carry, rather than memory allocation (object ID). No more big conditions with multiple expressions, single === would be enough!

https://wiki.php.net/rfc/dataclass

=> View attached media

=> More informations about this toot | More toots from codito@mas.to

Toot

Written by Greg Korba on 2025-01-22 at 09:44

There are another 2 #PHP RFCs with similar concept 😵‍💫!

How on Earth voters can process all of that? Each of these RFCs require a lot of attention, I feel sorry for them 😅.

=> More informations about this toot | More toots from codito@mas.to

Descendants

Written by Giuseppe Mazzapica on 2025-01-22 at 12:15

@codito @codito I wonder why nobody has proposed an & before class name to make it comparable by value.

No new keyword, and the `&` is already something that means "by value" in PHP.


=> /toot/113871954873896640 More informations about this toot
=> /profile/109381886065948083 More toots from gmazzap@phpc.social

### Written by Greg Korba on 2025-01-22 at 12:36
@gmazzap Well, `&` actually means "by reference" 😅.

https://www.php.net/manual/en/language.references.pass.php

https://www.php.net/manual/en/language.references.return.php


=> /toot/113872035761975527 More informations about this toot
=> /profile/110077782275676734 More toots from codito@mas.to

### Written by Giuseppe Mazzapica on 2025-01-22 at 13:52
@codito My full though if I did not hit reply to quickly on mobile is that `&` is already used in PHP to switch from by-value to by-reference. When used before a class name (and not in front of a var name, as it is used now) it would IMO look in line with the current PHP syntax and a good-enough indication to tell "objects created from this class will be passed by value".


=> /toot/113872334721722753 More informations about this toot
=> /profile/109381886065948083 More toots from gmazzap@phpc.social

### Written by Greg Korba on 2025-01-22 at 14:21
@gmazzap Personally I don't like this. Currently `&` is used for telling PHP to pass/return by reference, where passing/returning by value is a default behaviour. Not only I don't like that `&` is "meaningless" (only familiarity makes it clear), but also I think that one operator can't do 2 opposite things, depending on the context. It's like you would like `@` to make PHP to report errors even if they are disabled through `error_reporting(...)` and wouldn't be reported when there's no `@` 😅.


=> /toot/113872451170156963 More informations about this toot
=> /profile/110077782275676734 More toots from codito@mas.to

### Written by Larry Garfield on 2025-01-22 at 14:39
@codito @gmazzap It's also not even about references. Objects pass by value now, but what passes is the object handle. That's subtly different than a reference.

What's needed is a way to force an object to clone itself on modification, which is what Ilija's RFC does. The catch is detecting when to do that is quite hard without the user indicating it syntactically, which his RFC does.


=> /toot/113872519230314519 More informations about this toot
=> /profile/108193348463228558 More toots from Crell@phpc.social

### Written by Giuseppe Mazzapica on 2025-01-22 at 15:27
@Crell @codito I liked Ilija's RFC, I only not like the `!` on method calls. The RFC says it is "technically necessary" without explaining why. 

The problem is that you need to know what the method does to know you have to use the `!`. Examples in the RFC are one liners, with complex methods someone else wrote understanding if you have to use `!` or not will be hard.

Btw, what I was saying is that you can keep anything in that RFC just the syntax could be:

=> More informations about this toot | More toots from gmazzap@phpc.social

Written by Larry Garfield on 2025-01-22 at 15:33

@gmazzap @codito If you can't figure out if the method will need to separate the object, the compiler has no hope. :-) That's why the ! is there. I hate it too.

But as Codito said, & means "make a reference", which is the exact opposite of what would be happening here. It's a misleading symbol. Some other symbol could make sense, but we're very low on available symbols...

=> More informations about this toot | More toots from Crell@phpc.social

Written by Giuseppe Mazzapica on 2025-01-22 at 15:38

@Crell @codito

If you can't figure out if the method will need to separate the object, the compiler has no hope

The burden to understand it should be on who writes the method, not who calls it.

& means "make a reference", which is the exact opposite of

As I said, you could make that symbol the "by-value/by-reference switch" and switches works both ways.

=> More informations about this toot | More toots from gmazzap@phpc.social

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113871358653987847
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
306.772157 milliseconds
Gemini-to-HTML Time
2.577785 milliseconds

This content has been proxied by September (3851b).