PHP HTTP request class I would like to get you opinion on this class, which is used to send HTTP requests (at that moment only POST method).

It is working ok, but I would like to get response on maintainability, reusability, security, code formatting, etc...

Class HttpRequest{

    private $POST = 'POST';
    private $PUT = 'PUT';
    private $GET = 'GET';
    private $DELETE = 'DELETE';
    private $PATCH = 'PATCH';

    private $body;
    private $options;
    private $handle;
    private $httpCode;
    private $response;

    public function __construct(){}


    /**
     * send post request
     * @param url 
     * @param header 
     * @param options
     * @param body
     * @return json object
     */
    public function post($url, $header, $options, $body){
        if(!$this-&gt;handle || get_resource_type($this-&gt;handle) == "Unknown"){
            $this-&gt;handle = curl_init(); 
        }
        curl_setopt($this-&gt;handle, CURLOPT_URL, $url);
        curl_setopt($this-&gt;handle, CURLOPT_HTTPHEADER, $header);
        curl_setopt_array($this-&gt;handle, $options);
        // curl_setopt($this-&gt;handle, CURLOPT_SSL_VERIFYPEER, true);
        // curl_setopt($this-&gt;handle, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($this-&gt;handle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this-&gt;handle, CURLOPT_CUSTOMREQUEST, $this-&gt;POST);
        curl_setopt($this-&gt;handle, CURLOPT_POSTFIELDS, $body);
        $this-&gt;response = curl_exec($this-&gt;handle);
        $this-&gt;httpCode = curl_getinfo($this-&gt;handle, CURLINFO_HTTP_CODE);
        curl_close($this-&gt;handle);
        return $this-&gt;response;
    }


    public function getResponse(){
        return $this-&gt;response;
    }

    public function getHttpCode(){
        return $this-&gt;httpCode;
    }

    /**
     * send get request
     * @param url 
     * @param header 
     * @param options
     */
    public function get($url,$header=array(), $options=array()){
        /**
         * @todo 
         * implemets this method
         */
    }

    /**
     * send patch request
     */ 
    public function patch(){
        /**
         * @todo 
         * implemets this method
         */
    }
    /**
     * send delete request
     */
    public function delete(){
        /**
         * @todo 
         * implemets this method
         */
    }
    /**
     * send put request
     */
    public function put(){
        /**
         * @todo 
         * implemets this method
         */
    }
}

?&gt;
Use class constants to store values that will remain the same and are unchangeable

Your HTTP method verbs are better off set as class constants than class properties since they will remain the same and are unchangeable. (i.e. constant)

private $POST = 'POST';
private $PUT = 'PUT';
private $GET = 'GET';
private $DELETE = 'DELETE';
private $PATCH = 'PATCH';


becomes

const POST = 'POST';
const PUT = 'PUT';
const GET = 'GET';
const DELETE = 'DELETE';
const PATCH = 'PATCH';


You can then refer to them using self

self::POST


No need for an empty constructor

If your contractor doesn't have any code in it you could, and should omit it. It's just noise otherwise. You can always add it if the constructor definition changes.   

Be sure to use docblock comments for your class properties    

Not just class methods should have well written docblock comments, so should your class properties.

/**
 * @var string The body of the HTTP request
 */
private $body; 


Follow PSR coding standards    

The PSR coding standards exist to ensure a high level of technical interoperability between shared PHP code. They also ensure conformity for projects with multiple developers. 

PSR-2  says that:


  Opening braces for classes MUST go on the next line, and closing braces MUST go on the next line after the body.
  and
  Opening braces for methods MUST go on the next line, and closing braces MUST go on the next line after the body.


Class HttpRequest{


becomes

Class HttpRequest
{


and 

public function post($url, $header, $options, $body){


becomes

public function post($url, $header, $options, $body)
{


Use type hinting to variable types in class methods    

From the manual:


  Type declarations allow functions to require that parameters are of a certain type at call time. If the given value is of the incorrect type, then an error is generated


To use your code as an example, you can declare that $url must be a string and $header and $options must be arrays. This will be enforced by PHP at run time and prevent obvious and non obvious errors from occurring.

public function get($url,$header=array(), $options=array()){


becomes

public function get(string $url, array $header=[], array $options=[])
{


(I used shortened array syntax [] versus the more verbose array() for brevity.)    

Use return type declarations

Just like you can enforce that class method parameters are a certain data type, you can also enforce the value returned by that method is a certain data type. Since all of your methods are stubs I'll pretend your HttpRequestget() method returns a Boolean to use as an example.

public function get(string $url, array $header=[], array $options=[]): bool
{


Now my calling code will know that a Boolean, and only a Boolean value, will be returned by that method.    

When doing comparisons use === whenever possible

Unlike == which compares values only, === compares both values and type. This strict comparison helps to avoid error, and attacks, that occur when PHP encounters a comparison of two variables of different types it will coerce one of the variables into the type of the other variable in order to do the comparison.

For example

1 == '1'  // true
1 === '1' // false


How much does this matter? It depends. If you get into a situation where you are getting numbers as strings but you are trying to use them as numbers, for something like sorting, you can get unexpected results if your check only checks value instead of type. And those of us who remember phpBB remember when it was subject to a slew of high profile vulnerabilities many of which were resolved simply by using a stricter comparison. So, yes, it matters.