Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cannot redeclare class

    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

    <?php
    class SQL{ //line 2

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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().
    De gustibus non est disputandum.

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Canada, Ontario, Mississauga
    Posts
    312
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't see anywhere in my code included sql class twice. how do I check the include once thing?

    phpinfo();

    auto_append_file no value(local) no value(master)
    Last edited by weronpc; 05-06-2004 at 09:08 AM.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Then post your complete code please, and the version of PHP you're using. It's not an auto_prepend/append thing though.
    De gustibus non est disputandum.

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Sadiq.

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I would do is create a page with nothing else on it except:

    PHP Code:
    <?php
    class SQL {

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

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    De gustibus non est disputandum.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •