So I have 3 classes in this situation.
Connection.php
Engineer.php
Status.php
Both Engineer and Status classes actually use connection. Hasn't been a problem but now that I'm using both classes in a page I'm getting
Fatal error: Cannot redeclare class Connection
Is there a way round this? In both classes I need db access from the connection class.
Thanks,
Jonesy
Use require_once() rather than require().
Or alternatively, use autoload, which saves you having to specify it loads of times.
I suspect the autoload functionality would be the best thing for you, assuming you're using a new-enough version of PHP (it requires 5.3).
You are probably using an unsafe class file inclusion method, such as
require
orinclude
.Try using
include_once
orrequire_once
.Use require_once.
well, how are you including the Connection.php? try using
require_once
.instead of using include() use require_once() for importing Connection.php into Engineer.php and Status.php.
You can always:
or just use
include_once
(link) orrequire_once
(link) or autoload mechanism