这个有什么具体点要求么?这样写有什么错么?
比如根目录下有个 index.php 和 class文件夹,class文件夹里有个ipdo.class.php,定义了个iPDO类。在index.php中:// 自动加载
function __autoload($class_name) {
$class = strtolower($class_name);
$class_path = "./class/".$class.".class.php";
if(file_exists($class_name)) {
require_once "$class_path";
}else {
echo "没有类名:$class_path";
}
}
$iPdo=new iPDO();为什么不可以呢?!!!!
比如根目录下有个 index.php 和 class文件夹,class文件夹里有个ipdo.class.php,定义了个iPDO类。在index.php中:// 自动加载
function __autoload($class_name) {
$class = strtolower($class_name);
$class_path = "./class/".$class.".class.php";
if(file_exists($class_name)) {
require_once "$class_path";
}else {
echo "没有类名:$class_path";
}
}
$iPdo=new iPDO();为什么不可以呢?!!!!
if(file_exists($class_path)) {
要风清楚class_name 跟包含class的 file
这里有什么要注意的吗。PHP版本是5.2~~
在线等
THX
function __autoload($class_name) {
$class = strtolower($class_name);
echo './class/',$class,'.class.php';
if(file_exists('./class/'.$class.'.class.php')) {
require_once $class_path;
}else {
echo "没有类名:$class_path";
}
}看看有没有输入,如果有输出还不正确,可能是你的路径错了,否则把错误贴上来
moocky 你的$class_path没有定义。嘿嘿。
function __autoload($class_name) {
$class = strtolower($class_name);
echo './class/',$class,'.class.php';
if(file_exists('./class/'.$class.'.class.php')) {
require_once './class/'.$class.'.class.php';
}else {
echo "没有类名:$class_path";
}
}
==,else里边的$class_path依然没有定义。
<?
function __autoload($class_name) {
$class = strtolower($class_name);
$class_path = "./class/".$class.".class.php";
if(file_exists($class_path)) {
require_once "$class_path";
}else {
echo "没有类名:$class_path";
}
}
$iPdo=new iPDO();
$iPdo->callBack("hiahaihidfe");
?>
class.ipdo.php
<?
class ipdo{
private $time;
public function __construct($time=null){
if(empty($time)){
$this->time=time()-3600;
}
else{
$this->time=$time;
}
} function callBack($content){
echo "time = ".$this->time;
echo "date = ".date("Y-m-d H:i:s",$this->time);
echo "content = ".$content." for test";
} }
?>
但是在这个project下,依然还是不成!!!!!!!!烦躁死了。代码和上面一模一样,但还是提醒找不到类!!!郁卒哈
囧SHI了。哎
基础不过关呐、~~~自掴