473,322 Members | 1,496 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to initialize a class property with binary value? (bitmasks)

Lets run following code:

------- snip ------

class Perm {
static $read = bindec('001');
static $write = bindec('010');
static $delete = bindec('100');
}

print Perm::$read & Perm::$write;

------- snap ------

Output:

Parse error: parse error, unexpected '(', expecting ',' or ';' in ...
So, how do I get around that, i.e. initialize a class property with binary
value? Separate method or calculator are not very beautiful solutions.
--
Jaakko Holster

Jul 17 '05 #1
3 2684
.oO(Jaakko Holster)
class Perm {
static $read = bindec('001');
static $write = bindec('010');
static $delete = bindec('100');
}

print Perm::$read & Perm::$write;

------- snap ------

Output:

Parse error: parse error, unexpected '(', expecting ',' or ';' in ...
So, how do I get around that, i.e. initialize a class property with binary
value? Separate method or calculator are not very beautiful solutions.


That's what a constructor is for, but in this case ... why not simply
put in the values directly (1, 2, 4)? Or use predefined constants:

define('P_READ', bindec('001'));
....

Micha
Jul 17 '05 #2
>>So, how do I get around that, i.e. initialize a class property with binary
value? Separate method or calculator are not very beautiful solutions.
That's what a constructor is for, but in this case ... why not simply
put in the values directly (1, 2, 4)?


It's easier to write bitmasks in binary format than in decimal format...
define('P_READ', bindec('001'));


....whereas global constants are not very beautiful from point of view of
oop.

What I'm saying, PHP should consider 0010110b strings as binary value
(similar to 0xff -> hex syntax).

Well, if you cant have the best - I'm satisfied with following code:

class Perm {
const read = 1; // 001b
const write = 2; // 010b
const list = 4; // 100b
...etc...
}

print Perm::read;

--
Jaakko Holster

Jul 17 '05 #3
.oO(Jaakko Holster)
It's easier to write bitmasks in binary format than in decimal format...


Fo such things I used hexadecimal format a while ago.

Micha
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Pascal | last post by:
Hello, I've a binary file with data in it. This file come from an old ms dos application (multilog ~ 1980). In this application, a field is declared as a 'decimal' (999 999 999.99). I put 0.00...
1
by: dx | last post by:
I'm extremely frustrated with ASP.NET...again! To me this should be as simple as setting oCheckBox.Checked = True.. yet for some reason it isn't. I have a user control (ascx) that that has a...
0
by: Daniel Sélen Secches | last post by:
I found a good class to do a simple FTP. Very good.... I'm posting it with the message, i hope it helps someone ============================================================== Imports...
5
by: Dick | last post by:
Hello, I'm trying to serialize a class with a Hashtable within: ' Class code: Imports System.Collections Class clsOptions Public countID As Integer Public persons As New Hashtable End Class
0
by: juststarter | last post by:
Hello all, here is my problem. I am using a property grid control (in a vb.net 2003 project) in which two properties are exposed : "editorStyle" and "events". The first property is used to select...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
4
by: bob | last post by:
Why doesn't c++ let me initialize static members like this: class MySound { static CSoundManager* g_pSoundManager = NULL; };
1
by: davebaranas | last post by:
I am able to serialize this but I get a null exception when I try to deserialize it back Even if I don't make any child classes it throws "Object reference not set to an instance of an object."...
4
by: shapper | last post by:
Hello, I have a class which I am using in my profile. I made this class Serializable by using: <Serializable()_ Public Class Options One of the properties in this class is of type Level...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.