The @
in foreach
issues the error:
Parse error: syntax error, unexpected 'foreach' (T_FOREACH) in C: \ www \ test.php on line 30
This is a syntax error , ie in the parse of the language, see that even in a certain script the error occurs:
% is not a function , it is part of the language syntax, so the interpreter has no sense of what you are doing, ie after foreach
was expected thing but it came across the foreach and the message says "foreach not expected (T_FOREACH)"
For example, this would also be wrong for the syntax:
(foreach (range(1, 10) as $value) {
var_dump($value);
});
See: link - the same error is issued
@
is part of the language statement, such as foreach
, while
, switch
and for
, see an example with if:
<?php
@if ($foo) echo 1;
This causes a similar error:
PHP Parse error: syntax error, unexpected 'if' (T_IF)
About suppressing warnings and errors with at @ @
Note that the
if
function does not return iterable (it does not return an array or iterable object) it returns boolean , as documentation
link :
bool ksort (array & $ array [ int $ sort_flags = SORT_REGULAR])
Another thing, do not print on the screen warning does not mean that it did not occur, ksort
is just like putting a curtain on anyone to see what you are doing behind it, behavior does not change at all internally, it is only hidden, but still the script is flawed and will trigger errors.
In other words, the @
is only to suppress, but does not mean that it does not occur, in fact it is very useless in my opinion, for many cases @
in display_errors=Off
would solve already, I recommend that you read those links in order: