ID:               39466
 User updated by:  kevin at metalaxe dot com
 Reported By:      kevin at metalaxe dot com
 Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: *
-PHP Version:      5.2.0
+PHP Version:      5.2.0+
 New Comment:

I don't understand why I'm being shrugged off as impossible. I'm asking
for functionality similar to global constants for class constants. If
you can do it for global constants, it seems only plausible that class
constants should be handled in a similar fashion.
I could find many more uses for the exact same functionality if
necessary, within the same applicable class even.


Previous Comments:
------------------------------------------------------------------------

[2006-11-10 22:40:38] [EMAIL PROTECTED]

define() is just a function. which declares constants.
I was talking about class constants et al.

------------------------------------------------------------------------

[2006-11-10 22:37:11] kevin at metalaxe dot com

Just for reference, I reread the docs for global constants set using
define(). http://us2.php.net/manual/en/function.define.php states:

Defines a named constant at runtime. See the section on constants for
more details.

------------------------------------------------------------------------

[2006-11-10 22:33:06] kevin at metalaxe dot com

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.

------------------------------------------------------------------------

[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

Reply via email to