How to use function flags?
<p>I want to create a class and extend a PHP class FilesystemIterator as in the following code. I define a method hasFlag() and test whether it contains a flag (I want it to be like some other PHP functions, eg. glob), but the result is always different from expected. So how can I fix this problem?</p>

<pre><code>class c extends FilesystemIterator 
{
    /* These are parent constants */
    const CURRENT_AS_FILEINFO  = 0 ;
    const KEY_AS_PATHNAME      = 0 ;
    const CURRENT_AS_SELF      = 16 ;
    const CURRENT_AS_PATHNAME  = 32 ;
    const CURRENT_MODE_MASK    = 240 ;
    const KEY_AS_FILENAME      = 256 ;
    const NEW_CURRENT_AND_KEY  = 256 ;
    const FOLLOW_SYMLINKS      = 512 ;
    const KEY_MODE_MASK        = 3840 ;
    const SKIP_DOTS            = 4096 ;
    const UNIX_PATHS           = 8192 ;

    public function __construct($flags) {
        $this-&gt;flags = $flags;
    }
    public function hasFlag($flag) {
        //How do I test $this-&gt;flags it contains a $flag???
        return ($this-&gt;flags &amp; $flag) ? true : false;
    }
}

$c = new c(
    c::CURRENT_AS_FILEINFO | 
    c::KEY_AS_PATHNAME | 
    c::CURRENT_AS_SELF |
    c::CURRENT_AS_PATHNAME |
    c::CURRENT_MODE_MASK |
    c::KEY_AS_FILENAME  |
    c::NEW_CURRENT_AND_KEY |
    c::FOLLOW_SYMLINKS |
    c::KEY_MODE_MASK |
    c::SKIP_DOTS |
    c::UNIX_PATHS
);

var_dump($c-&gt;hasFlag(c::CURRENT_AS_FILEINFO));
</code></pre>

<p>EDIT 1</p>

<p>why is so ??</p>

<pre><code>var_dump( ((0 | 16 | 32 | 240 | 3840) &amp; 0)    == 0 );    //true
var_dump( ((0 | 16 | 32 | 240 | 3840) &amp; 32)   == 32 );   //true
var_dump( ((0 | 16 | 32 | 240 | 3840) &amp; 240)  == 240 );  //true
var_dump( ((0 | 16 | 32 | 240 | 3840) &amp; 1024) == 1024 ); //true??
var_dump( ((0 | 16 | 32 | 240 | 3840) &amp; 2048) == 2048 ); //true??
var_dump( ((0 | 16 | 32 | 240 | 3840) &amp; 3840) == 3840 ); //true
</code></pre>
