|
Posted by Jon Slaughter on 05/29/07 21:23
"ZeldorBlat" <zeldorblat@gmail.com> wrote in message
news:1180471969.899593.68390@k79g2000hse.googlegroups.com...
> On May 29, 3:54 pm, "Jon Slaughter" <Jon_Slaugh...@Hotmail.com> wrote:
>> I have created a few classes which depend on other classes but I'm unsure
>> how to go about including the classes so they are visible to each other.
>>
>> Can I just require_once at some point before use and make sure the order
>> is
>> correct? or can I insert the require_once in the class itself(which then
>> I'm
>> worried about forcing the location)? How does one normally go about
>> this?
>>
>> Thanks,
>> Jon
>
> Use __autoload() -- it'll make your life a lot easier:
>
> <http://www.php.net/autoload>
>
> Here's what mine looks like (my files are named after my classes, so a
> class called Foo lives in a file called Foo.php):
>
> if(!function_exists('__autoload')) {
> function __autoload($class_name) {
> require_once($class_name . '.php');
> }
> }
>
> ini_set('unserialize_callback_func', '__autoload');
>
>
> Put all that in a file (call it autoload.php or something), then just
> require_once that file on all your pages. No need to include each
> class separately -- only things that are needed will be loaded (and in
> the right order, too). Problem solved!
>
Well, that is essentially what I'm doing. Since I have a central php file
that handles everything I can just require it in that and it will act the
same... the problem is that the order has to be right and so the dependence
could get screwed up ;/ Was trying to avoid it if possible.
I might try that though,
Thanks,
Jon
Navigation:
[Reply to this message]
|