From: kevin at metalaxe dot com Operating system: * PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: Expaned Class members to allow setting of a read only value at runtime
Description: ------------ Since http://bugs.php.net/bug.php?id=39466 was shot down, PHP is in need of a method to which we can set class member variables as read-only during runtime to prevent changing of values that are critically important for script execution. I would like to use a class constant for this but, because it cannot be assigned a value at runtime, it is impossible to do so. The reproduce code is an example of a value that I would like to set as read only. The scope of the variable should not matter in this suggestion as it is practical that it would need to be changed given a proper reason. Reproduce code: --------------- <?php class parser { public $magic_quotes = false; public __construct() { //Add some sort of identifier here to set the //value read only (readonly)$this->magic_quotes = (bool)get_magic_quotes_gpc(); } public my_stripslashes( $str ) { if( self::magic_quotes === true ) { $str = stripslashes( $str ); } return $str; } public change_magic_quotes($to) { $this->magic_quotes = $to; } } $parser = new parser(); //Returns stripped string $stripped = $parser->my_stripslashes( 'Hi, there\'s a coke in the fridge' ); //Doesn't change the value of magic_quotes and flags an //E_WARNING or E_NOTICE error. $parser->change_magic_quotes( true ); ?> Expected result: ---------------- Hope to have it not allow the variable to be changed (ha, a constant, what a silly notion) and pop an error of some kind to the parser. Actual result: -------------- Not implemented, thus values can be changed at any time as long as the variable is within the visibility scope of calling party. -- Edit bug report at http://bugs.php.net/?id=39467&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39467&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39467&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39467&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39467&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39467&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39467&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39467&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39467&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39467&r=support Expected behavior: http://bugs.php.net/fix.php?id=39467&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39467&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39467&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39467&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39467&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39467&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39467&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39467&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39467&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39467&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39467&r=mysqlcfg