Are there any plans to allow bitwise declaration of flags?

Example:

class foo {
   const FLAG_1 = 1;
   const FLAG_2 = 2;
   const FLAG_3 = 4;

   private $Flags = self::FLAG_1 | self::FLAG_3
}


Hi,

This is not allowed since declaration values should be resolvable at compile time. I.e. they can not be an expression, but only a value literal.

While technically expression folding is possible, it's not implemented in any part of the PHP engine (AFAIK), and I don't think it's planned any time soon.

To do what you want, initialize the value in the constructor:

class foo {
   ...
   private $flags;

   function __construct()
   {
       $this->flags = self::FLAG_1 | self::FLAG_3;
   }
}

Regards,
Stan Vassilev

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to