why do class constants as default keys in arrays turn to numerical keys in php?
I would like to s开发者_如何转开发ave the user settings when to send an email. To achieve this I was going to make use of my system's class constants of the Mailing Class and use its constants as array key values. But for some reason the keys are turned into numerical indexes and the match on runtime with class constants doesnt work anymore. When I use a single string instead, its working as expected..
This is an example of the class with the output given: http://pastie.org/2541980
Why are you doing it like this? The constants seem to resemble flags -- a more efficient way of handling those is to map them to a number, ideally using binary operators. That way, you can 'turn on' all applicable flags, resulting in just one integer -- easier to store and easier to pass around.
Check this out: http://life-of-brian.com/2008/04/binary-code-bitwise-operators-php/
精彩评论