cURL을 사용하여 Twitter API에 요청하는 클래스를 만들려고합니다. 필자는 PHP에서 객체 지향 프로그래밍에 대한 연구를 해왔습니다. 그리고 이것이 어떻게 작동하는지 알아 내지 못합니다. 다음 코드는 NULL 반환PHP 클래스에서 cURL 메서드 만들기
<?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);
?>
을 또한, PHP 클래스에서 $variable
대 $this->variable
을 사용할 때 좀 확실 해요. 어떤 클래스에서 언급 된 모든 변수가 $this->variable
으로 참조되어야합니까? 왜 현재 객체의 변수를 참조하고 싶지 않으십니까?
나는 코드가 작동하는지 테스트했다. – flowfree
클래스의 함수를 단순히 래핑하는 것입니다. OOP의 관점에서 여기에서 알아야 할 것이 없습니다. – Alexander
'$ json'을 항상 var_dump하여 반환 된 데이터가 실제로 있는지 알아낼 수 있습니다. 그러면 범인에 대해 더 잘 알 수 있습니다. – Strawberry