title: Violation of Liskov's Substitution Principle
body: <p>How is this example below violating Liskov's Substitution Principle? I still can't get my head around it. It seems ok to me in terms of hierarchy in PHP OOP.</p>
  
  <pre><code>// Violation of Likov's Substitution Principle
  class Rectangle
  {
      protected $width;
      protected $height;
  
      public function setWidth($width){
          $this-&gt;width = $width;
      }
  
      public function setHeight($height){
          $this-&gt;height = $height;
      }
  
  
      public function getWidth(){
          return $width;
      }
  
      public function getHeight(){
          return $height;
      }
  
      public function getArea(){
          return $this-&gt;width * $this-&gt;height;
      }   
  }
  
  class Square extends Rectangle 
  {
      public function setWidth($width){
          $this-&gt;width = $width;
          $this-&gt;height = $width;
      }
  
      public function setHeight($height){
          $this-&gt;width = $height;
          $this-&gt;height = $height;
      }
  
  }
  </code></pre>
  
  <p>usage:</p>
  
  <pre><code>$Rectangle = new Rectangle();
  $Rectangle-&gt;setWidth(5);
  $Rectangle-&gt;setHeight(10);
  echo $Rectangle-&gt;getArea(); // 50 --&gt; correct
  </code></pre>
  
  <p>Another:</p>
  
  <pre><code>$Rectangle = new Square();
  $Rectangle-&gt;setWidth(5);
  $Rectangle-&gt;setHeight(10);
  echo $Rectangle-&gt;getArea(); // 100 --&gt; correct
  </code></pre>
  
  <p>The reuslt from both are correct.</p>
  
  <p>So, how this code should be written so that it is not violating Liskov's Substitution Principle?</p>