Home php Error: CANNOT REDECLARE CLASS

Error: CANNOT REDECLARE CLASS

Author

Date

Category

I have an error “CANNOT REDECLARE CLASS SYSTEM”. This means that something is wrong with the SYSTEM class, and what?

Added from the comment.

I have no more than such class. Maybe it is called several times?

function __autoload ($ class)
{
  If ($ Class = "System") {
    $ class_dir = "System / System.php";
  } else {
    $ class_dir = 'System / Classes /'. $ Class. '.class.php';
  }
  If (! File_exists ($ class_dir)) {
    Exit ("On the site there is no class: & lt; b & gt;" $ Class. "& lt; / b & gt; it is necessary for the script work.");
  } else {
    REQUIRE $ CASS_DIR;
  }
}
$ Index = New System;

Answer 1, Authority 100%

This means that the class with the name System in your code is trying to determine the second time.

class system {// Determined the class "SYSTEM"
  ...
}
// still a little or a lot of code
...
Class System {// What, again?! - error.
  ...
}

upd. If this is a copy-past of the original code, then the error:

if ($ class = "System")

D. to be two signs of equality == for comparison. Otherwise, it simply assigns the variable $ Class The value "System" and if will always true . Now your autoload is creating the System class again and again, hence the error.

Correct

if ($ class == "System")

Answer 2, Authority 33%

Often, this error occurs due to the fact that you are two or more times try to enable the same file directive Include or Require . As a result of PHP, the parser is trying again and again to disassemble the previously entered definitions of classes and override them.

To avoid this situation, use INCLUDE_ONCE or REQUIRE_ONCE .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions