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 7176469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:30:51+00:00 2026-05-28T16:30:51+00:00

Possible Duplicate: Workaround for basic syntax not being parsed I am trying to allow

  • 0

Possible Duplicate:
Workaround for basic syntax not being parsed

I am trying to allow developers to specify any combination of bits to specify which pieces of data they want included in a response.

    class ClassName {
            const BUILD_DATE_RFC = 1; 
            const BUILD_DATE_SQL = 2;
            const BUILD_DATE_SQLTIME = 4;
            const BUILD_DATE_UNIX = 8;

           // ....
   }

This works in the sense that when I instantiate the class like this:

$whatever = new ClassName(BUILD_DATE_RFC|BUILD_DATE_SQL);

This logic would be executed:

    if (self::BUILD_DATE_RFC & $this->metaBits) {   
        $dateMeta['RFC'] = date('r');
    }
    if (self::BUILD_DATE_SQL & $this->metaBits) {
        $dateMeta['SQL'] = date('Y-m-d');
    }
    if (self::BUILD_DATE_SQLTIME & $this->metaBits) {
        $dateMeta['SQL_time'] = date('Y-m-d H:i:s');
    }

All of this works beautifully, except I’d like to define ‘shortcut bits’ something like BUILD_DATE_ALL which would be the value of the sum of all the DATE related bits so they only have to specify that shortcut constant rather than each one individually.

I tried this but it throws an error:

const BUILD_DATE_ALL =  (self::BUILD_DATE_RFC|self::BUILD_DATE_SQL|self::BUILD_DATE_SQLTIME|self::BUILD_DATE_UNIX);

I also tried different approaches/syntaxes:

const BUILD_REQUEST_ALL =   self::BUILD_IP |
                self::BUILD_USERAGENT |
                self::BUILD_REFERER;

and another approach I tried:

const BUILD_DEFAULT = self::BUILD_DATE_ALL|self::BUILD_REQUEST_ALL^self::BUILD_REFERER^self::BUILD_USERAGENT;

The error I get is:

ErrorException: syntax error, unexpected ‘(‘

and the error I get for the other approaches is:

ErrorException: syntax error, unexpected ‘|’, expecting ‘,’ or ‘;’

It looks like PHP doesn’t want to calculate too much in a constant definition and just wants a single value rather than derived value. I’m assuming this based off the fact that it doesn’t want parenthesis nor does it want the | to do further calculations. Additionally, I tried using ‘-‘ instead of | just to test my theory.. and yes, it complained about the + being unexpected too.

How do I go about fixing the problem so I can define a ‘shortcut bit’ which is a sum of a range of the other already-defined constants.

  • 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-05-28T16:30:53+00:00Added an answer on May 28, 2026 at 4:30 pm

    You can calculate it yourself. As these are bit flags there is a pattern.

    class ClassName {
            const BUILD_DATE_RFC = 1; 
            const BUILD_DATE_SQL = 2;
            const BUILD_DATE_SQLTIME = 4;
            const BUILD_DATE_UNIX = 8;
            const BUILD_DATE_ALL = 15; // 15 = 1|2|4|8;
           // ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Any way to access array directly after method call? In C# and
Possible Duplicate: Learning to write a compiler I looked around trying to find out
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Anyone know a good workaround for the lack of an enum generic
Possible Duplicate: Elegant workaround for JavaScript floating point number problem var sum = 0;
Possible Duplicate: Elegant workaround for JavaScript floating point number problem var sum = 0;
Possible Duplicate: Elegant workaround for JavaScript floating point number problem Why is it that
Possible Duplicate: Cross-domain XHR/AJAX : a possible workaround? I tried to do a xmlHttpRequest
Possible Duplicate: Is there a workaround for Java's poor performance on walking huge directories?

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.