n8dog
asked on
Fatal error: Cannot redeclare class db in db.cls on line 2
when i used the code at the bottom of the file the class is physically in, it works fine.
if i include or require the class file, instantiate, and use the object, it gives me this error:
Fatal error: Cannot redeclare class db in /home/lifelock/lib/common/ class/db.c ls on line 2
The db.cls is a class that contains the access to the database..
WTF??
if i include or require the class file, instantiate, and use the object, it gives me this error:
Fatal error: Cannot redeclare class db in /home/lifelock/lib/common/
The db.cls is a class that contains the access to the database..
WTF??
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
>>One thing I never really understood is the difference between require_once and include_once
You need to understand the differenct between include and require, which is very well documented on the php site:
require() includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for include().
require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
As for the require_once and include_once, they behave the same as the require and include except that a file will be "imported" at most once.
You need to understand the differenct between include and require, which is very well documented on the php site:
require() includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for include().
require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless.
As for the require_once and include_once, they behave the same as the require and include except that a file will be "imported" at most once.
So to answer your question about the problem, you should do what hielo says, i.e. using require_once() / include_once()