A question asked here How to get second last page as a number without hyperref? had an answer, which was accepted and must have worked at the time:
\documentclass[a5paper]{article}
\usepackage{lastpage}
\usepackage{hyperref}
\usepackage{refcount}
\usepackage{lipsum}
\newcommand*{\thesecondlastpage}{%
\the\numexpr(\getrefbykeydefault{LastPage}{page}{0})-1\relax
}
\AtBeginDocument{\refused{LastPage}}
\begin{document}
The second last page is \thesecondlastpage.
\lipsum
\end{document}
However, it no longer works - after the first typeset, the first line of the PDF is "The second last page is -1." But after the second typeset, it has an error "Missing number, treated as zero. \begingroup
I assume this is either because of the update to the LastPage package on 2023-07-25, or the update to the hyperref package on 2023-07-09.
Can anyone suggest what changes might be needed to this MWE to get it functional again?