Index: library/Zend/Config.php =================================================================== --- library/Zend/Config.php (revision 7117) +++ library/Zend/Config.php (working copy) @@ -42,6 +42,13 @@ protected $_allowModifications; /** + * Check and cast types, or not + * + * @var boolean + */ + protected $_detectTypes; + + /** * Iteration index * * @var integer @@ -92,9 +99,10 @@ * @param boolean $allowModifications * @throws Zend_Config_Exception */ - public function __construct($array, $allowModifications = false) + public function __construct($array, $allowModifications = false, $detectTypes = false) { $this->_allowModifications = (boolean) $allowModifications; + $this->_detectTypes = (boolean) $detectTypes; $this->_loadedSection = null; $this->_index = 0; $this->_data = array(); @@ -120,6 +128,7 @@ $result = $default; if (array_key_exists($name, $this->_data)) { $result = $this->_data[$name]; + $result = $this->_detectTypes($result); } return $result; } @@ -169,7 +178,7 @@ if ($value instanceof Zend_Config) { $array[$key] = $value->toArray(); } else { - $array[$key] = $value; + $array[$key] = $this->_detectTypes($value); } } return $array; @@ -340,4 +349,33 @@ $this->_extends[$extendingSection] = $extendedSection; } + /** + * Checks $value in being one of the elemental data types and casts it accordingly. + * + * @param string $value + * @return mixed + */ + protected function _detectTypes($value) + { + if ($this->_detectTypes and !$value instanceof Zend_Config) { + switch(true) { + case strtolower($value) === "true": + $value = (bool) true; + break; + + case strtolower($value) === "false": + $value = (bool) false; + break; + + case $value === (string)(int) $value: + $value = (int) $value; + break; + + case $value === (string)(float) $value: + $value = (float) $value; + break; + } + } + return $value; + } }