WordPress get permalink function

From https://developer.wordpress.org/reference/functions/get_permalink/ :

get_permalink( int|WP_Post $post, bool $leavename = false )

Retrieves the full permalink for the current post or post ID.

[…]

Note that when used outside The Loop on a posts page (index, archive,
etc.) without the ID parameter, it will return the URL of the last
post in The Loop, not the permalink for the current page.