Can I disable warnings for particular foreach statements and more specifically the “invalid argument supplied” warning?
p.s. I want a foreach that when passed null, instead of throwing an error, will just not execute.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Alternative, type agnostic, using a typecast:
Would convert a NULL into an empty array, or a integer/string into an array with a single entry. This is sometimes advisable if you traverse flexible data structures (PHP is a dynamic language after all). The failure method is advisable for catching invalid data (should rather throw an error however).