简体   繁体   中英

Fatal error: Cannot redeclare class (PHP)

I'm having big problems with this fatal error. I have 5 files and every of them contains one class (Nationality.php, Team.php, BoughtTickets.php, Users.php, Tickets.php) and two of them require other classes.

So here is index.php

<?php

require 'header.html';
require 'pages/first.html';
require 'class/db.php';

$c=DB::connect();

require 'pages/footer.html';
?>

Users.php

require 'Nationality.php';
require 'Team.php';
require 'BoughtTickets.php';

class Users{
    public $Email;
    public $Name;
    ...

BoughtTickets.php

require 'Tickets.php';

class BoughtTicket{

    public $IDTicket;
    public $Date;
    ...

Eveytime I want to login, it gives me fatal error. If I remove line require 'BoughtTickets.php'; from class Users, it works, but it won't display table in one file which requires class BoughtTickets.php. Do you have any idea what to do to solve the problem?

Thank you

使用require_once代替require

You may come across this error if you have something like

class C
{
}

class B extends A
{
}

class A
{
}

尝试使用include_once而不是require。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM