Slide 10
Slide 10 text
AccessArray
• get,set,isset,unset
を実装
class
Uint8Array
implements
ArrayAccess
{
protected
$container;
funcmon
__construct($n)
{
$this-‐>arraySize
=
$n;
$this-‐>container
=
str_repeat("\0",
$n);
}
public
funcmon
offsetGet($offset)
{
return
ord($this-‐>container[$offset]);
}
public
funcmon
offsetSet($offset,
$value)
{
$this-‐>container[$offset]
=
chr($value);
}
public
funcmon
offsetExists($offset)
{
;;;
}
public
funcmon
offsetUnset($offset)
{
;;;
}
}
$a
=
new
Uint8Array(5);
$a[2]
=
7;
var_dump($a[1],
$a[2]);
=>
int(0)
int(7)