L'interface ArrayAccess
ArrayAccess
&reftitle.intro;
Interface permettant d'accéder aux objets de la même façon que pour les tableaux.
&reftitle.classsynopsis;
ArrayAccess
ArrayAccess
Méthodes
Basic usage
container = array(
"un" => 1,
"deux" => 2,
"trois" => 3,
);
}
public function offsetSet($offset, $value) {
$this->container[$offset] = $value;
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
}
public function offsetUnset($offset) {
unset($this->container[$offset]);
}
public function offsetGet($offset) {
return isset($this->container[$offset]) ? $this->container[$offset] : null;
}
}
$obj = new obj;
var_dump(isset($obj["deux"]));
var_dump($obj["deux"]);
unset($obj["deux"]);
var_dump(isset($obj["deux"]));
$obj["deux"] = "Une valeur";
var_dump($obj["deux"]);
?>
]]>
&example.outputs.similar;
&language.predefined.arrayaccess.offsetexists;
&language.predefined.arrayaccess.offsetget;
&language.predefined.arrayaccess.offsetset;
&language.predefined.arrayaccess.offsetunset;