{"id":6824,"date":"2014-04-23T08:10:02","date_gmt":"2014-04-23T08:10:02","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/23\/fatal-error-call-to-a-member-function-api-on-a-non-object-collection-of-common-programming-errors\/"},"modified":"2014-04-23T08:10:02","modified_gmt":"2014-04-23T08:10:02","slug":"fatal-error-call-to-a-member-function-api-on-a-non-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/23\/fatal-error-call-to-a-member-function-api-on-a-non-object-collection-of-common-programming-errors\/","title":{"rendered":"Fatal error: Call to a member function api() on a non-object-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m running this code and I&#8217;m getting the following message:<\/p>\n<p>&#8220;Fatal error: Call to a member function api() on a non-object in&#8221;<\/p>\n<p>The line it refers to is the one just below where I write <code>global $facebook<\/code>. The facebook object is initialised in a config.php file which I include in my Database.php file, which I have linked in. I have researched this problem and it seems that it comes about when your <code>$facebook<\/code> is declared outside a function and you use it inside without making it global. As you can see, I have made it global, and I have even tried doing it without making it global &#8211; both result in that error.<\/p>\n<p>Does anyone know why?<\/p>\n<p>p.s. I don&#8217;t even see why it needs to be global since if config.php is included in my Database.php file, and that is included in the code below, then isn&#8217;t the $facebook object within the scope of this code?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m running this code and I&#8217;m getting the following message: &#8220;Fatal error: Call to a member function api() on a non-object in&#8221; The line it refers to is the one just below where I write global $facebook. The facebook object is initialised in a config.php file which I include in my Database.php file, which I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6824","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6824"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6824\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}