SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Intermittant "cannot redeclare class" chaos, from server to server

    I develop on Mint Linux localhost.

    I (usually) install on a CentOS virtual dedicated server. I try to keep both regularly updated. But codes from localhost often produce a "cannot re-declare class" error on CenOS apache2 even when relevant files are referenced with either include_once or require_once.

    I can fix that error (on the server) by trial and error removal of offending include statements. But that limits the portability of the included modules in other contexts. This must be a bug. Has anybody else seen the same behavior?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Sounds like you're sometimes including a file multiple times, which doesn't work if there is a class in that file, because it would effectively re-declare the class (as the error says).

    A few pointers:
    • It is always the same class you get this error with or are there several classes?
    • Does it always happen at the same point or on different points?
    • Are you maybe trying to declare class that is already installed in PHP on one server but not on the other?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=ScallioXTX;5582879]Sounds like you're sometimes including a file multiple times, which doesn't work if there is a class in that file, because it would effectively re-declare the class (as the error says).

    Yes this indicates including a file more than once. But (I thought) that was supposed to be avoided with "include_once("whatever.php");
    That's how we did it 20 years ago with C

    #ifndef whatever.h
    include whatever.h

    .....No????

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,097
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    IIRC, when using include_once, you must always use include_once. If you first include and then include_once you still get an error.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2009
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll have to try to replicate the error. I never "include" anything. I always "include_once" or "require_once"
    I never mix the two. I use grep and command-line perl to keep it consistent.


Bookmarks

Posting Permissions

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