Req #48689 [Opn->Fbk]: Allow for dynamic class constants via magic method __constant()
| From: | levim@php.net | Date: | Wed, 16 Apr 2014 19:25:58 +0000 |
| Subject: | Req #48689 [Opn->Fbk]: Allow for dynamic class constants via magic method __constant() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185301@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: levim@php.net
Reported by: RQuadling at GoogleMail dot com
Summary: Allow for dynamic class constants via magic method
__constant()
-Status: Open
+Status: Feedback
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: Irrelevant
PHP Version: 5.3.0RC4
Block user comment: N
Private report: N
New Comment:
Are you still interested in this?
Previous Comments:
------------------------------------------------------------------------
[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