I have 5 scripts, say: database.php, parent.php, child1.php, child2.php and somescript.php
The parent.php class is as follows:
include 'database.php'; class Parent { public $db; function __construct() { $this->db = new Database(); } }
The child1 and child2 classes look like this:
include 'parent.php'; class Child1 extends Parent { function __construct() { parent::__construct(); } function useDb() { $this->db->some_db_operation(); } }
Problem
When I try to include child1 and child2 in somescript.php, it returns the following error:
cannot declare a class database, because the name is already used in database.php on line 4 (this is a line containing a database of word classes)
But if I include only one file (child1 or child2), it works fine.
How to fix it?
oop php
egorik
source share