cannot use variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bimmerboy85
Forum Newbie
Posts: 4
Joined: Tue Mar 02, 2004 3:47 pm
Location: Bath, OH, USA

cannot use variable

Post 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
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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;
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

require could also be good if u want to make sure that they r included
bimmerboy85
Forum Newbie
Posts: 4
Joined: Tue Mar 02, 2004 3:47 pm
Location: Bath, OH, USA

Post by bimmerboy85 »

there is the problem, when I call it it tells me the variable is not defined.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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! :)
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

Are you using functions on these pages ???
bimmerboy85
Forum Newbie
Posts: 4
Joined: Tue Mar 02, 2004 3:47 pm
Location: Bath, OH, USA

Post by bimmerboy85 »

yes, but i am not calling the variable from within a function.
User avatar
Dr Evil
Forum Contributor
Posts: 184
Joined: Wed Jan 14, 2004 9:56 am
Location: Switzerland

Post by Dr Evil »

Could you show us the code please?
bimmerboy85
Forum Newbie
Posts: 4
Joined: Tue Mar 02, 2004 3:47 pm
Location: Bath, OH, USA

i figured it out!

Post 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
Post Reply