SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: variables

  1. #1
    SitePoint Guru
    Join Date
    Dec 1999
    Location
    Southampton, Hants, UK
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variables

    I've got a php page that I include in everypage on my site, its got variables declared with values at the top, and then functions i use, after including the page into my sites pages, when I use the functions the variables dont work, as in they are blank. How do i set them so they work within the functions aswell. do i declare them global or something? bearing in mind - they are all used in nearly all the functions.


    cheers

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Global them

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Guru
    Join Date
    Dec 1999
    Location
    Southampton, Hants, UK
    Posts
    672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how?

  4. #4
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrck
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    PHP Code:
    function doSomething($var1$var2)
    {
       global 
    $var1$var2// or the names of other variables from outside the function itself

    Last edited by Chris82; Mar 17, 2002 at 15:56.

  5. #5
    SitePoint Evangelist =X='s Avatar
    Join Date
    Jun 2001
    Posts
    487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this could bring up a discussion, but globalizing might not be such a good idea...

    better is to call the function with the vars as parameters

    function_name($var, $var, $var,...)
    PHP-Webservices - Profesional Hosting and Programming of sites.

  6. #6
    SitePoint Enthusiast MaRkY's Avatar
    Join Date
    Dec 2001
    Location
    Spain
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this could bring up a discussion, but globalizing might not be such a good idea...
    I think the same

  7. #7
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrck
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I read that topic in the Advanced section. There was quite some discussion going on.

    However, I tend to use global nonetheless.


Bookmarks

Posting Permissions

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