title: A simpler way to write the calculator class in OOP PHP
body: <p>I have created a class called Calculator with the add, subtract, multiply and divide function. The calculator is limited to adding two numbers and returning the result.
  I am relatively new to OOP,would like to get some input on the class, did i take the long route and if i did is there another way to simplify the class.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>class Calculator {
      private $_val1 , $_val2;
  
      public function __construct($val1, $val2){
          $this-&gt;_val1 = $val1;
          $this-&gt;_val2 = $val2;
      }
  
      public function add(){
          return $this-&gt;_val1 + $this-&gt;_val2;
      }
  
      public function subtract(){
          return $this-&gt;_val1 - $this-&gt;_val2;
      }
  
      public function multiply (){
          return $this-&gt;_val1 * $this-&gt;_val2;
      }
  
      public function divide () {
          return $this-&gt;_val1 / $this-&gt;_val2;
      }
  }
  
  $calc = new Calculator(3,4);
  echo "&lt;p&gt;3 + 4 = ".$calc-&gt;add(). "&lt;/p&gt;";
  
  $calc = new Calculator (15,12);
  echo "&lt;p&gt;15 - 12 = ".$calc-&gt;subtract(). "&lt;/p&gt;";
  
  $calc = new Calculator (20,2);
  echo "&lt;p&gt; 20 * 2 = ".$calc-&gt;multiply(). "&lt;/p&gt;";
  
  $calc = new Calculator (20,2);
  echo "&lt;p&gt; 20 / 2 = ".$calc -&gt;divide(). "&lt;/p&gt;";
  </code></pre>