I am getting the below error in CakePHP, the function works fine in PHP just not Cake, does anyone know why this is not supported or a workaround?
Error: Unsupported operand types
File: /var/www/spitdev/console2/app/Lib/IpLib.php
Line: 40
Notice: If you want to customize this error message, create app/View/Errors/fatal_error.ctp
Function:
public function lastHost($ip_add, $subnet_mask){
$ip = ip2long($ip_add);
$nm = ip2long($subnet_mask);
$nw = ($ip & $nm);
$bc = $nw | (~$nm); <------------LINE 40
$lh = long2ip($bc - 1);
return $lh;
}
This is not problem of operand but of value passing.Make sure that $ip_add and $subnet_mask are getting VALID values and not empty. Because
$test=$this->lastHost('69.89.31.226','255.0.0.0');
var_dump($test);
returning valid result while
$test_again=$this->lastHost('','');
var_dump($test_again);
returning same error as you specified