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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:01:58+00:00 2026-05-30T06:01:58+00:00

Hey so I got tired of writing echo varname message; var_dump(variable); So I wrote

  • 0

Hey so I got tired of writing

echo "varname message";
var_dump(variable);

So I wrote this

function debugger($var, $message) {
    echo $message;
    var_dump($var);
    echo "<br />";
}

Which seems to work fine, except when its in a function. Then its like it doesn’t know that there’s a function defined, because its defined outside of the function. Like so.

function blah() {
    $x = 2;
    debugger($x, "this is x");
}

Also, I don’t understand functions, I knew you cant reference something in a function outside of the function without returning it, but I didn’t know you couldn’t reference variables or functions outside of the function without setting them as parameters. I think I have this wrong though.

So one more thing, does that mean that the variables inside of a function don’t conflict with the ones outside a function unless its returned?

  • 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-30T06:02:00+00:00Added an answer on May 30, 2026 at 6:02 am

    Your code should work. Something else is wrong in your code. Try being more precise about what is not working and try isolating your problem. As for your other questions:

    Variables defined in a function are scoped to that function, and will not interfere with variables from other functions. They also cannot access variables defined outside the function. For example

    $a = 5;
    function foo() {
        echo $a; //This will not work
    }
    

    What you can do is use the global keyword to “include” variables into your function’s scope, if you don’t want to pass them as arguments:

    $a = 5;
    function foo() {
        global $a;
        echo $a;
    }
    

    Or since a certain version of PHP (not sure which, if anyone knows please edit), you can use use:

    $a = 5;
    function foo() use ($a) {
        echo $a;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I got this error message when I tried to trigger the function
Hey Friends i got all contacts detail of my iphone by using this function
Hey there, i got this very annoying problem: I have a CheckBoxList getting items
Hey I have got data in my variable using foreach($report as &rep) note it
Hey, I've got this nice little piece of code, much like all the other
Hey guys, I got this JS code and want to add a slight fade
Hey guys i got a problem which is doing my head in, and was
Hey I got this xml array: <resources> <string-array name=colors> <item>BLUE</item> <item>CYAN</item> <item>DARK_GRAY</item> <item>GRAY</item> <item>GREEN</item>
hey guys i have got this far with a chat system but now i
Hey I got the following ps for retrieving the site template from SharePoint,but I

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.