dqrmkdu25623 2014-06-15 20:27
浏览 47
已采纳

致命错误:无法在第3行的C:\ xampp \ htdocs \ includes \ classes \ class.login.php中重新声明类登录

I'm working on a login. As the base I took PHP-Login because it provides a lot of stuff at forehand. Now I'm getting this error:

Fatal error: Cannot redeclare class Login in C:\xampp\htdocs\includes\classes\class.login.php on line 3

When looking at the first few lines of class.login.php I don't see any mistakes:

<?php
class Login {
    private $db_connection = null;
    public $errors = array();
    public $messages = array();
    public function __construct() {
        if (isset($_GET["logout"])) {
            $this->doLogout();
        }
        elseif (isset($_POST["login"])) {
            $this->dologinWithPostData();
        }
    }

If anyone sees the error, please tell me.

  • 写回答

1条回答 默认 最新

  • dps123456789 2014-06-15 20:35
    关注

    The error message indicates that a class of that name is already declared when this part of the code is reached. This can have multiple reasons:

    1. You included php code that declares a class of the same name

    2. You included the file "class.login.php" twice using include() or require() instead of include_once() or require_once(). *_once() functions will make sure that contained code is only considered once (as the name suggests) to avoid such errors.

    3. You are using a class loader and screwed it up. If this was the case my strong advice is to go without dynamic class loading. It is difficult to read and understand and adds "magic" to the behaviour of your code which in most cases is only clear to one person in the world - to you. Code should be easy to read and understand though.

    I hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1