Previous and next links with image and text

I have a portfolio of projects. At the bottom of each project I’d like links to the ‘previous’ and ‘next’ projects (and for the last project to link to the first, and the first project to link to the last). I’ve done this. But now I’d like to include the main image (I’ve called ‘portfolio_thumbnail’), heading and subheading of the previous and next projects. But I’m getting a PHP error ‘Undefined variable: next’. Here’s what I’ve got:

TEMPLATE

<ul class="portfolio">
	<li>
		<?php if ($prev = $page->prevListed() ?? $page->siblings()->listed()->last()): ?>
			<a href="<?= $prev->url() ?>">
				<?= $prev->content()->get('portfolio_thumbnail')->toFile() ?>
				<p><strong><?= $prev->heading() ?></strong><br><?= $next->subheading() ?></p>
			</a>
		<?php endif ?>
	</li>

	<li>
		<?php if ($next = $page->nextListed() ?? $page->siblings()->listed()->first()): ?>
			<a href="<?= $next->url() ?>">
				<?= $next->content()->get('portfolio_thumbnail')->toFile() ?>
				<p><strong><?= $next->heading() ?></strong><br><?= $next->subheading() ?></p>
			</a>
		<?php endif ?>
	</li>
</ul>

BLUEPRINT

title: Case study pages

columns:
	main:
		width: 2/3
		
		fields: 

			heading:
				label: Heading
				type: text

			subheading:
				label: Sub heading
				type: text

	sidebar:
		width: 1/3

		sections:
			section1:
				type: fields
				fields:
					portfolio_thumbnail:
						label: Portfolio thumbnail
						type: files
						max: 1
						layout: cardlets
						image:
							back: white

Also, how do I pull in the ALT text associated with the portfolio_thumbnail image?

I had a typo. This works

<ul class="portfolio">
	<li>
		<?php if ($prev = $page->prevListed() ?? $page->siblings()->listed()->last()): ?>
			<a href="<?= $prev->url() ?>">
				<?php if ($image = $prev->portfolio_thumbnail()->toFile()): ?>
					<img src="<?= $image->url() ?>" alt="<?= $image->alt() ?>">
				<?php endif ?>
				<p><strong><?= $prev->heading() ?></strong><br><?= $prev->subheading() ?></p>
			</a>
		<?php endif ?>
	</li>

	<li>
		<?php if ($next = $page->nextListed() ?? $page->siblings()->listed()->first()): ?>
			<a href="<?= $next->url() ?>">
				<?php if ($image = $next->portfolio_thumbnail()->toFile()): ?>
					<img src="<?= $image->url() ?>" alt="<?= $image->alt() ?>">
				<?php endif ?>
				<p><strong><?= $next->heading() ?></strong><br><?= $next->subheading() ?></p>
			</a>
		<?php endif ?>
	</li>
</ul>