|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-04-16 19:25 UTC] levim@php.net
-Status: Open
+Status: Feedback
-Package: Feature/Change Request
+Package: *General Issues
[2014-04-16 19:25 UTC] levim@php.net
[2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 16:00:01 2025 UTC |
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.