Faqts : Computers : Programming : Languages : PHP : kms : Classes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 13 people (23%) answered Yes
Recently 1 of 10 people (10%) answered Yes

Entry

How can i acess a variable inside a class that was declared in other module(included by require/include) ?

Aug 25th, 2000 16:30
Ben Udall, Marcus Soares,


Any variables declared in files included/required are globally declared 
across all those files.  For example:
File: disp_conf.inc
<?
$bg_color   = '#000000';
$text_color = '#FFFFFF';
?>
File: script.php
<?
require('disp_conf.inc');
// After disp_conf.inc has been included,
// $bg_color and $text_color are set in this file too.
print("<HTML>\n");
print("<BODY bgcolor=\"$bg_color\" text=\"$text_color\">\n");
?>
The require() function essentially replaces itself with the PHP code 
found in the file specified. While the include() function causes the 
execution to branch to the file specified, then return to where it left 
off when the file is done.
Here are some links to the PHP manual pages:
http://www.php.net/manual/function.require.php
http://www.php.net/manual/function.include.php