Ancestors

Written by dseguy on 2024-12-11 at 20:33

Passing a literal by reference is a Fatal error,

while returning the same literal by reference is a notice.

[#]PHP : Why?

[#]phptip #phptrick

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

=> View attached media

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

Written by Alerta! Alerta! on 2024-12-11 at 21:31

@dseguy Passing a literal value by reference doesn't make sense and is probably a case of "you are doing it wrong". Think about passing a literal array to sort doesn't make sense....

OTOH returning a reference to some static value still allows me to change that value - even though it might not male much sense.

Alao usually the person calling a function is much more likely to do something stupid than the person writing that function.... 🙈

It might not be the real reason, but it works for me 😁

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

Toot

Written by Ben Ramsey on 2024-12-11 at 21:43

@heiglandreas @dseguy Passing a literal array to sort() is a common mistake because most people probably expect it to return the sorted array. After 25 years of using sort(), I’ve even found myself doing this and forgetting that it doesn’t return the sorted array.

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

Descendants

Written by Ben Ramsey on 2024-12-11 at 21:45

@heiglandreas @dseguy A “literal” is a bad example in this case because, if I had a literal, I would probably handwrite it already sorted, but you get the point. 😁

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

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

This content has been proxied by September (ba2dc).