tags:

views:

63

answers:

1

I'm having a problem with this spl_autoload and a static method. The constructor in this class requires two params to function. I'm new to autoload and static classes so I'm out of my league a bit here. Hopefully someone can shed some light on this for me.

Here is the call:

if(captcha::validate($post))...

If I require the class apart from the spl_autoload function, it works as expected. If I let autoload handle it, as it should, the script dies with this message:

Fatal error:  Class 'captcha' not found...

Can someone tell me what I am doing wrong here?

A: 

Here is the official manual of spl_autoload

Or try below function:

function my_autoload($className, $extList='.inc,.php') {
  $ext = explode(',',$extList);
  foreach($ext as $x) {
    $fname = $className.$x;
    if(@file_exists($fname)) {
        require_once($fname);
        return true;
    }
  }
  return false;
}
Sarfraz
I looked at that already and it is like looking for a needle in a haystack (No pun intended) :) Anyway, I searched the page for anything having to do with static classes but didn't find anything useful.
Jim
@Jim: If you can, you should provide more code with your question so that it makes more sense and possibly someone could come up with solutions. Thanks
Sarfraz
Thanks Sarfraz. I think I'm getting closer to the problem though. I may not even need any help from here. The code snippet that you posted simply loads the classes. The code that I am currently using is from the same place you got that code, only I'm using the first example where PHP handles everything through its own internal functions. Here is what I did and got no errors...
Jim
spl_autoload_extensions() is the current function that I'm using that handles the loading of the classes. Somehow it isn't working properly but when I include the class directly, which is exactly what your code snippet does, it works fine and doesn't die. I think I will use your code and forgo what I have.
Jim
@Jim: That is great news then :)
Sarfraz