Jump to content

How to use variables from other included files


georgefl

Recommended Posts

Hy!

I have 3 files:

 

file 1 (index.php) includes 2 files: file2.php and file3.php

 

File2.php contains $aditionalStuff and in file3.php I want to use $aditionalStuff, but it wont work (like it wasn't initialized).

 

How can I make this work?

 

index.php

include "file2.php";
include "file3.php";

 

file2.php

$aditionalStuff = 'some stuff';

 

file3.php

echo $aditionalStuff;

 

Thanks!

Anyway in file3.php you didnt include file2.php i think.

 

Edit: If you get index.php only its working, but if you get file3.php it has a problem

 

I do not want to include file2 in file3. That's the problem.

And no, my example doesn't work. I have error reporting activated.

Just post your actual code to get the quickest help with why it is not working.

 

There's several million php web sites where what you are doing works.

 

Either your include statements are failing or the few lines of code you posted out of context are either not being executed or they have a different variable scope from where the variable is set.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.