Page 1 of 1

cannot use variable

Posted: Tue Mar 02, 2004 3:47 pm
by bimmerboy85
Hi I have 3 pages called page1.php, page2.php and page3.php. page1.php requires page2.php and page2.php requires page3.php. However, page1.php cannot access variable $page3_variable. Is this a bug or do I just need to have page1.php load page3.php?

Thanx,
AP

Posted: Tue Mar 02, 2004 3:58 pm
by infolock
you just need to include them.

Code: Select all

include('page2.php');

// then call the variables.  if the variable is $bob, call it.

echo $bob;

Posted: Tue Mar 02, 2004 4:13 pm
by Deemo
require could also be good if u want to make sure that they r included

Posted: Tue Mar 02, 2004 11:35 pm
by bimmerboy85
there is the problem, when I call it it tells me the variable is not defined.

Posted: Wed Mar 03, 2004 2:12 am
by m3mn0n
Deemo wrote:require could also be good if u want to make sure that they r included
The two constructs are identical in every way except how they handle failure. [php_man]include[/php_man]() produces a Warning while require() results in a Fatal Error. In other words, use [php_man]require[/php_man]() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well. Be warned that parse error in required file doesn't cause processing halting.

I recommend you [php_man]require_once[/php_man]() both of those scripts. I'd love to explain why this is better but that what manuals are for! :)

Posted: Wed Mar 03, 2004 3:55 am
by Dr Evil
Are you using functions on these pages ???

Posted: Wed Mar 03, 2004 3:54 pm
by bimmerboy85
yes, but i am not calling the variable from within a function.

Posted: Thu Mar 04, 2004 2:04 am
by Dr Evil
Could you show us the code please?

i figured it out!

Posted: Sat Mar 13, 2004 7:51 pm
by bimmerboy85
here is a little example of what i was trying to do:

$the_var_i_was_trying_to_access = "holds valuable info";

function da_function() {
$the_var_i_was_trying_to_access = "i am kinda retarded";
}


yeah, i just kinda slow

thanx y'all