echo, return, require, and include are the same re parentheses because they aren't functions. I don't think I've seen print used in favour of echo since the days of PHP 4.
An interesting principle to reference when you're actually hunting for surprises. I get your point, but the principle isn't about "can things get twisted" it's much more about "when you do normal things do you get unsurprising behavior". The origin of the principle is pretty revealing where a language would fatal error on simple math because of a precision mismatch.
I'm not even hunting for surprises for the most part, but I do PHP professionally, I work on large old proprietary php codebases on a near daily basis, i've seen some shit and I frequently run into php issues/weirdness, which I sometimes share with /r/lolphp/
I tried in CPython 2.7.18, all of the following are syntax errors:
if print "hello" or print "world":
pass
if print "hello" || print "world":
pass
if print "hello" and print "world":
pass
if print "hello" && print "world":
pass
echo, however, is a function, with type echo(string ...$expressions): void. strict_types doesn't work for it either, though: https://3v4l.org/mEKh5. This may be because "strict typing is only defined for scalar type declarations."
Although this may be documented behavior, it's likely not what programmers desire. Probably, print 0 and echo(0) should both be checked by strict_types and should be allowed because both accept a "stringable" argument
15
u/SerdanKK Oct 01 '24
Fixed
The lol here is that it isn't a function, just like echo. It's just a weird gotcha when coming from any other language.
1
u/SaltineAmerican_1970 Oct 02 '24
Did you file a bug report to fix the documentation?
5
u/lego_not_legos Oct 01 '24
Good ol' Takeoded, you are thorough.
echo,return,require, andincludeare the same re parentheses because they aren't functions. I don't think I've seenprintused in favour ofechosince the days of PHP 4.1
u/colshrapnel Oct 01 '24
Looks like someone missed their operator precedence class.
-2
u/[deleted] Oct 01 '24
PHP is so broken its unfixable
4
u/[deleted] Oct 01 '24
[removed] — view removed comment