Re: Procedural Autoloader?

From: Date: Mon, 22 Nov 2010 21:59:57 +0000
Subject: Re: Procedural Autoloader?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-309629@lists.php.net to get a copy of this message
On Nov 22, 2010, at 4:24 PM, Daniel P. Brown wrote:
On Mon, Nov 22, 2010 at 15:37, Jason Pruim <lists@pruimphotography.com> wrote:
Hey Everyone! Fresh off my problem with functions and arrays I come across something that I can't seem to find currently... The autoloader function that is in PHP 5+ works on classes... But I'm not finding anything that would do the same thing on the procedural end... Such as I have a folder typically called includes in my projects where I place all my function files... I would LOVE to use the autoloader to be able to just load them on demand... But in my quick searching/thinking I haven't found away too... So I thought I would see if anyone had invented that wheel yet before I go and try and do it my self :) I may also have a misunderstanding of how it is supposed to work since I don't truly understand OOP I've always done procedural... Any help on this one would be greatly appreciated it! :)
There's no such thing, Prune. Autoloaders are for classes, and the only way you could have it work for functions would be to catch the error in the core and handle it at a lower level than your scripts (modified core or extension), because the error generated for an undefined function isn't a catchable fatal. Alternatively, you *could* write a function wrapper that utilizes function_exists() and the like, then rewrite all of your code to use that wrapper.... but how much sense does that make? ;-P
How much sense do I ever make? :P Maybe it's time to get a book on OOP and start learning the concept.. Or find a better way to load my functions so I don't have to have 1 huge functions file or tons of includes if I have them all separate... Or maybe I can just bastardize classes enough to make something work :P I think most of my functions border on classes anyway... Off to google to see if I'm right! :)

« previous php.general (#309629) next »