M
Don't forget that in a production PHP system, warnings should be disabled. The only time I ever use @ in my code is somewhere I truly don't care if the call succeeds or not, i.e: in cases where "it's nice if it works, but not necessary for life to go on".
I will admit, though, that it is tempting during development to slap down useless foreach() warnings with @.
Case in point... let's say you've got a set of checkboxes in a form, something like:
<input type="checkbox" name="boxes[]" value="val1"><input type="checkbox" name="boxes[]" value="val2">etc...
And process them as:
$boxes = $_POST['boxes'];foreach ($boxes as $idx => $val) { ... yada yada yada...}
If the form's submitted and none of those boxes were checked, $boxes will be a NULL value, causing PHP to spit out
PHP Warning: Invalid argument supplied for foreach() in <file><file> on line <x><x>.</x></file>
The joys of a shared namespace for all variables, I suppose. Perl's much nicer in this regard, with different namespaces for scalars, arrays, and hashes, and NOT complaining when an array you're iterating over happens to be empty.
p.s. For those who've managed to avoid PHP so far (lucky buggers...), naming a form field as name[] (with the brackets) will tell PHP to treat those fields as a multi-value field and store them into the $_GET/$_POST/$_REQUEST superglobals as an array, rather than a single value which contains only the last value as submitted by the useragent.