Re: Re: foreach with null
| From: | Markus Fischer | Date: | Wed, 26 Oct 2005 17:50:40 +0000 |
| Subject: | Re: Re: foreach with null | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-19730@lists.php.net to get a copy of this message | ||
Sebastian wrote:
Good code is code that's easy to debug (among other things). By removing the "Invalid argument supplied for foreach()" warning without providing mechanisms to turn it on, debugging code will be more difficult. Logically speaking, when does it make sense to iterate over something that isn't an array? If I were writing one-time use scripts that I will never use again (not likely) this might be desired behavior. If I were writing code that is used by other programmers, paying users, and under conditions likely to change (implying changing code, and often debugging and testing), the ability to detect errors as early as possible is vital (The Pragmatic Programmer is a good reference for this). Most people don't want to spend more time than is necessary to troubleshoot code. Probably more importantly, managers and customers don't want to wait longer for a product they're paying for.I also don't feel very comfortable with silencing the warning for NULL. If the variable is not an array and not traversable there's nothing to iterate over and it should tell the user. If we intentionally want to not know about this error, an alternate syntax with the '@' operator should be considered as it was requested in the past, e.g. '@foreach' or 'foreach(@$notarrayOrIterable ...'. - Markus