Click to See Complete Forum and Search --> : A member variables Wich are a instance of an other class


WinSeb
07-08-2004, 12:03 PM
Hello
I 've got a little question :

I have one class: food and an other : meal .

In my class food I 'd like to declare a member variables : meal1 wich are an instance of meal (meal meal1=new meal (); ).

The problem is that the 2 classes (food and meal ) are not in the same file so the meal's constructor is unknwon of food .

Is there anything that I cando except include (meal.class.php) ???

Thanks
Have a nice day
SEB

planetsim
07-08-2004, 09:25 PM
Well that is the only way. If the class isnt included even if you made the class PHP isnt going to be able to find and and throw a Undefined Object at you.

Moonglobe
07-08-2004, 11:11 PM
declare a global function __autoload($classname) { } with all the required code to load any class passed to it. then, when an unknown class is encountered, PHP will automatically call the function.