1,105,371 Community Members

Facebook Notification API error

Member Avatar
nunuaziz_
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Been getting PHP Fatal error: Cannot redeclare class Facebook error since...

Can anyone please enlighten what does this means?

Member Avatar
pritaeas
mod_pritaeas
11,291 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,832 [?]
Skill Endorsements: 155 [?]
Moderator
Featured
Sponsor
 
0
 

Cannot redeclare class Facebook

You cannot redeclare an existing class.

Member Avatar
veedeoo
Veteran Poster
1,009 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 164 [?]
Skill Endorsements: 17 [?]
 
0
 

UPDATE! this will only work to check if the class exists, but will not be able to check if there is an instance of the class already been instantiated.. try looking into this PHP function called instanceof.

you can also create a simple conditional checkpoint.. this is important in real world practice, because as your application gets bigger, you will not be able to track all of the instances going on and off within your appplication.

one method is to use an autoload or to use any of the 5 design patterns e.g. factory,,singleton,observer,chain of command and strategy patterns.
second, is to check if the class exist before actually initializing it. For example, we can put this on top of the php document requiring a class file and needing an instance of that class..

if (class_exists('FaceBookAPI'){
include_once ('location_of_facebook_API_class');
$fb_class = new FaceBookAPI();
}

To learn more about this method, please read my reference.

Here are some of the php functions that can help and can save dosages of headache medication :). I lifted them here..

method_exists() - Checks if the class method exists

is_callable() - Verify that the contents of a variable can be called as a function

get_defined_functions() - Returns an array of all defined functions

class_exists() - Checks if the class has been defined

extension_loaded() - Find out whether an extension is loaded

You can also prevent this from happening to other classes in your application by creating an instance manager script..

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: