Req #48689 [Fbk->NoF]: Allow for dynamic class constants via magic method __constant()

From: Date: Tue, 30 Dec 2014 10:41:35 +0000
Subject: Req #48689 [Fbk->NoF]: Allow for dynamic class constants via magic method __constant()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189393@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48689&edit=1 ID: 48689 Updated by: php-bugs@lists.php.net Reported by: RQuadling at GoogleMail dot com Summary: Allow for dynamic class constants via magic method __constant() -Status: Feedback +Status: No Feedback Type: Feature/Change Request Package: *General Issues Operating System: Irrelevant PHP Version: 5.3.0RC4 Private report: N New Comment: No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Re-Opened". Thank you. Previous Comments: ------------------------------------------------------------------------ [2014-04-16 19:25:58] levim@php.net Are you still interested in this? ------------------------------------------------------------------------ [2009-06-25 11:18:57] RQuadling at GoogleMail dot com 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 this bug report at https://bugs.php.net/bug.php?id=48689&edit=1

« previous php.bugs (#189393) next »