We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,970 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Facebook Notification API error

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

Can anyone please enlighten what does this means?

3
Contributors
2
Replies
10 Hours
Discussion Span
3 Months Ago
Last Updated
3
Views
nunuaziz_
Newbie Poster
7 posts since Dec 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Cannot redeclare class Facebook

You cannot redeclare an existing class.

pritaeas
Posting Prodigy
Moderator
9,284 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,457
Skill Endorsements: 86

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

veedeoo
Master Poster
735 posts since Oct 2011
Reputation Points: 298
Solved Threads: 130
Skill Endorsements: 13

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0602 seconds using 2.71MB