4

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;
}
Steven Marks
  • 704
  • 1
  • 6
  • 21
  • 2
    I highly doubt that this is CakePHP specific. It looks like a basic PHP issue. – mark May 29 '15 at 12:14
  • `$submet_mask` is most likely invalid and ip2long is returning false. Then the bitwise `~`operator is what's throwing the error. – tigrang May 29 '15 at 23:38
  • check any empty data is coming in $nm and $nw .I have faced this type of problem. – Shaddy Nov 25 '15 at 11:08

1 Answers1

0

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

Shashikala
  • 457
  • 1
  • 8
  • 25