From a70989705e008d1d7d8f7ad0cf884be5c1a1105f Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Sat, 3 Aug 2019 14:56:37 +0200 Subject: [PATCH] New event_is_declared() function Note: use isset() instead of array_key_exists() as discussed in PR https://github.com/mantisbt/mantisbt/pull/1534#discussion_r310346891 Replace usage of isset( $g_event_cache[...] ) elsewhere in event API, by calls to the new function. Fixes #25953 --- core/event_api.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/core/event_api.php b/core/event_api.php index 1297d9dd75..364459b98c 100644 --- a/core/event_api.php +++ b/core/event_api.php @@ -37,6 +37,17 @@ # @global array $g_event_cache $g_event_cache = array(); +/** + * Determine if a given event has been declared + * @param string $p_name Event name + * @return bool True if the even has been declared + */ +function event_is_declared( $p_name ) { + global $g_event_cache; + + return isset( $g_event_cache[$p_name] ); +} + /** * Declare an event of a given type. * Will do nothing if event already exists. @@ -48,7 +59,7 @@ function event_declare( $p_name, $p_type = EVENT_TYPE_DEFAULT ) { global $g_event_cache; - if( !isset( $g_event_cache[$p_name] ) ) { + if( !event_is_declared( $p_name ) ) { $g_event_cache[$p_name] = array( 'type' => $p_type, 'callbacks' => array(), @@ -80,7 +91,7 @@ function event_declare_many( array $p_events ) { function event_hook( $p_name, $p_callback, $p_plugin = 0 ) { global $g_event_cache; - if( !isset( $g_event_cache[$p_name] ) ) { + if( !event_is_declared( $p_name ) ) { error_parameters( $p_name ); trigger_error( ERROR_EVENT_UNDECLARED, WARNING ); return null; @@ -135,7 +146,7 @@ function event_clear_callbacks() { function event_signal( $p_name, $p_params = null, $p_params_dynamic = null, $p_type = null ) { global $g_event_cache; - if( !isset( $g_event_cache[$p_name] ) ) { + if( !event_is_declared( $p_name ) ) { error_parameters( $p_name ); trigger_error( ERROR_EVENT_UNDECLARED, WARNING ); return null;