You are here: Re: class dependence « PHP Programming Language « IT news, forums, messages
Re: class dependence

Posted by ZeldorBlat on 05/29/07 20:52

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!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация