tags:

views:

67

answers:

6

Is it possible to make my class file be already included in all files of a folder?

A: 

www.php.net/require_once

FractalizeR
+7  A: 

Have a look at:

Autoloading Classes Using __autoload() (offical Docs)

Example:

function __autoload($class_name) {
    require_once $class_name . '.php';
}

$obj  = new MyClass1();
$obj2 = new MyClass2(); 
Sarfraz
+2  A: 

Try using class autoloading: http://www.php.net/manual/en/language.oop5.autoload.php

Very useful

Mchl
+4  A: 

You can also automatically prepend files using auto_prepend_file - set the path in php.ini, httpd.conf or an .htaccess file:

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it was called with the require() function, so include_path is used.
Ken
+1  A: 

there is also auto_prepend_file configuration option
so, you can add an .htaccess file (in case you're running PHP as Apache module) to that folder with following line:

php_value auto_prepend_file /path/to/that/file
Col. Shrapnel
A: 

Besides using the already mentioned autoloading of classes you could also specify a file with auto_prepend_file in a .htaccess file that is loaded before:

php_value auto_prepend_file foo.php

With this the file foo.php is loaded whenever a PHP file in that directory or a subdirectory is requested.

Gumbo