Declare Class Twice

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
blodder24
Forum Newbie
Posts: 7
Joined: Wed Nov 26, 2008 4:18 pm

Declare Class Twice

Post 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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Declare Class Twice

Post 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.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: Declare Class Twice

Post 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 :wink:
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Declare Class Twice

Post 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.
Post Reply