Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Setting a var to global from another function not work?

    Hey guys..... what am I doing wrong here? This is basically what I am doing in less code..

    PHP Code:
    function foo () {
     
    $var $_SESSION['blah'];
     
    $yeah do_stuff();
    }

    function 
    do_stuff() {
     global 
    $var;
     echo 
    $var// Outputs ""

    Ok.. I understand that the reason it's not working is because $var isn't available to the secondary function to make global because it is only available locally inside foo(); but any way to get it inside do_stuff() without passing it as an argument?

    Thanks!

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    no, you should pass it as an argument.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

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