• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1094
  • Last Modified:

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)");
  }
}
0
jerrylmclaughlin
Asked:
jerrylmclaughlin
1 Solution
 
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
 
Rob_JeffreyCommented:
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now