Simple httpcode monitor I'm making a simple httpcode monitor as an example for teaching myself PHP OOP. I have written the code below and would be interested in having it improved.

In particular, I'm not sure about this line:

$httpcode = $website-&gt;get_httpcode($url);


This seems very inefficient to me as I have to to pass the URL back to the website class right after I have already done just that two lines above. Shouldn't it already remember its URL? That might be a dumb question, but in my mind, I've already made an object called website and given it a URL. Then if I want the httpcode of the URL, then I feel there should be some way for it to remember its URL which I passed two lines above.

class website {
var $url;

function __construct($url) {
    $this-&gt;url = $url;
}

public function get_url() {
    return $this-&gt;url;
}

public function get_httpcode($url) {
    //get the http status code
    $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
    $ch=curl_init();
    curl_setopt ($ch, CURLOPT_URL,$url );
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_VERBOSE,false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSLVERSION, 3);
    $page=curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    return $httpcode;
}
}

// create an instance of the website class and pass the url   
$website = new website("http://www.google.com");
$url = $website-&gt;get_url();
$httpcode = $website-&gt;get_httpcode($url);
Two things:


Always specify the visibility. Don't use the old var keyword, use public, private or protected. Since the class-member $url contains internal information, you'll probably want to hide that information (you've already implemented a getter method so that the information can be read but not written):

class website {
    protected $url;

    public function __construct($url) {
        $this-&gt;url = $url;
    }

    // ...

Every instance of this class seems to be meant to represent one website. But your method "get_httpcode()" works for every website (it expects a URL; this is exactly what you've already noticed by yourself). It would be more natural to skip the parameter and return the HTTP-Statuscode for the url that is bound to the instance (you've "remembered" the URL in the class-member variable $this-&gt;url):

class website {
    // ...

    public function get_httpcode() {
        // ...
        curl_setopt($ch, CURLOPT_URL, $this-&gt;url);
        // ...
    }
}

// Usage:
$google = new website("http://www.google.com");
$statusCode = $google-&gt;get_httpcode();