php - __autoload() vs include,will __autoload() output something? -
i developing programm , it's based on third-party.i write class , use __autoload() load class. program runs following:
1.i upload script remote server.
2.the third-party server request script param.
3.my script return str , third-party server check str,if str same param,it's valid,if not,it's not valid.
now,the problem is:
when use __autoload(),it raise error , when replace __autoload include/require run exactly.
code following:
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(); ?>
addition,my php version 5.4.i test script long , find both __autoload() , include work in php 5.2,but not in php 5.4.
think if there bugs in php,but can't decide.
hope describe question , sorry bad english.
the answer is:
include "./wechat/".strtolower($classname).".class.php";
it try include wechat.class.php otherwise (with uppercase w, not exist file.
Comments
Post a Comment