Jump to content


Photo

The class loader


  • Please log in to reply
2 replies to this topic

#1 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 07 October 2008 - 04:11 PM

PHP introduced a feature called autoloading. It allows you to specify a function that automatically loads classes when needed on the fly. This is to:
- prevent long lists of includes at the top of every script
- allow for cyclic dependencies
To further simplify stuff, I've developed a class loader utility class. You only include one file, tell the class where to find your classes (multiple directories supported!) and you're done.

Code and examples here:
http://www.bartvanhe...php/Classloader
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#2 Phil

Phil

    Force Majeure

  • Network Leaders
  • 7,976 posts
  • Location:Switzerland
  • Projects:Revora, C&C:Online
  •  Thought Police
  • Division:Revora
  • Job:Network Leader
  • Donated
  • Association

Posted 07 October 2008 - 04:34 PM

Not bad. I wanted to write a class with some more functionality (e.g. multiple directories) than the usual __autoload() for some time, I just never really needed it.

revorapresident.jpg
My Political Compass

Sieben Elefanten hatte Herr Dschin
Und da war dann noch der achte.
Sieben waren wild und der achte war zahm
Und der achte war's, der sie bewachte.


#3 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 08 October 2008 - 06:19 PM

on the site is a new version which:
- uses spl classes for searching the directory
- supports caching, which greatly improves speed
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users