Req #80093 [NEW]: Please add dynamic defining for class constants

From: Date: Fri, 11 Sep 2020 15:10:28 +0000
Subject: Req #80093 [NEW]: Please add dynamic defining for class constants
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228978@lists.php.net to get a copy of this message
From: flexjoly at vfweb dot nl Operating system: PHP version: Irrelevant Package: Class/Object related Bug Type: Feature/Change Request Bug description:Please add dynamic defining for class constants Description: ------------ Normal constants are made by the function 'define()'. But something like that is not possible for a class constant. That limits their purpose and usability very much. Can you please add a define-function for a class constant? Then we can use a class with constant to replace all the separate constants. Nowadays many variables are put in static classes and can be found and used easily. But when using these for config/settings etc. you need to set them public for direct access. But then they can be changed, and that is not wanted. A class constant solves this. For it can be used public, but cannot be changed. But for settings/config etc. it need to be possible to define a class constant from a variable or function, just like a normal constant. Test script: --------------- class myClass { const myConst; const otherConst = 'already set'; public function defineMyConst(){ // first time defining, works fine self::myConst = 'some value'; // second time defining not allowed, should throw an error self::myConst = 'other value'; // defining a defined constant is not allowed, and throws an error self::myConst = 'changing'; } } -- Edit bug report at https://bugs.php.net/bug.php?id=80093&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80093&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80093&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80093&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80093&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80093&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80093&r=support Expected behavior: https://bugs.php.net/fix.php?id=80093&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80093&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80093&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80093&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80093&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80093&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80093&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80093&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80093&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80093&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80093&r=mysqlcfg

« previous php.bugs (#228978) next »