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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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
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?
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.