开发者

spl_autoload problem

开发者 https://www.devze.com 2022-12-15 11:06 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消