ID: 39466
User updated by: kevin at metalaxe dot com
Reported By: kevin at metalaxe dot com
-Status: Bogus
+Status: Open
Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5.2.0
New Comment:
Ok, if that is the case, how does the global constant MAGIC_QUOTES get
defined from the code in the description?
<?php
define( 'MAGIC_QUOTES', ( (bool)get_magic_quotes_gpc() ), true );
var_dump( MAGIC_QUOTES );
?>
prints bool(true)
We are running 3 functions there (according to the docs). One to get
the value being applied, another to cast to int and finally one to
"define" the constant.
Previous Comments:
------------------------------------------------------------------------
[2006-11-10 22:26:50] [EMAIL PROTECTED]
That's not possible, as constants are declared at compile time, while
functions are executed at runtime.
------------------------------------------------------------------------
[2006-11-10 22:11:17] kevin at metalaxe dot com
Description:
------------
You can define a global constant based on the return of a function yet
you cannot do so for class constants.
eg. define( 'MAGIC_QUOTES', ( (bool)get_magic_quotes_gpc() ), true );
Requesting a method to assign class constants in a manner similar to
global constants
Reproduce code:
---------------
<?php
class parser
{
const magic_quotes = (bool)get_magic_quotes_gpc();
public my_stripslashes( $str )
{
if( self::magic_quotes === true )
{
$str = stripslashes( $str );
}
return $str;
}
}
?>
Expected result:
----------------
Constant "magic_quotes" to be assigned the boolean value of
get_magic_quotes_gpc's return.
Actual result:
--------------
With boolean cast:
Parse error: syntax error, unexpected T_BOOL_CAST in parser.php on line
4
Without boolean cast:
Parse error: syntax error, unexpected '(', expecting ',' or ';' in
parser.php on line 4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39466&edit=1