简体   繁体   中英

spl_autoload problem

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?

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM