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
=> More informations about this toot | More toots from dseguy@phpc.social
@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
@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
@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
@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
@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
@Flyingmana @dseguy @woodworker ... this one?
https://github.com/woodworker/WTF.php
=> More informations about this toot | More toots from xris@social.farcaster.net
@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 This content has been proxied by September (3851b).Proxy Information
text/gemini