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?
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?
[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
IIRC, when using include_once, you must always use include_once. If you first include and then include_once you still get an error.
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.
This topic is now closed. New replies are no longer allowed.