在PHP类中创建cURL方法

I'm trying to create a class that uses cURL to make requests to the Twitter API. I've done some research on object oriented programming in PHP, and I can't quite figure out how this should work. The following code returns NULL:

 <?php

    class twitter {

      public function curlQuery($url) {
      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HEADER, 0);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);

      $json = curl_exec($ch);

      curl_close($ch);

      $array = json_decode($json);
      return var_dump($array);
      }
}

$object1 = new twitter;
$object1->url = "http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2";
$object1->curlQuery($object1->url);

 ?>

Also, I'm a little unsure when to use $this->variable vs $variable in a PHP class. Shouldn't all variables mentioned in an class be referenced as $this->variable? Why would you ever not want to reference the variable of the current object?

查看全部
duanpu8830
duanpu8830
2012/06/09 05:22
  • oop
  • curl
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复