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

  • SEARCH
  • Home
  • 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 8350335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:17:08+00:00 2026-06-09T08:17:08+00:00

I’m not sure if bitmask is the correct term. Let me explain: In php,

  • 0

I’m not sure if bitmask is the correct term. Let me explain:

In php, the error_reporting function can be called multiple ways:

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

I got the term bitmask from the php.net page here

Anyway the point of this is, I have implemented a SIMPLE method called ls which returns the contents of a directory.

This function takes 3 args… ( $include_hidden = false, $return_absolute = false, $ext = false )

So when i call the function, i set how i want the results. Whether i want the results to return hidden directories, whether i want basenames only etc.

so when i call the function i’m writing

ls(true, false, true)
ls(false, false, true)
ls(true, true, true)
etc...

I thought it would be much more readable if i could just flag how i want the data returned?

so something like:

ls( INCLUDE_HIDDEN | HIDE_EXTS );
ls( SHOW_ABSOLUTE_PATHS | HIDE_EXTS );

etc…

How would i implement this in terms of testing which flags have been called?

  • 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-09T08:17:11+00:00Added an answer on June 9, 2026 at 8:17 am

    It’s quite simple actually. First a bit of code to demonstrate how it can be implemented. If you don’t understand anything about what this code is doing or how it works, feel free to ask additional questions in the comments:

    const FLAG_1 = 0b0001; // 1
    const FLAG_2 = 0b0010; // 2
    const FLAG_3 = 0b0100; // 4
    const FLAG_4 = 0b1000; // 8
    // Can you see the pattern? ;-)
    
    function show_flags ($flags) {
      if ($flags & FLAG_1) {
        echo "You passed flag 1!<br>\n";
      }
      if ($flags & FLAG_2) {
        echo "You passed flag 2!<br>\n";
      }
      if ($flags & FLAG_3) {
        echo "You passed flag 3!<br>\n";
      }
      if ($flags & FLAG_4) {
        echo "You passed flag 4!<br>\n";
      }
    }
    
    show_flags(FLAG_1 | FLAG_3);
    

    Demo


    Because the flags are integers, on a 32-bit platform you define up to 32 flags. On a 64-bit platform, it’s 64. It is also possible to define the flags as strings, in which case the number of available flags is more or less infinite (within the bounds of system resources, of course). Here’s how it works in binary (cut down to 8-bit integers for simplicity).

    FLAG_1
    Dec:    1
    Binary: 00000001
    
    FLAG_2
    Dec:    2
    Binary: 00000010
    
    FLAG_3
    Dec:    4
    Binary: 00000100
    
    // And so on...
    

    When you combine the flags to pass them to the function, you OR them together. Let’s take a look at what happens when we pass FLAG_1 | FLAG_3

      00000001
    | 00000100
    = 00000101
    

    And when you want to see which flags were set, you AND the bitmask with the flag. So, lets take the result above and see if FLAG_3 was set:

      00000101
    & 00000100
    = 00000100
    

    …we get the value of the flag back, a non-zero integer – but if we see if FLAG_2 was set:

      00000101
    & 00000010
    = 00000000
    

    …we get zero. This means that you can simply evaluate the result of the AND operation as a boolean when checking if the value was passed.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need a function that will clean a strings' special characters. I do NOT
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string

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.