Re: optimizing space for array of booleans

From: Date: Wed, 25 Feb 2009 06:11:53 +0000
Subject: Re: optimizing space for array of booleans
References: 1 2 3 4 5 6 7 8  Groups: php.general 
Request: Send a blank email to php-general+get-288779@lists.php.net to get a copy of this message
leledumbo wrote:
Good points, I'll try it.
Without testing it (it's late here), your binstr() function doesn't accept parameters, so it would always return the same result each time it's called, regardless of what you pass into it.
In case you want to check it tomorrow or later: private function binstr() { $temp_bits = $this->bits; $str = ""; for ($i=0;$i<32;$i++) {
    $str = strval($temp_bits & 1) . $str;
    $temp_bits >>= 1;
} return $str; } it doesn't accept parameters, but instead use private field $bits assigned to $temp_bits (PHP manual states that it will be copied instead of referenced, and it's exactly what I need).
but you're trying to pass stuff to it: public function tostring() {
    $str = $this->binstr($this->bits[0]);
    for ($i=1;$i<8;$i++)
      $str .= "," . $this->binstr($this->bits[$i]);
    return $str;
} -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#288779) next »