Show the use $obj[] within an ArrayAccess interface.

Fix bug#52308

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@301180 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Richard Quadling 2010-07-12 10:35:59 +00:00
parent d9e565cad1
commit 75ce87e32c
2 changed files with 35 additions and 3 deletions

View file

@ -55,7 +55,11 @@ class obj implements arrayaccess {
);
}
public function offsetSet($offset, $value) {
$this->container[$offset] = $value;
if (is_null($offset)) {
$this->container[] = $value;
} else {
$this->container[$offset] = $value;
}
}
public function offsetExists($offset) {
return isset($this->container[$offset]);
@ -76,7 +80,10 @@ unset($obj["two"]);
var_dump(isset($obj["two"]));
$obj["two"] = "A value";
var_dump($obj["two"]);
$obj[] = 'Append 1';
$obj[] = 'Append 2';
$obj[] = 'Append 3';
print_r($obj);
?>
]]>
</programlisting>
@ -87,6 +94,19 @@ bool(true)
int(2)
bool(false)
string(7) "A value"
obj Object
(
[container:obj:private] => Array
(
[one] => 1
[three] => 3
[two] => A value
[0] => Append 1
[1] => Append 2
[2] => Append 3
)
)
]]>
</screen>
</example><!-- }}} -->

View file

@ -61,10 +61,22 @@
<programlisting role="php">
<![CDATA[
<?php
$arrayaccess[] = "value";
$arrayaccess[] = "first value";
$arrayaccess[] = "second value";
print_r($arrayaccess);
?>
]]>
</programlisting>
&example.output;
<screen>
<![CDATA[
Array
(
[0] => first value
[1] => second value
)
]]>
</screen>
</informalexample>
</para>
</note>