類可以有位移值定義爲類常量/靜態變量嗎?php類常量與位值
我想要實現類似於這裏所描述的一個權限系統http://www.litfuel.net/tutorials/bitwise.htm(對不起最好的例子,我可以從一個快速谷歌找到)
例如香港專業教育學院試過這種
class permissions { const perm1 =1; const perm2 =2; const perm3 =4; //--CUT-- const perm24 =8388608;這給const perm25 = perm1 | perm2;
}
syntax error, unexpected '|', expecting ',' or ';'
和優選方式
class permissions {
static $perm1 =1<<0;
static $perm2 =1<<1;
static $perm3 =1<<2;
//--CUT--
static $perm24 =1<<23;
static $perm25 = $perm1 | $perm2;
}
其給出
syntax error, unexpected T_SL, expecting ',' or ';'
後者的工作方式的一類環境例如
$perm1 =1<<0;
$perm2 =1<<1;
$perm3 =1<<2;
//--CUT--
$perm24 =1<<23;
$perm25 = $perm1 | $perm2;
echo $perm25;
給予外部的預期的3(2 + 1)(或2^0 + 2^1)
在課堂上定義這個最好的方法是什麼?
使用的__construct方法 – machineaddict 2013-05-08 22:09:27
'$ PERM1 = 1 << 0;'不限定恆定;它定義了一個變量 – 2013-05-08 22:11:42