From 4661aa2114e9a409b198a0a66739dc2b2f6fc39a Mon Sep 17 00:00:00 2001 From: Jakub Filak Date: Wed, 19 Feb 2020 23:17:01 +0100 Subject: [PATCH] Hooks fixes (#99) * repace deprecated each with foreach I tried to enable the example.php hooks and the use of the keyword each was causing crashes in the docker image osixia/phpldapadmin:0.9.0 * check if DEBUG_ENABLED is defined I enabled the hooks example.php and I started getting crashes caused by undefined constant. Tested with the docker image osixia/phpldapadmin:0.9.0 --- lib/hooks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/hooks.php b/lib/hooks.php index 57066ed..a39a938 100644 --- a/lib/hooks.php +++ b/lib/hooks.php @@ -32,7 +32,7 @@ * element priority. 1 otherwise. */ function sort_array_by_priority($a,$b) { - if (DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) + if (defined('DEBUG_ENABLED') && DEBUG_ENABLED && (($fargs=func_get_args())||$fargs='NOARGS')) debug_log('Entered (%%)',257,0,__FILE__,__LINE__,__METHOD__,$fargs); return (($a['priority'] < $b['priority']) ? -1 : 1 ); @@ -68,7 +68,7 @@ function run_hook($hook_name,$args) { /* Execution of procedures attached is done using a numeric order * since all procedures have been attached to the hook with a * numerical weight. */ - while (list($key,$hook) = each($hooks[$hook_name])) { + foreach ($hooks[$hook_name] as $key=>$hook) { if (DEBUG_ENABLED) debug_log('Calling HOOK Function (%s)(%s)',257,0,__FILE__,__LINE__,__METHOD__, $hook['hook_function'],$args); @@ -159,7 +159,7 @@ function remove_hook($hook_name,$hook_function,$priority,$rollback_function) { if (array_key_exists($hook_name,$_SESSION[APPCONFIG]->hooks)) { reset($_SESSION[APPCONFIG]->hooks[$hook_name]); - while (list($key,$hook) = each($_SESSION[APPCONFIG]->hooks[$hook_name])) { + foreach ($_SESSION[APPCONFIG]->hooks[$hook_name] as $key=>$hook) { if (($priority >= 0 && $priority == $hook['priority']) || ($hook_function && $hook_function == $hook['hook_function']) || ($rollback_function && $rollback_function == $hook['rollback_function'])) {