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
    Feb 2007
    Posts
    217
    Thanks
    25
    Thanked 1 Time in 1 Post

    using variable in two functions

    I've got a public function in which I call an other function, in this function some values are stored in the variable $dompydom. Now I want to use this same variable within my public function. I don't know how to do this though.

    I've got this setup (simplified):

    Code:
    public function index() {
    
    $this->otherf();
    echo $dompydom;
    
    }
    
    
    function createimages(){
    
    $dompydom="blablabla";
    
    }
    But the echo'ing in the public function doesn't return anything. How can I solve this?

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,091
    Thanks
    51
    Thanked 506 Times in 493 Posts
    There are two main ways around this..

    You either need to make the variable global by declaring it global in both functions OR make it available to everything by storing it somewhere such as a database or session variable. Using the session is IMO the better option as it will mean less strain on the database server.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    docock (05-19-2013)


  •  

    Posting Permissions

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