Hi!
You can do it like this. When an enum is defined:
I'm not talking about implementation in the code of PHP engine. I'm talking about writing code with these things that wouldn't produce fatal errors in random places without you being able to prevent it and without checking before each function call. Compiled languages deal with it easily because they check these things on compile - if you try to send int variable where BlahBlah type is expected, the compiler bails out and you know it's a problem. Dynamic languages don't work that way.
You'd just cast it to the enum type, at which point PHP would look up the enum value in the internal array in the enum class to efficiently retrieve the relevant strongly typed enum constant.
But the procedure loading the configs probably has no idea about your enums - for it it's just nmumbers. So you'd probably have to take the cast down close to the actual call. At which time you could as well done the proper check and handle it in an application-specific way.
I also suggest when type-hinting, if the type is integer or string where an enum is expected, PHP attempts a cast before failing, to make this more convenient.
Strict typing is not robust unless you can ensure your variables and method returns have required types - either using compiler or manually checking. Converting helps a little here but still you're putting into the language something that is best handled on user-level since the language doesn't have enough information to handle it.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php