I have a function that will create a php code that will do a bitwire operation.
this code is generated by function
1 | 2 | 4
what I want to do is return the result of the operation. return (1 | 2 | 4);
I tried to use eval()
but I get the following error
Parse error: syntax error, unexpected end of file in ..... : eval()'d code on line 1
The flowing is my code
<?php
class Roles
{
protected $rolesList = array();
public function __construct(){
$this->rolesList = array(
'can_use' => 1,
'can_view' => 2, //0000000001
'can_update' => 4, //0000000010
'can_insert' => 8, //0000000100
'can_delete' => 16 //0000001000
);
}
public function mapRoles(){
if ( func_num_args() == 0 ){
return false; //no args passed
}
$tmp = array();
$parmeters = func_get_args();
foreach($parmeters as $arg){
$tmp[] = $this->rolesList[$arg];
}
$cmd = implode(' | ', $tmp);
return eval($cmd);
}
}
?>