Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Andy McKenzie
On Mon, Mar 14, 2011 at 11:39 PM, Adam Richardson simples...@gmail.com 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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Andy McKenzie
On Tue, Mar 15, 2011 at 8:07 AM, Andy McKenzie amckenz...@gmail.com wrote:
 On Mon, Mar 14, 2011 at 11:39 PM, Adam Richardson simples...@gmail.com 
 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



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Andy McKenzie
 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


As it turns out, the most important lesson here is:  Don't trust what
anyone tells you.  The old server is 64-bit.  The new server is
32-bit.  Once I stopped to check that myself, it all became clear.
For the archives, here's what happened.

Everything worked fine until I ran bindec() on the binary netmask;  at
that point it returned a float rather than an int, as it it used to.
Therefore, when I ran ip2long on the result, it choked, and returned
bool(false).  Which isn't really useful when you're trying to produce
a human-readable netmask, when you get right down to it.

I still don't have a solution that will work on a 32-bit server, but
now that I know what's going on, I should be able to either find
something that will work, or get things moved to a 64-bit machine.


-Alex

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Adam Richardson
On Tue, Mar 15, 2011 at 11:50 AM, Andy McKenzie amckenz...@gmail.comwrote:

  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
 

 As it turns out, the most important lesson here is:  Don't trust what
 anyone tells you.  The old server is 64-bit.  The new server is
 32-bit.  Once I stopped to check that myself, it all became clear.
 For the archives, here's what happened.

 Everything worked fine until I ran bindec() on the binary netmask;  at
 that point it returned a float rather than an int, as it it used to.
 Therefore, when I ran ip2long on the result, it choked, and returned
 bool(false).  Which isn't really useful when you're trying to produce
 a human-readable netmask, when you get right down to it.

 I still don't have a solution that will work on a 32-bit server, but
 now that I know what's going on, I should be able to either find
 something that will work, or get things moved to a 64-bit machine.


 -Alex

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


Nice detective work, Alex.

Thanks for posting this info back to the list. I'm sure some tired-eyed
developer some time in the future will benefit from having this information
available in the list archives (it might even be me once my shabby memory
has lost the index for this valuable info.)

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Adam Richardson
On Tue, Mar 15, 2011 at 12:15 PM, Adam Richardson simples...@gmail.comwrote:

 On Tue, Mar 15, 2011 at 11:50 AM, Andy McKenzie amckenz...@gmail.comwrote:

  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
 

 As it turns out, the most important lesson here is:  Don't trust what
 anyone tells you.  The old server is 64-bit.  The new server is
 32-bit.  Once I stopped to check that myself, it all became clear.
 For the archives, here's what happened.

 Everything worked fine until I ran bindec() on the binary netmask;  at
 that point it returned a float rather than an int, as it it used to.
 Therefore, when I ran ip2long on the result, it choked, and returned
 bool(false).  Which isn't really useful when you're trying to produce
 a human-readable netmask, when you get right down to it.

 I still don't have a solution that will work on a 32-bit server, but
 now that I know what's going on, I should be able to either find
 something that will work, or get things moved to a 64-bit machine.


 -Alex

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


 Nice detective work, Alex.

 Thanks for posting this info back to the list. I'm sure some tired-eyed
 developer some time in the future will benefit from having this information
 available in the list archives (it might even be me once my shabby memory
 has lost the index for this valuable info.)

 Adam

 --
 Nephtali:  A simple, flexible, fast, and security-focused PHP framework
 http://nephtaliproject.com


My apologies:

Nice detective work ANDY (sorry, Andy, see earlier note about my shabby
memory.) I'd just replied to an Alex on another list.

Sorry.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Daniel Brown
On Tue, Mar 15, 2011 at 12:18, Adam Richardson simples...@gmail.com wrote:

 My apologies:

 Nice detective work ANDY (sorry, Andy, see earlier note about my shabby
 memory.) I'd just replied to an Alex on another list.

 Sorry.

Don't be.  He signs his emails as Alex.  I had to do a
double-take before, too.  ;-P

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Adam Richardson
On Tue, Mar 15, 2011 at 12:21 PM, Daniel Brown danbr...@php.net wrote:

 On Tue, Mar 15, 2011 at 12:18, Adam Richardson simples...@gmail.com
 wrote:
 
  My apologies:
 
  Nice detective work ANDY (sorry, Andy, see earlier note about my shabby
  memory.) I'd just replied to an Alex on another list.
 
  Sorry.

 Don't be.  He signs his emails as Alex.  I had to do a
 double-take before, too.  ;-P

 --
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/


Hah!

This was the list with the Alex. Too many lists, too few neurons.

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Daniel Brown
On Tue, Mar 15, 2011 at 12:26, Adam Richardson simples...@gmail.com wrote:

 Hah!

 This was the list with the Alex. Too many lists, too few neurons.

In the Facebook age, email really needs some sort of I Agree
button.  I'm right-on with you on that one, Adam.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Ford, Mike
 -Original Message-
 From: Andy McKenzie [mailto:amckenz...@gmail.com]
 Sent: 15 March 2011 15:51
 
 As it turns out, the most important lesson here is:  Don't trust
 what
 anyone tells you.  The old server is 64-bit.  The new server is
 32-bit.  Once I stopped to check that myself, it all became clear.
 For the archives, here's what happened.
 
 Everything worked fine until I ran bindec() on the binary netmask;
 at
 that point it returned a float rather than an int, as it it used to.
 Therefore, when I ran ip2long on the result, it choked, and returned
 bool(false).  Which isn't really useful when you're trying to
 produce
 a human-readable netmask, when you get right down to it.
 
 I still don't have a solution that will work on a 32-bit server, but
 now that I know what's going on, I should be able to either find
 something that will work, or get things moved to a 64-bit machine.

You may have to use a replacement for bindec which employs bit-shifting
to get the result you want; something like:

  function my_bindec($binstr)
  {
$binlen = strlen($binstr);
$decval = 0;
for ($i=0; $i$binlen; ++$i):
  $decval = ($decval1) | ($binstr[$i]?1:0);
endfor;

return $decval;
  }

Note: off the top of my head and completely UNTESTED!

Also, the constant 4294967295 quoted in your original message will
become a float value on a 32-bit system. It's actually a representation
of 32-bit -1, so either write it like that or use something like
ip2long('255.255.255.255') (or
my_bindec('')!!!).


Cheers!

Mike

 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507 City Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730




To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-15 Thread Joel
You might want to take a look at the BC Math functions, which can
perform operations on arbitrary length numbers.

On Tue, Mar 15, 2011 at 12:31 PM, Ford, Mike m.f...@leedsmet.ac.uk wrote:
 -Original Message-
 From: Andy McKenzie [mailto:amckenz...@gmail.com]
 Sent: 15 March 2011 15:51

 As it turns out, the most important lesson here is:  Don't trust
 what
 anyone tells you.  The old server is 64-bit.  The new server is
 32-bit.  Once I stopped to check that myself, it all became clear.
 For the archives, here's what happened.

 Everything worked fine until I ran bindec() on the binary netmask;
 at
 that point it returned a float rather than an int, as it it used to.
 Therefore, when I ran ip2long on the result, it choked, and returned
 bool(false).  Which isn't really useful when you're trying to
 produce
 a human-readable netmask, when you get right down to it.

 I still don't have a solution that will work on a 32-bit server, but
 now that I know what's going on, I should be able to either find
 something that will work, or get things moved to a 64-bit machine.

 You may have to use a replacement for bindec which employs bit-shifting
 to get the result you want; something like:

  function my_bindec($binstr)
  {
    $binlen = strlen($binstr);
    $decval = 0;
    for ($i=0; $i$binlen; ++$i):
      $decval = ($decval1) | ($binstr[$i]?1:0);
    endfor;

    return $decval;
  }

 Note: off the top of my head and completely UNTESTED!

 Also, the constant 4294967295 quoted in your original message will
 become a float value on a 32-bit system. It's actually a representation
 of 32-bit -1, so either write it like that or use something like
 ip2long('255.255.255.255') (or
 my_bindec('')!!!).


 Cheers!

 Mike

  --
 Mike Ford,
 Electronic Information Developer, Libraries and Learning Innovation,
 Leeds Metropolitan University, C507 City Campus,
 Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
 Email: m.f...@leedsmet.ac.uk
 Tel: +44 113 812 4730




 To view the terms under which this email is distributed, please go to 
 http://disclaimer.leedsmet.ac.uk/email.htm

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Failure in bitwise operations moving from 5.2.x to 5.3.x

2011-03-14 Thread Adam Richardson

 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