为什么用opendir打开目录用户require_once 加载文件会报错

从此不换网名 2018-06-20 06:05:12
谢谢大神帮忙看看错在那里
错误提示代码:
( ! ) Fatal error: Cannot declare class logincheckentry, because the name is already in use in'd:/web/system/autofile/logincheckentry.php on line 15



<?php
$dir = 'd:/web/system/autofile/'; // 这个目录下只有一个文件 logincheckentry.php
if ($dh = opendir($dir))
{
while (($autofile = readdir($dh)) !== false)
{
//略过linux目录的名字为'.'和‘..'的文件
if($autofile != '.' && $autofile != '..')
{

//strrchr() 函数查找字符串在另一个字符串中最后一次出现的位置,并返回从该位置到字符串结尾的所有字符
$fix = substr(strrchr($autofile, '.'), 1);
if($fix == 'php')
{
require_once $dir.$autofile;
} //加载文件,把文件写入编译HX110里
}
}
closedir($dh);
}




加载的文件logincheckentry.php

class logincheckentry{

function __construct(){

$this->index();
}
function index()
{
echo "加载成功";

}
}


...全文
191 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
M51921 2018-06-30
  • 打赏
  • 举报
回复
你那判断只写一个等号,肯定了。。
木秀猿林 2018-06-22
  • 打赏
  • 举报
回复
你是不是多次加载了这个文件啊
xuzuning 2018-06-21
  • 打赏
  • 举报
回复
Cannot declare class logincheckentry, because the name is already
是说 类 logincheckentry 的定义已经存在了
同名类不能多次定义,这是基本规则

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧