F
F
firecorer2022-02-12 22:01:53
PHP
firecorer, 2022-02-12 22:01:53

How to import two classes if they repeat imports of the same class?

I tried to google, honestly.

Error in index.php:
Fatal error : Cannot declare class Database, because the name is already in use in /opt/lampp/htdocs/Model/Database/Database.php on line 3

Index.php file imports:

require_once($_SERVER['DOCUMENT_ROOT'] . '/Model/Email/Email.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/Model/Goods/Goods.php');
require_once($_SERVER['DOCUMENT_ROOT'] . '/Model/Database/Database.php');


Imports of the Model/Email/Email.php file:
include($_SERVER['DOCUMENT_ROOT'] . '/Vendor/autoload.php');
include($_SERVER['DOCUMENT_ROOT'] . '/Model/Database/Database.php');


Imports of the Model/Goods/Goods.php file:
include($_SERVER['DOCUMENT_ROOT'] . '/Model/Database/Database.php');


It is clear that it is possible to remove imports of the Database class somewhere, but I feel that there should be a prettier solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2022-02-12
@firecorer

include_once () use and why the heck is there generally an insertion of classes when there is autoload?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question