On Tue, Mar 15, 2011 at 8:07 AM, Andy McKenzie <amckenzie4@xxxxxxxxx> wrote: > On Mon, Mar 14, 2011 at 11:39 PM, Adam Richardson <simpleshot@xxxxxxxxx> wrote: >>> >>> This one's got me stumped. I >>> have the following line in a script: >>> >>> $this->bc = ($this->network | (~$this->netmask)) & 4294967295; >>> >>> $this->network and $this->netmask should both be of type long, and I >>> should wind up with another long. I didn't write the original method, >>> and I can't remember what "bc" stands for at the moment, but it's part >>> of a tool for working out first and last IP address, netmask, and a >>> few other things from a subnet definition. >>> >>> On the old system, it works fine. On the new system, I get the following >>> error: >>> >>> "PHP Fatal error: Unsupported operand types in >>> /var/www/test/common_subnet.inc on line 39" >>> >> >> Have you checked the types being operated on? I'm wondering if somehow one >> of the object properties you're operating on has changed has changed in >> terms of type. >> >> I'd try var_dumping each of the properties ($this->network and >> $this->netmask) the line above just to make sure they didn't somehow get >> switched to a type that bitwise operators complain about (array, Object.) >> >> Adam >> >> -- >> Nephtali: A simple, flexible, fast, and security-focused PHP framework >> http://nephtaliproject.com >> > > I'll check when I get back to work, but I doubt that's it: the last > time either is touched, it's being converted from an network address > or netmask to a long, using ip2long. I would assume that if there was > a problem with that, it would show up there, not when it got further > down. I'll check the values, though, as I say... I hadn't really > considered that something might be failing silently earlier on. > > -Alex > And, as Adam suggested, the problem is in fact with the input values. On the old system, those variables have the following values: this->network: int(168566272) this->netmask: int(4294966784) On the new system, they return: this->network: int(0) this->netmask: bool(false) Clearly there's a problem there. Here's the code that generates those values: class subnet { # Begin class subnet private $cidr; # The CIDR format network definition private $ip_array; # An array with the IP and the CIDR netmask private $ip; # The IP, as a decimal private $netmask; # The binary netmask private $network; # The network number private $bc; # beats me, but it's used all over the place. public function __construct($cidr) { # Begin __construct $this->cidr = $cidr; $this->ip_array = explode('/', $this->cidr); for($i = 1; $i <= 32; $i++) { $this->bin .= $this->ip_array[1] >= $i ? '1' : '0'; } $this->ip_array[1] = bindec($this->bin); $this->netmask = ip2long($this->ip_array[1]); $this->network = ($this->ip & $this->netmask); $this->bc = ($this->network | (~$this->netmask)) & 4294967295; } # End __construct >From there it goes on to give me functions to return the first, last, and total number of IPs in the range, the netmask, and so on. They can all be returned as either a standard ip (1.2.3.4) or a long int. Now: I did a little more looking around this morning, and it looks like I may well run into problems here given that I'm moving from a 32-bit architecture to a 64-bit architecture. Bitwise math is still fairly obscure to me, so it's likely that I'm overlooking something obvious, but maybe instead of asking "How do I fix this?" I should be asking "What would the right way to do this have been?" As I think I said before, I didn't actually write most of this code, I inherited it, and as long as the input and output of the class remain the same, I don't actually care how the work is done. If anyone has any useful input here, I'd appreciate it! -Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php