I don't think this has ever been the right way to remove something from \AfterEndEnvironment
.
\documentclass{article}
\usepackage{etoolbox}
\newenvironment{Toto}{%
}{%
}
\newcommand{\iforgot}{I forgot\dots}
\AfterEndEnvironment{Toto}{\iforgot}
\begin{document}
\begin{Toto}
x
\end{Toto}
\renewcommand{\iforgot}{}
\begin{Toto}
x
\end{Toto}
\end{document}
A new hook management is now built in the LaTeX kernel from the 2020-10-01 release.
\documentclass{article}
\newenvironment{Toto}{}{}
\AddToHook{env/Toto/after}[forgot]{I forgot\ldots}
\begin{document}
\begin{Toto}
x
\end{Toto}
\RemoveFromHook{env/Toto/after}[forgot]
\begin{Toto}
x
\end{Toto}
\end{document}
The label in square brackets is an arbitrary string. You can add as many pieces of code you want and only disable some of them through the label mechanism. See the documentation with
texdoc lthooks
etoolbox
has been updated to be aware of this