Curious question about php tags

Hi there, been a long time since I last used php and I just stumbled upon a curious question.
This code produces an ‘unexpected error’:

<?= if ($hero_image = $page->hero_img()->toFile()): ?>
<img src="<?= $hero_image->url() ?>" srcset="<?= $page->hero_img()->toFile()->srcset([300, 800, 1024])?>" alt="" />
<?= endif ?>

This works:

<?php if ($hero_image = $page->hero_img()->toFile()): ?>
<img src="<?= $hero_image->url() ?>" srcset="<?= $page->hero_img()->toFile()->srcset([300, 800, 1024])?>" alt="" />
<?php endif ?>

Why is this the case? To my understanding short tags were ok to use by now. My local dev environment is running on php 7.3.8

I feel like I am missing something and would be very happy for some enlightenment :see_no_evil:

This is the short echo tag, which is the same as the long form <?php echo. Using that with an if-statement doesn’t make sense.

Contrary to the short echo tag, PHP short tags <? as in <? if ($this == $that) { //... ; }?>, however, should be avoided.

Thank you very much for explaining! I probably should read up on basics again.