autoload() issue

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
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

autoload() issue

Post by jmut »

I am using autoload() to automatically include class.
What happens when I am using external class (from PEAR) for example.
Should hardcode in autoload() external class that I use and the it should load them?


P.S. Actually I cannot hardcode extgerna class...as this class might call other stuff :(
What should I do
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

utilize the include_path settings?
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

feyd wrote:utilize the include_path settings?
Yep that was the problem.
I just added my classes' path to include path and it all worked like a charm.
10xy
duk
Forum Contributor
Posts: 199
Joined: Wed May 19, 2004 8:45 am
Location: London

Post by duk »

when you meen "autoload()"

is something like this ?? im trying to understand when you mean autoload what it is in fact...

Code: Select all

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

$obj  = new MyClass1();
$obj2 = new MyClass2();
?>
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

duk wrote:when you meen "autoload()"

is something like this ?? im trying to understand when you mean autoload what it is in fact...

Code: Select all

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

$obj  = new MyClass1();
$obj2 = new MyClass2();
?>
exactly


just before I did something like

Code: Select all

function __autoload($class_name) {
   require_once CLASS_PATH.$class_name . '.php';
}
and now I just included CLASS_PATH to include path and did it as you mention. (PEAR style....replacing "_" with "/")
So that external classes run as well :)
Post Reply