Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7776385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:52:12+00:00 2026-06-01T17:52:12+00:00

Pretty simple question really, how do I pass undefined vars to functions without E_NOTICE

  • 0

Pretty simple question really, how do I pass undefined vars to functions without E_NOTICE errors?

When passing undefined variables to functions such as isset(), no error is raised, but send the same to your own function and you’ll get a Notice: Undefined offset: etc.

I have thought of a few reasons to want this today, but my current function is almost a clone of isset except it will check if any of the args are set, rather than all like isset(a,b,c) does.

function anyset()
{
    $argc = func_num_args();
    $argv = func_get_args();
    for ($i = 0; $i < $argc; $i++) 
        if (isset($argv[$i])) return true;
    else return false;
}

Now, I have for example a giant 2d array of [x][y], into which values will be placed at random. I need to check the randomized co-ords contains anything “next” to it (x-1,y-1 to x+1,y+1) etc.

I do not want to do a loop of 20,000,000 and initialise each variable. I just want to send 9 vars and check if any are already set.

while (anyset($items[$x-1][$y-1],$items[$x][$y-1],$items[$x+1][$y-1],
              $items[$x-1][$y],$items[$x][$y],$items[$x+1][$y],
              $items[$x-1][$y+1],$items[$x][$y+1],$items[$x+1][$y+1]));

Like so.

I could just do isset(x) || isset(x) || isset(x) but that doesn’t look very nice.

Is there a way to allow undefined variables to pass to my function without raising errors?

Not interested in taking the easy option 😉

Thanks for reading!

\o

Update: 12 April 2012, 21:03
Looks like there is no special feature allowing this to happen. So either pass like anyset(@$array[0], @$array[1]) etc, or just wrap everything in a thousand issets like so:

while (isset($items[$x-1][$y-1]) || isset($items[$x][$y-1]) || isset($items[$x+1][$y-1]) || 
       isset($items[$x-1][$y])   || isset($items[$x][$y])   || isset($items[$x+1][$y]) || 
       isset($items[$x-1][$y+1]) || isset($items[$x][$y+1]) || isset($items[$x+1][$y+1]));

Hope this helps someone else in the future!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:52:13+00:00Added an answer on June 1, 2026 at 5:52 pm

    You have three options:

    • Use isset to handle the logic properly (isset($x) || isset($y) || isset($z))
    • Wrap everything in isset() and then have your function check if any of the arguements are true (kind of bleh)
    • Use @ to suppress errors (also bleh)

    An example of @ would be:

    function a($a) { } a(@$x);
    

    You should remember though that notices exist for a reason. I avoid error suppressing. It seems hacky to me. I would just properly wrap everything in isset(). It’s a lot more verbose, but also, in my opinion anyway, more correct.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a pretty simple question really, but let's say I'm creating a model
This might be a pretty simple question, but if there really is a difference,
This is pretty simple question, but I'm having really hard time with it. I
I know this question seems subjective but it's really pretty simple. As a long
A pretty simple question really. Are queries consistent across instances? I understand that with
This is a really simple question concerning a method. I'm pretty new to C#
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
Pretty simple question. I've got some Polygons and GroundOverlays defined in KML. Is there
This is a pretty simple question but I'm somewhat stumped. I am capturing sections
I have a pretty simple question which perhaps someone familiar with Server/Client design &

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.