1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

'daisy chain' includes - doesn't work?

Discussion in 'PHP' started by Greg-J, Apr 13, 2006.

  1. #1
    I'm not sure how I've never come across this before, but here goes.

    I have index.php which has:
    include('backend.php')
    PHP:

    I have backend.php which has
    include('config.php')
    PHP:

    Now, when I define a variable in config.php, I can use it in backend.php. When I define a variable in backend.php, I can use it index.php. Why then, when I define a variable in config.php - can I not use it in index.php?
     
    Greg-J, Apr 13, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You may need to define the variables in the config.php file as global in order for them to pass up the chain.

    In the manual for include(), the php developers state -- somewhat unhelpfully:

    Perhaps, more helpfully, when the phpers talk about scope they add:

    I know this is not quite an answer, But, I hope it helps.
     
    clancey, Apr 13, 2006 IP
  3. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #3
    The variables should be global across includes by default. I do multi-level includes like that and it isn't a problem. Are you maybe resetting the variable somewhere?
     
    TheHoff, Apr 13, 2006 IP
  4. Greg-J

    Greg-J I humbly return to you.

    Messages:
    1,844
    Likes Received:
    153
    Best Answers:
    0
    Trophy Points:
    135
    #4
    Interesting. It seems to work fine on my *nix boxes, but the wamp stack I use for testing just doesn't like it.

    Is it a php.ini setting perhaps?
     
    Greg-J, Apr 13, 2006 IP
  5. TheHoff

    TheHoff Peon

    Messages:
    1,530
    Likes Received:
    130
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ahh no comment on WAMP :) Uncharted waters for me.
     
    TheHoff, Apr 13, 2006 IP