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 7075619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:11:57+00:00 2026-05-28T06:11:57+00:00

Extension from https://stackoverflow.com/a/55191/547210 I am creating a validating function to check several attributes of

  • 0

Extension from https://stackoverflow.com/a/55191/547210
I am creating a validating function to check several attributes of string variables, which may or may not have been set. (One of the attributes which is checked)
What I am trying to do with the function is receive arguments an unknown number of arguments in the form (See below), and suppress errors that may be caused by passing an unset variable.
I’m receiving the variables like validate([ mixed $... ] ) by using func_get_args()
The previous post mentioned that it was possible by passing by reference, now is this possible when the variables are passed implicitly like this?

  • 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-05-28T06:11:57+00:00Added an answer on May 28, 2026 at 6:11 am

    If you pass a variable that is not set in the calling scope, the array returned by func_get_args() will contain a NULL value at the position where the variable was passed, and an error will be triggered. This error is not triggered in the function code itself, but in the function call. There is, therefore, nothing that can be done to suppress this error from within the code of the function.

    Consider this:

    function accepts_some_args () {
      $args = func_get_args();
      var_dump($args);
    }
    
    $myVar = 'value';
    accepts_some_args($notSet, $myVar);
    
    /*
      Ouput:
    
      Notice: Undefined variable: notSet in...
      array(2) {
        [0]=>
        NULL
        [1]=>
        string(5) "value"
      }
    */
    

    As you can see, the variable name notSet appears in the error, telling us that the error was triggered in the caller’s scope, not that of the callee.

    If we want to counter the error, we could do this:

    accepts_some_args(@$notSet, $myVar);
    

    …and prefix the variable names with the evil @ operator, but a better solution would be to structure our code differently, so we can do the checks ourselves:

    function accepts_some_args ($args) {
      var_dump($args);
    }
    
    $myVar = 'value';
    
    $toPassToFunction = array();
    $toPassToFunction[] = (isset($notSet)) ? $notSet : NULL;
    $toPassToFunction[] = (isset($myVar)) ? $myVar : NULL;
    
    accepts_some_args($toPassToFunction);
    
    /*
      Ouput:
    
      array(2) {
        [0]=>
        NULL
        [1]=>
        string(5) "value"
      }
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a small function that allows me to remove the extension from
What I want to do is trigger a function from an extension/GM Script once
I created a project with Google Code, checked it out from https://stackexchange.googlecode.com/hg/ using the
I found it inside the symphony CMS app, it's very small: https://github.com/symphonycms/xssfilter/blob/master/extension.driver.php#L100 And I
I'm using version 2.1 of Aquamacs and django-mode from https://github.com/myfreeweb/django-mode . I installed it
I am following a tutorial here http://www.blackweb20.com/2010/01/11/creating-your-own-google-chrome-extension/ I can open fine a tab with
I have a bunch of XSD's from https://github.com/XeroAPI/XeroAPI-Schemas/tree/master/v2.00 I need to do two things:
I cant seem to request this url: https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=dogs from my popup.html. I'm getting: XMLHttpRequest
I noticed some odd behaviour when using the strongly typed HtmlHelper.ActionLink() extension method from
I'm using some custom tasks from MSBuild Extension Pack (MEP). My projects are splitted

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.