I received a Fatal Error in PHP5- Fatal error: Cannot redeclare class invalidargumentexception What does this mean? How do I fix it?


The code is below. What does this mean?

class InvalidArgumentException extends Exception
{
  function __construct($in_argname)
  {
    parent::__construct("We're sorry, but an internal programming error has occurred in the web application.  The system administrators have been notified of the error and we kindly request that you try again in a little while. (param: $in_argname)");
  }
}
jerrylmclaughlinAsked:
Who is Participating?
 
Rob_JeffreyIT/ProgrammingCommented:
You can simply place a test around the declaration to absolutely ensure it is only declared once.

if (!defined('CLASS_INVALIDARG_SET')) {
  define('CLASS_INVALIDARG_SET', 'yup');

  class InvalidArgumentException extends Exception
  {
    function __construct($in_argname)
    {
      parent::__construct("We're sorry, but an internal programming error has occurred in the web application.  The system administrators have been notified of the error and we kindly request that you try again in a little while. (param: $in_argname)");
    }
  }


I use unique include file names for each file I include in the app.  If I screw up and include a file more than once the structures and functions/classes only get delared once.  This is lazy programming, but it works.
0
 
TomeeboyCommented:
It sounds like your class has already been defined and it's trying to define it a second time.  Make sure that the file which contains this class is not accidentally getting included twice in your script.
0
 
BogoJokerCommented:
I agree with Tomeeboy.
If that is the case you can use the function: include_once()
That will help stop including a script multiple times.

Joe P
0
 
jerrylmclaughlinAuthor Commented:
Thank you for responding. This is code is part of a larger include file. The include file is placed in a file with require_once() function, is this the same.

How do I use the include_once() function with above code?
0
 
jerrylmclaughlinAuthor Commented:
Thanks Rob - I tried it just as you placed it above and I got the same error message. I 'm going to try your other suggestion now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.