mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
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:
parent
d9e565cad1
commit
75ce87e32c
2 changed files with 35 additions and 3 deletions
|
@ -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><!-- }}} -->
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue