Cannot access $image->alt() in image block

I am having the weirdest problem (that I know of, that is).
In my installation (v4.5.0 in a local environment) I use a layout field and therein blocks, of course.
The image block works fine—as long as I don’t try to retrieve the image’s alt text.
I am working with a custom image block, but even reducing it to the following for testing, the problem persists:

<?php if ($image = $block->image()): ?>
  <?= $image->alt() ?>
  <?= $image->toFile() ?>
<?php endif ?>

The column with the image block renders completely empty. Removing the line with the alt, the image shows in the frontend.
Whether the alt text field of the image contains text or not doesn’t make any difference.

Same goes for a caption field I added to the image file blueprint.

I am pretty sure, that there is some simple oversight on my part. But I just cannot find it.
Thus, any help is appreciated.

What’'s inside $image? I would think a Field object, not a File object. At least not until you call ->toFile(). And you want to call ->alt()on the file, not on the field. The if statement also doesn’t make a lot of sense like this, cause it will always return a field and that will always evaluate to true.

Should it be

<?php if ($image = $block->image()->toFile()): ?>

?

Thank you, Nico.
You are exactly right. (Of course.)

I don’t know how I came to think, that it would work the way I tried it.
(Maybe that’s the aftermath of me being sick over the weekend. :grimacing:)