Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:06:12+00:00 2026-06-13T23:06:12+00:00

// Hi, I want to exclude a flag with bitwise operations, but I don’t

  • 0

// Hi, I want to exclude a flag with bitwise operations, but I don’t know how :
// Here are the flags (they come from filesystemiterator)

define('CURRENT_AS_FILEINFO', 0);
define('CURRENT_AS_SELF', 16);
define('CURRENT_AS_PATHNAME', 32);
define('CURRENT_MODE_MASK', 240);
define('KEY_AS_PATHNAME', 0);
define('KEY_AS_FILENAME', 256);
define('FOLLOW_SYMLINKS', 512);
define('KEY_MODE_MASK', 3840);
define('NEW_CURRENT_AND_KEY', 256);
define('SKIP_DOTS', 4096);
define('UNIX_PATHS', 8192);

The user can potentially set any combination of flags.
I need to detect if CURRENT_AS_SELF or CURRENT_AS_PATHNAME was set,
so here is my function so far:

function containsPathnameOrSelfFlag($flags) {
    if ($flags & (CURRENT_AS_PATHNAME | CURRENT_AS_SELF)) {
        return true;
    }
    return false;
}

And here is a test suite :

var_dump(containsPathnameOrSelfFlag(CURRENT_MODE_MASK | CURRENT_AS_PATHNAME)); // true, ok
var_dump(containsPathnameOrSelfFlag(CURRENT_AS_FILEINFO)); // false, ok
var_dump(containsPathnameOrSelfFlag(CURRENT_MODE_MASK | CURRENT_AS_FILEINFO)); // true, but false was expected, because neither CURRENT_AS_SELF nor CURRENT_AS_SELF were set, so my function is wrong

Is it possible to use bitwise operators to make the function pass the third case
( it should return false )
?

The problem I see here is that the CURRENT_MODE_MASK’s bit overlap the CURRENT_AS_SELF
and CURRENT_AS_PATHNAME’s bits :

0000000000010000 : CURRENT_AS_SELF 
0000000000100000 : CURRENT_AS_PATHNAME 
0000000011110000 : CURRENT_MODE_MASK 
0000000100000000 : KEY_AS_FILENAME
0000001000000000 : FOLLOW_SYMLINKS
0000111100000000 : KEY_MODE_MASK
0000000100000000 : NEW_CURRENT_AND_KEY
0001000000000000 : SKIP_DOTS
0010000000000000 : UNIX_PATHS

So every time the user add the CURRENT_MODE_MASK to the flags, my function
will think that the CURRENT_AS_SELF and the CURRENT_AS_PATHNAME were set too, though it’s not the case.
I don’t know how to solve this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:06:12+00:00Added an answer on June 13, 2026 at 11:06 pm

    Masks are meant to be anded against the current value for testing, not ored with new values for generation. If you want to test for presence of or use only a single flag, then use only that flag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to match all URLS but exclude image urls from beeing matched with
I want to exclude some tests from my continuous integration build but I haven't
Here we only want to exclude a class from certain classpath, say com.abc.projectA.service.orderService.sectionA.orderService.class However
I want to exclude developer iAds from my apps, as I don't think the
I want to exclude the following characters from my string: \-- ' < >
I want to exclude spaces when validating a textbox in vb.net. Here is the
I have a custom CMS here entitled phpVMS, and I want to exclude a
Hi want to exclude 2 or more files from my batch file. My batch
I want to exclude a particular method of a class from java compilation. For
Is it possible to programmatically set that you want to exclude a property from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.