Page 1 of 1
Declare Class Twice
Posted: Sat Feb 21, 2009 2:42 pm
by blodder24
Hello,
I'm getting the error: "Fatal error: Cannot redeclare class session in..." because I am declaring the class session twice, in different files. Is there a way to allow it to be declared twice?
Thanks
Re: Declare Class Twice
Posted: Sat Feb 21, 2009 2:56 pm
by alex.barylski
No you cannot declare the same class twice...
use include_once to prevent the same class file from being included twice or re-work your code to fix this design problem.
Re: Declare Class Twice
Posted: Sun Feb 22, 2009 5:17 pm
by php_east
Code: Select all
if (!class_exists('USER'))
{
class USER
{
var $name;
var $age;
function USER()
{
}
}
} // end if not class_exists
declare as many times as your hearts desire
Re: Declare Class Twice
Posted: Sun Feb 22, 2009 5:23 pm
by josh
use require_once. You want an error to be thrown so if you mess up your code you won't keep moving forward blindly with bugs.