This is in relation to my post here but taken in a completely different direction Charset detection in PHP
essentially, i\'m looking to reduce the memory that many h
Don't tell nobody!
class IntegerstringArray IMPLEMENTS ArrayAccess {
var $evil = "0000111122220000ffff";
// 16 bit each
function offsetExists ( $offset ) {
return (strlen($this->evil) / 4) - 1 >= $offset;
}
function offsetGet ( $offset ) {
return hexdec(substr($this->evil, $offset * 4, 4));
}
function offsetSet ( $offset , $value ) {
$hex = dechex($value);
if ($fill = 4 - strlen($hex)) {
$hex = str_repeat("0", $fill) . $hex;
}
for ($i=0; $i<4; $i++) {
$this->evil[$offset*4+$i] = $hex[$i];
}
}
function offsetUnset ( $offset ) {
assert(false);
}
}
So you can pretty much create an array object from this:
$array = new IntegerstringArray();
$array[2] = 65535;
print $array[2];
It internally stores a list and accepts 16-bit integers. The array offsets must be consecutive.
Not tested. Just as an implementation guide.