From: RQuadling at GoogleMail dot com Operating system: Irrelevant PHP version: 5.3.0RC4 PHP Bug Type: Feature/Change Request Bug description: Allow for dynamic class constants via magic method __constant()
Description: ------------ Hi. Would it be possible to have a new magic method allowing a class to handle a request for a constant that has not been defined. <?php class ANSI { static public function __constant($constant) { // Parse $constant to determine response. // e.g. turning COLOUR_BRIGHT_FG_WHITE_RED // into '1;37;41'; } } The values for various constant names are constant. They won't change, but having to manually create all the combinations is a headache. They could be cached internally. So asking for a constant and not finding it would allow the magic method to run and then save it for the next usage. Maybe. Or not. I know this is easily handled as ... ANSI::convertConstantStringToANSISequence(COLOUR_BRIGHT_FG_WHITE_RED) but ANSI::COLOUR_BRIGHT_FG_WHITE_RED is the intent. Even without the caching (which could be done in userland if constants could be added at runtime), then this would be useful. Any takers? Regards, Richard Quadling. -- Edit bug report at http://bugs.php.net/?id=48689&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=48689&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=48689&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=48689&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=48689&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=48689&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=48689&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=48689&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=48689&r=needscript Try newer version: http://bugs.php.net/fix.php?id=48689&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=48689&r=support Expected behavior: http://bugs.php.net/fix.php?id=48689&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=48689&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=48689&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=48689&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=48689&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=48689&r=dst IIS Stability: http://bugs.php.net/fix.php?id=48689&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=48689&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=48689&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=48689&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=48689&r=mysqlcfg