cannot use variable
Moderator: General Moderators
-
bimmerboy85
- Forum Newbie
- Posts: 4
- Joined: Tue Mar 02, 2004 3:47 pm
- Location: Bath, OH, USA
cannot use variable
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
Thanx,
AP
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;-
bimmerboy85
- Forum Newbie
- Posts: 4
- Joined: Tue Mar 02, 2004 3:47 pm
- Location: Bath, OH, USA
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.Deemo wrote:require could also be good if u want to make sure that they r included
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!
-
bimmerboy85
- Forum Newbie
- Posts: 4
- Joined: Tue Mar 02, 2004 3:47 pm
- Location: Bath, OH, USA
-
bimmerboy85
- Forum Newbie
- Posts: 4
- Joined: Tue Mar 02, 2004 3:47 pm
- Location: Bath, OH, USA
i figured it out!
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
$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