[英]Fatal error: Cannot redeclare class Login in C:\xampp\htdocs\includes\classes\class.login.php on line 3
I'm working on a login. 我正在登录。 As the base I took PHP-Login because it provides a lot of stuff at forehand. 作为基础,我选择了PHP-Login,因为它直接提供了很多东西。 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: 查看class.login.php
的前几class.login.php
我没有看到任何错误:
<?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. 如果有人看到错误,请告诉我。
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: 这可能有多个原因:
You included php code that declares a class of the same name 您包括了声明同名类的php代码
You included the file "class.login.php" twice using include() or require() instead of include_once() or require_once(). 您使用include()或require()而不是include_once()或require_once()两次包含了文件“ class.login.php”。 *_once() functions will make sure that contained code is only considered once (as the name suggests) to avoid such errors. * _once()函数将确保所包含的代码仅被考虑一次(顾名思义),以避免此类错误。
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. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.