Ancestors

Toot

Written by dseguy on 2025-01-24 at 22:29

The two lines of code look very similar, except for the new operator. And they actually behave very differently.

Can you guess what is the difference of treatment?

[#]phptip #phptrick

https://php-tips.readthedocs.io/en/latest/tips/method_or_property.html

=> View attached media

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

Descendants

Written by FlyingMana on 2025-01-24 at 22:32

@dseguy hmm, foo returns a classname and this gets instantiated by new?

But I cpuld also imagine some weird behavior where $object has a class name, which gets instantiated and then foo on this new instance is called

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

Written by dseguy on 2025-01-24 at 22:36

@Flyingmana are you sure both of them are method calls?

I mean, they look awfully like each other....

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

Written by FlyingMana on 2025-01-24 at 22:48

@dseguy I would expect it, but in such weird constructs I try to always add extra braces to make sure it does what I actually intend 😅

But that the second example might interpret foo as a property sounds scary

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

Written by dseguy on 2025-01-24 at 22:52

@Flyingmana I hear you. I like to showcase this kind of situations for education: better know them before they find you and bite you.

Although, I keep finding more, and more...

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

Written by FlyingMana on 2025-01-24 at 23:09

@dseguy there once was pho wtf collection with such things

@woodworker do you remember where?

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

Written by Christoph Lühr on 2025-01-25 at 06:53

@Flyingmana @dseguy @woodworker ... this one?

https://github.com/woodworker/WTF.php

=> More informations about this toot | More toots from xris@social.farcaster.net

Written by dseguy on 2025-01-25 at 09:42

@xris @Flyingmana @woodworker

Ah! How do I discover this 7 years too late?

"All the WTF of the PHP world" and there are only 3? Is there some more somewhere? Check the forks?

I have 170+ here, although some are actually diamonds in the rough. Let me introduce you to my little friend :

https://php-tips.readthedocs.io/en/latest/tipSection.html

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

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

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