View Full Version : Cannot redeclare class

05-06-2004, 07:56 AM
I am trying to write my php page using Object and Class. some how I get this error, I went on google and cannot find any answer.

anyone know why?

Fatal error: Cannot redeclare class sql in C:\htdocs\Class\SQL.php on line 2

class SQL{ //line 2

05-06-2004, 08:28 AM
The error means that you have 2 classes called SQL in your code, which isn't permitted by the parser. Most likely you are including this file somewhere else where a class "SQL" is already defined. Check your include(_once) and require(_once) statements in all files that include your class file. Another error source could be that you have auto_append_file activated and that another file with such a class definition is included automatically for every file you have on this server. Check that setting in the output of phpinfo().

05-06-2004, 09:02 AM
I don't see anywhere in my code included sql class twice. how do I check the include once thing?


auto_append_file no value(local) no value(master)

05-06-2004, 08:46 PM
Then post your complete code please, and the version of PHP you're using. It's not an auto_prepend/append thing though.

05-06-2004, 09:22 PM
A quick check could be to change the name of the class from SQL to SQL_c or something. It could be that there's a built-in class called SQL already?

Of course everywhere you call SQL right now, you'll have to change it to SQL_c. I would maybe recommend stepping through your code yourself instead of find/replace, as it may help you to find the problem (perhaps its something we haven't thought of and you might be able to catch it with your keen eyes!).

If you get the same error except instead of SQL, it points to SQL_c then you are defining it twice somewhere, and you'll have to look more closely. If you don't get the error anymore, then SQL may be a "reserved word" in the sense that another class is already called SQL and you can't call it that.

Let us know what you come up with or if you're still having troubles.


05-06-2004, 10:17 PM
What I would do is create a page with nothing else on it except:

class SQL {


and test that... if it says you cant redefine then it is probably built in.

05-07-2004, 12:07 AM
FWIW, naming your class SQL is perfectly valid. At least it is on my PHP 4.3.4 installation. Checking include_once is same as looking for include/require statements, it does the same, but has the useful advantage of not including a file a second time if it's already been included.