Results 1 to 3 of 3

Thread: [RESOLVED] How to properly handle "Undefined offset"?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    431

    Resolved [RESOLVED] How to properly handle "Undefined offset"?

    What is the correct way to fix this?

    The only option I have right now it to disable that particular notice in php.ini.

    I am using is_null (but atm is_set would also work as far as functionality), but just sending that undefined offset using is_null sets off the error. Any trick to fixing this? Right now I am getting like 30-40, and I just started coding :P
    Last edited by Zeratulsdomain; Mar 27th, 2008 at 08:05 AM.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: How to properly handle "Undefined offset"?

    I assume you are using strict mode. This is a good thing. Don't disable warnings; fix the code.

    You can use isset() or array_key_exists() to determine if an offset exists. There is a very subtle difference between the two which doesn't matter in most cases.

    is_null() will not work — this actually attempts to read the array offset, and so fails if it does not exist.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Posts
    431

    Re: How to properly handle "Undefined offset"?

    weird, thought I had tried isset, but just tried it again and it worked, tnx.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width