Am I allowed to use the same argument names in a function within a class? For example, with $time_out as shown below…
public function SetTimeOut($time_out)
{
$this->SetOption(CURLOPT_TIMEOUT, $time_out);
}
public function SetConnectionTimeOut($time_out)
{
$this->SetOption(CURLOPT_CONNECTTIMEOUT, $time_out);
}
Okay, I think I’ve got a basic understanding of how to create classes in OOP. Since my site relies heavily on Curl, I’ve written a curl class with the help of some tutorials. Before I go ahead and add to it I need to know if I am on the right lines or not…
<?php
class Curl
{
public function __construct()
{
$this->curl = curl_init();
}
public function SetOption($option, $value)
{
$this->options[$option] = $value;
return curl_setopt($this->curl, $option, $value);
}
public function SetCookieFile($cookie_file)
{
$this->setOption(CURLOPT_COOKIEFILE, $cookie_file);
}
public function SetCookieJar($cookie_jar)
{
$this->SetOption(CURLOPT_COOKIEJAR, $cookie_jar);
}
public function SetURL($url)
{
$this->SetOption(CURLOPT_URL, $url);
}
public function SetProxy($proxy, $port)
{
$this->SetOption(CURLOPT_PROXY, $proxy);
$this->SetOption(CURLOPT_PROXYPORT, $port);
}
public function SetUserAgent($user_agent)
{
$this->SetOption(CURLOPT_USERAGENT, $user_agent);
}
public function SetTimeOut($time_out)
{
$this->SetOption(CURLOPT_TIMEOUT, $time_out);
}
public function SetConnectionTimeOut($time_out)
{
$this->SetOption(CURLOPT_CONNECTTIMEOUT, $time_out);
}
public function Get()
{
$this->SetOption(CURLOPT_CUSTOMREQUEST, 'GET');
$this->setOption(CURLOPT_HTTPGET, true);
return curl_exec($this->curl);
}
}
?>
One thing I am unsure about is the Curl Handler variables ($ch). In my old code is used within the curl_setopt functions, then later with the curl_exec() function. Do I not need to use any handler within this class, or is the handler now $this->curl ?