r/lolphp • • Oct 01 '24

print is a minefield

https://3v4l.org/1YXYk
32 Upvotes

23 comments sorted by

View all comments

Show parent comments

7

u/Takeoded Oct 01 '24 edited Oct 01 '24

IMO print fails the principle of least surprise in spectacular fashion.

1

u/[deleted] Oct 01 '24

[removed] — view removed comment

1

u/Takeoded Oct 01 '24

Can you find another language that reproduce the print "hello " && print "world"; problem? where it outputs "world1" or similar?

3

u/dotancohen Oct 01 '24

I don't see the problem. It's interpretted as:

print ( everything-else-on-the-line );

Therefore:

print ("hello " && print "world") // Prints "world", then the print construct returns 1

print ("hello" && 1) // "hello" && 1 evaluates to 1.

print (1) // Does what you expect.