After adding my website to a new server, I keep getting a unexpected end of file error, but the file is identitcal to it’s original source

So the issue has already been resolved via the comments and the current state of the question already includes the corrected code. But I thought I should post this answer as a reminder for you, me and everyone reading this. 🙂

So first off, here’s a helpful excerpt from an article on WP Engine:

The “unexpected end of file” error is not specific to WordPress, and
can happen on any PHP-based website. This specific error means the file mentioned in the error message ends abruptly without the proper
closing tags
, and the code was unable to be parsed as a result.

And now here’s the comment which helped solved the problem:

And also the {?> (change that to { ?>) and )?> (change that to
) ?>) – i.e. once again, add a space (or a new line, whichever is
better..) before the ?> (and after the <?php).

And based on this answer on Stack Overflow, I believe the problem was the {?> which should have been written as { ?> (i.e. an opening bracket followed by a space then the closing PHP tag).

So in summary, you should not put brackets directly close to the opening/closing PHP tag, but separate it with a space:

// Bad
{?>
<?php}

// Good
{ ?>
<?php }

However, regarding this: “the file is identical across both sites though, and mine works perfectly“; it’s probably because some PHP installations/setups are forgiving to brackets that are directly close to the opening/closing PHP tag. Because that seemed to be the case with my first test which was on a PHP 7.3 (Windows) install, except that I had to change the <?php; } to <?php }, but that’s probably just a typo in the question.. 🙂