From 0a7c58fd8f8f272147f119d8729c82958f63b0ba Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 19 Dec 2023 09:13:53 +0800 Subject: [PATCH] MDL-59467 core: Use hasHelper instead of catching exception When xdebug is set to break on exceptions it stops on all exceptions, including _caught_ exceptions. As a result we regularly hit this uniqid helper issue if debugging with xdebug. The solution is to check if the helper exists using the hasHelper method instead of catching an exception when it does not exist. --- lib/outputrenderers.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 3cef72177a2..1bf346d9cca 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -181,10 +181,10 @@ class renderer_base { public function render_from_template($templatename, $context) { $mustache = $this->get_mustache(); - try { + if ($mustache->hasHelper('uniqid')) { // Grab a copy of the existing helper to be restored later. $uniqidhelper = $mustache->getHelper('uniqid'); - } catch (Mustache_Exception_UnknownHelperException $e) { + } else { // Helper doesn't exist. $uniqidhelper = null; }