开发者

How to store numeric values in Zend_Config without loosing its type?

I decided to move some applicatio开发者_Go百科n settings from database to file system to be accessible via Zend_Config. However I run in to one annoying thing, Zend_Config recognise all values as string ignoring data type.

Is there any magic way to parse config file keeping original types like float, integer, string and what would be best storage for it INI, XML, YAML or JSON?


At least not possible with Zend_Config_Xml:

Configuration data read into Zend_Config_Xml are always returned as strings. Conversion of data from strings to other types is left to developers to suit their particular needs.

Not sure about the others. You can very much do something like

// config.php
return array('foo' => 1);

// bootstrap
$config = new Zend_Config(include 'config.php');
var_dump($config->foo); // int(1)


Zend will automagically turn integers, floats, and bools into their respective types with JSON and YAML. XML is always string, and INI has all the caveats and power of parse_ini_file() when it comes to choosing type.

If you want an explicit type, such as a particular object, you need to include that in the serialized data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜