繁体   English   中英

__autoload()与include,__ autoload()是否会输出?

[英]__autoload() vs include,will __autoload() output something?

我正在开发一个基于第三方的程序,我编写了一个类并使用__autoload()加载该类。 程序运行如下:
1.我将脚本上传到远程服务器。
2.第三方服务器会要求我的脚本获取一些参数。
3.我的脚本返回str,第三方服务器将检查str,如果str与get参数相同,则该字符串有效,否则,该字符串无效。
现在,问题是:
当我使用__autoload()时,它将引发一些错误,当我将__autoload替换为include / require时,它将自动运行。
代码如下:

wechat.class.php

        public function __construct($options){
            $this->_token=isset($options['token'])?$options['token']:'';
        }

        public function test(){
            var_dump($this->_token);
        }

        private function checkSignature(){
            $signature = isset($_GET["signature"])?$_GET["signature"]:'';
            $timestamp = isset($_GET["timestamp"])?$_GET["timestamp"]:'';
            $nonce = isset($_GET["nonce"])?$_GET["nonce"]:'';

            $token = $this->_token;
            $tmpArr = array($token, $timestamp, $nonce);
            sort($tmpArr, SORT_STRING);
            $tmpStr = implode( $tmpArr );
            $tmpStr = sha1( $tmpStr );

            if( $tmpStr == $signature ){
                return true;
            }else{
                return false;
            }
        }

        public function valid($return=false){
            $echostr=isset($_GET['echostr'])?$_GET['echostr']:'';
            if($return){
                if($echostr){
                    if($this->checkSignature()){
                        return $echostr;
                    }else{
                        return false;
                    }
                }else{
                    return $this->checkSignature();
                }
            }else{
                if($echostr){
                    if($this->checkSignature()){
                        die($echostr);
                    }else{
                        die('no access');
                    }
                }else{
                    if($this->checkSignature()){
                        return true;
                    }else{
                        die('no access');
                    }
                }
            }
        }

    }
?>

wechat.php

<?php
    function __autoload($classname){
        include "./wechat/".$classname.".class.php";
    }
    $options=array(
            'token'=>'tudouya',
        );
    $wechat=new Wechat($options);
    $wechat->valid();
?>

另外,我的php版本是5.4。我测试了这个脚本很长时间,发现__autoload()和include都可以在php 5.2中正常工作,但在php 5.4中不能正常工作。
我什至认为php中是否有错误,但我无法决定。
希望我能清楚地描述我的问题,并对我的英语不好对不起。

答案是:

include "./wechat/".strtolower($classname).".class.php";

否则,它将尝试包含Wechat.class.php(带有大写字母w,该大写字母w作为文件不存在。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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