Avoiding downcasting in PHP

This is a theoretical problem that bothers me. Let’s say we have following, simplified structure:

interface ParagraphInterface {}  interface ParagraphGroupInterface {     public function getParagraphs(): array; }  interface ParagraphRendererInterface {     public function render(ParagraphInterface $  paragraph): string; }  abstract class Paragraph implements ParagraphInterface {     public $  id; }  class ParagraphText extends Paragraph {     public $  body; }  class ParagraphImage extends Paragraph {     public $  path; }  class ParagraphGroup implements ParagraphGroupInterface {     public function getParagraphs(): array     {         return [/* Some paragraphs */]     } }  class ParagraphTextRenderer implements ParagraphRendererInterface {     public function render(ParagraphInterface $  paragraph): string     {         // How to have here `ParagraphText` as a type in the argument without downcasting?     } }  class ParagraphImageRenderer implements ParagraphRendererInterface {     public function render(ParagraphInterface $  paragraph): string     {         // How to have here `ParagraphImage` as a type in the argument without downcasting?     } }  class ParagraphGroupRenderer {     /** @var ParagraphRendererInterface[] */     private $  renderers = [/* Array of renderers*/];      public function render(ParagraphGroupInterface $  paragraphGroup): string     {         $  output = '';         $  paragraphs = $  paragraphGroup->getParagraphs();         foreach ($  paragraphs as $  paragraph) {             $  output .= $  this->renderers[get_class($  paragraph)]->render($  paragraph);         }         return $  output;     } } 

So basically as we can see, we have group of paragraphs that we would like to render (transform into string). Each paragraph has its own renderer, that is responsible for extracting data from the Paragraph object and create a string out of it.

It seems natural for renderers to have injected objects of classes that they are actually rendering, but that’s impossible with the above structure without downcasting. At some point, downcasting seems to be unavoidable, at least assuming this structure, and these layers.

Can this structure be reconstructed in such a way that would allow for renderers to have injected specific paragraph classes/interfaces they are suppose to render, and at the same time avoid downcasting by usage of instanceof conditions and such? Are there any patterns that would be better here, and that would avoid downcasting?