title: Inheritance and Overriding typed properties
body: <p>I am trying to make wild things with inheritance in PHP. I e.g. the following code, which doesn't work</p>
  <pre><code>class Animal {
      public Food $food;
  }
  
  class Cat extends Animal {
      public Fish $food; //so this part doesn't work, eventhough Fish extends from Food
  }
  
  class Dog extends Animal {
      public Meat $food; //so this part doesn't work, eventhough Meat extends from Food
  }
  
  class Food {
      public int $weightInKilograms;
  }
  
  class Fish extends Food {
      public bool $isSaltWaterFish;
  }
  class Meat extends Food {
      public bool $isRawMeat;
  }
  </code></pre>
  <p>So how can i make the part work, where i put my comment in the code above? I don't understand why this shouldn't work since ChildX IS also the same like SuperX if it extends SuperX.</p>
  <p>I get the following error:</p>
  <blockquote>
  <p><br /> <b>Fatal error</b>:  Type of Cat::$food must be Food (as in
  class Animal) in <b>[...][...]</b> on line <b>6</b><br /></p>
  </blockquote>