类可以有位移值定义为类常量/静态变量吗?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