constructor in require/include functions

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
rozvinbm_jp
Forum Commoner
Posts: 43
Joined: Thu Jun 14, 2007 8:36 pm
Location: Fuji-shi, Shizuoka-ken, Japan

constructor in require/include functions

Post by rozvinbm_jp »

There is a constructor that execute first before require/include function? like __constructor in class...

purpose:
I want to call a function inside the phpfile.php before or upon execution of require('phpfile.php'); to load all the initial variables needed by all php file.

Code: Select all

<?php
//phpfile.php
function constructorfunc (){
    const(WORKINGFOLDER, "c:");
    //.....................
}
?>

<?php
//test.php
require('phpfile.php');
echo WORKINGFOLDER;
?>
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

When you include / require a file, you are essentially adding all of the code from that file into the current one, so all you have done is made the function available to the first file, not created a constant.
rozvinbm_jp
Forum Commoner
Posts: 43
Joined: Thu Jun 14, 2007 8:36 pm
Location: Fuji-shi, Shizuoka-ken, Japan

Post by rozvinbm_jp »

yes, I understand..
after require function..
I just call the function next to require function..

Thank you very much..
Post Reply