title: Pass a parent class as a parameter to a function
body: <p>This is a basic PHP question, and somehow I couldn't find any information about it.</p>
  
  <p>So what I'm trying to do is to pass a parent class to a function so all of its children class can be passed too.</p>
  
  <p>Is there anyway to do it?</p>
  
  <pre><code>function transform(Fruit $fruit){}
  
  transform($orange)
  transform($apple)
  </code></pre>
  
  <hr>
  
  <p>Update : </p>
  
  <p>Looks like I need to show the situation more.</p>
  
  <p>So what I have is a transformer parent </p>
  
  <pre><code>class ResourceTransformer{
      public function transform(ResourceModel $model){}
  }
  </code></pre>
  
  <p>And its child</p>
  
  <pre><code>class ColorTransformer extends ResourceTransformer{}
  </code></pre>
  
  <p>Now what I want to do is passing ColorModel, a child of ResourceModel to ColorTransformer.</p>
  
  <pre><code>class ColorModel extends ResourceModel{}
  </code></pre>
  
  <p>when I'm doing that it throws an error like this:</p>
  
  <pre><code>Type error: Argument 1 passed to App\\Modules\\Product\\Transformer\\ResourcesTransformer::transform() must be an instance of App\\Modules\\Product\\Models\\ResourceModel, instance of App\\Modules\\Product\\Models\\ColorModel given.
  </code></pre>
  
  <p>So basically, ColorTransformer can't accept ColorModel and only accept ResourceModel, yet ColorModel is a child of ResourceModel. Might be some of you can give me more enlightement.</p>