即時嘗試在抽象類有一個很好的做法方法,所以我創建了一個簡單的捲曲包裝類,但不幸的是它不工作。
抽象使用抽象類的簡單捲曲包裝方法?
<?php
abstract class curl{
private $url;
public function __construct($url){
$this->url = $url ;
}
public function curl_grab_page()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
ob_start(); // prevent any output
return curl_exec ($ch); // execute the curl command
ob_end_clean(); // stop preventing output
curl_close ($ch);
}
public abstract function getHTML();
}
?>
孩子
<?php
class google extends curl{
private $url;
function __construct($url) {
parent::__construct($url);
}
function curl_grab_page(){
parent::curl_grab_page();
}
function getHTML(){
return $this->curl_grab_page();
}
}
,這是我在頭版怎麼稱呼。
<?php
include 'classes/class.curl.php';
include 'classes/class.google.php';
$google = new google('http://www.google.com/');
echo $google->getHTML();
?>
它沒有打印出任何東西。
我單獨審判的功能和它去細
'new $ google' =>'new NULL' =>致命錯誤...丟棄'$'。 – Wrikken
嘗試:'$ google = new google('http://www.google.com/');' –
我確實沒有放棄它,但仍然沒有任何 –