Browse Source

Don't call function_exists() every time debug is set.

Only call function_exists() the first time debug is called.
This saves a few calls to function exists over the span of a test suite
run.
mark_story 12 years ago
parent
commit
13a9942d7f
1 changed files with 13 additions and 5 deletions
  1. 13 5
      src/Core/Configure.php

+ 13 - 5
src/Core/Configure.php

@@ -49,6 +49,13 @@ class Configure {
 	protected static $_engines = [];
 
 /**
+ * Flag to track whether or not ini_set exists.
+ *
+ * @return void
+ */
+	protected static $_hasIniSet = null;
+
+/**
  * Used to store a dynamic variable in Configure.
  *
  * Usage:
@@ -81,11 +88,12 @@ class Configure {
 			static::$_values = Hash::insert(static::$_values, $name, $value);
 		}
 
-		if (isset($config['debug']) && function_exists('ini_set')) {
-			if (static::$_values['debug']) {
-				ini_set('display_errors', 1);
-			} else {
-				ini_set('display_errors', 0);
+		if (isset($config['debug'])) {
+			if (static::$_hasIniSet === null) {
+				static::$_hasIniSet = function_exists('ini_set');
+			}
+			if (static::$_hasIniSet) {
+				ini_set('display_errors', $config['debug'] ? 1 : 0);
 			}
 		}
 		return true;