Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    381
    Thanks
    150
    Thanked 2 Times in 2 Posts

    PHP Notice: Undefined property: stdClass::$comments - how to correct it?

    Hello, I am getting this info in my error log:

    Code:
    PHP Notice:  Undefined property: stdClass::$comments in /mysite/public_html/wp-content/themes/theme/functions.php on line 797
    The code is the following:
    PHP Code:
    function full_comment_count() {
    global 
    $post;
    $url get_permalink($post->ID);

    $filecontent file_get_contents('https://graph.facebook.com/?ids=' $url);
    $json json_decode($filecontent);
    $id $json->$url->id;
    $comments file_get_contents('https://graph.facebook.com/' $id '/comments?summary=true');
    $jsoncomments json_decode($comments);
    $count $json->$url->comments;
    $wpCount get_comments_number();
    $realCount $count $wpCount;
    if (
    $realCount == || !isset($realCount)) {
        
    $realCount 0;
    }
    return 
    $realCount;

    The line 797 is the following:
    PHP Code:
    $count $json->$url->comments
    I am using this function several months already and it's working fine.
    Does anybody sees anything wrong in this code? What does it mean? Is it possible to correct it somehow?

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    maybe you mean $json->url->comments?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #3
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    381
    Thanks
    150
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Dormilich View Post
    maybe you mean $json->url->comments?
    hmm, I didn't get the question...

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    just a stab in the dark.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    381
    Thanks
    150
    Thanked 2 Times in 2 Posts
    anybody else has any idea?

  • #6
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    since we don’t know what $url or $json is, I guess no.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #7
    Regular Coder
    Join Date
    Oct 2008
    Location
    Poland
    Posts
    381
    Thanks
    150
    Thanked 2 Times in 2 Posts
    $json is the content of for example 'https://graph.facebook.com/?ids=http://google.com

    $url is for example http://google.com
    =====
    In my specific case instead than google url, is the link of my site.
    This function merges the count of Wordpress comments with the number of facebook comments, and gives the sum.
    For example. If a page has 2 wordpress comments, and 3 facebook comments. The $realcount is 5.

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,133
    Thanks
    12
    Thanked 332 Times in 328 Posts
    since PHP complains about a missing property, first thing I’d check (var_dump()) is what the object actually contains.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •