From 9ff8b6f7e64a72b9f2681b81e957b6feb9d697e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Pe=CC=81rez?= <jaime.perez@uninett.no> Date: Mon, 27 Jun 2016 12:09:50 +0200 Subject: [PATCH] Fix for compatibility with PHP 5.3. PHP 5.3 does not allow the use of $this inside closures. This is a temporary fix for compatibility with 5.3, while we are still supporting it. We will drop this when updating the minimum requirements to PHP 5.4. --- templates/selectidp-dropdown.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/templates/selectidp-dropdown.php b/templates/selectidp-dropdown.php index b9c3b73a7..ebe7646b4 100644 --- a/templates/selectidp-dropdown.php +++ b/templates/selectidp-dropdown.php @@ -33,10 +33,21 @@ foreach ($this->data['idplist'] as $idpentry) { value="<?php echo htmlspecialchars($this->data['returnIDParam']); ?>"/> <select id="dropdownlist" name="idpentityid"> <?php + /* + * TODO: change this to use $this instead when PHP 5.4 is the minimum requirement. + * + * This is a dirty hack because PHP 5.3 does not allow the use of $this inside closures. Therefore, the + * translation function must be passed somehow inside the closure. PHP 5.4 allows using $this, so we can + * then go back to the previous behaviour. + */ + $GLOBALS['__t'] = $this; usort($this->data['idplist'], function ($idpentry1, $idpentry2) { - // TODO: this is only compatible with PHP >= 5.4, fix compat with 5.3! - return strcmp($this->t('idpname_'.$idpentry1['entityid']), $this->t('idpname_'.$idpentry2['entityid'])); + return strcmp( + $GLOBALS['__t']->t('idpname_'.$idpentry1['entityid']), + $GLOBALS['__t']->t('idpname_'.$idpentry2['entityid']) + ); }); + unset($GLOBALS['__t']); foreach ($this->data['idplist'] as $idpentry) { echo '<option value="'.htmlspecialchars($idpentry['entityid']).'"'; -- GitLab