Jump to content

Recommended Posts

General question..

 

Im making a new website and at the moment I have error reporting set to display warnings for debugging.

 

However, when for instance I do a foreach() :  if the array is empty a warning error is displaed "invalid argument supplied for foreach()"

 

Should I be checking if the array is empty before doing a foreach even if no harm can be done either way code side

 

I turn warning errors off once I release live so even though they are there they will never cause any issues.

 

It just seems very tedious to me to have if (!empty($array)) {foreach().......} any time I want to do a foreach on an array that may not contain any elements

 

Your thoughts please?

 

p.s - I know its good practice.. but seriously.. do you bother with the example given above?

Link to comment
https://forums.phpfreaks.com/topic/169168-fix-warnings/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.