1. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Rep Power

    Is spl_autoload_register() too lazy

    Do you recommend using spl_autoload_register(), or should I always include require_once()?

    PHP Code:
    spl_autoload_register(function ($class) {
    What about when the parent class exists in the same directory as the child class? Also, include a "require_once", or don't bother?
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    this is perfectly fine and actually opens you up for a much more sane filestructure. I've worked at companies with thousands of class files, child classes, etc. The autoloaders become very useful when your classes are actually located in hundreds of directories with the paths determined by the class name.

    Comments on this post

    • PaulGer agrees
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo