Avatar of n8dog
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.cls on line 2

The db.cls is a class that contains the access to the database..

WTF??
PHP

Avatar of undefined
Last Comment
hielo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
NesFuratu

One thing I never really understood is the difference between require_once and include_once.... they both seem to include the file anyways.

So to answer your question about the problem, you should do what hielo says, i.e. using require_once() / include_once()
hielo

>>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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes