ID: 39467
User updated by: kevin at metalaxe dot com
Reported By: kevin at metalaxe dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5.2.0
New Comment:
There is a typo in my example code above.
public my_stripslashes( $str )
{
if( self::magic_quotes === true )
{
$str = stripslashes( $str );
}
return $str;
}
should be
public my_stripslashes( $str )
{
if( $this->magic_quotes === true )
{
$str = stripslashes( $str );
}
return $str;
}
Previous Comments:
------------------------------------------------------------------------
[2006-11-10 23:47:46] kevin at metalaxe dot com
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 this bug report at http://bugs.php.net/?id=39467&edit=1