Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #18730
| From | alex <1j9448a02@lnx159sneakemail.com.invalid> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | ArrayObject vs array |
| Date | 2021-07-23 11:16 +0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <sde1e5$p89$1@gioia.aioe.org> (permalink) |
class C implements ArrayAccess, Countable, IteratorAggregate, Serializable {
private $container = ['a', 'b'];
public function offsetSet($offset, $value) {
if (is_null($offset)) {
$this->container[] = $value;
} else {
$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;
}
public function count() {
return count($this->container);
}
public function getIterator() {
return new ArrayIterator($this->container);
}
public function serialize() {
return serialize($this->container);
}
public function unserialize($data) {
$this->container = unserialize($data);
}
public function getData() {
return $this->container;
}
}
print_r(
(array) new ArrayObject(['a', 'b'])
);
print_r(
(array) new C
);
Output:
Array
(
[0] => a
[1] => b
)
Array
(
[Ccontainer] => Array
(
[0] => a
[1] => b
)
)
Because the result is not the same?
Back to comp.lang.php | Previous | Next — Next in thread | Find similar
ArrayObject vs array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-23 11:16 +0200
Re: ArrayObject vs array Jerry Stuckle <jstucklex@attglobal.net> - 2021-07-23 13:39 -0400
Re: ArrayObject vs array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-24 08:26 +0200
Re: ArrayObject vs array "J.O. Aho" <user@example.net> - 2021-07-24 12:10 +0200
Re: ArrayObject vs array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-24 13:05 +0200
Re: ArrayObject vs array Jerry Stuckle <jstucklex@attglobal.net> - 2021-07-24 12:56 -0400
Re: ArrayObject vs array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-25 11:13 +0200
Re: ArrayObject vs array "J.O. Aho" <user@example.net> - 2021-07-25 11:48 +0200
Re: ArrayObject vs array alex <1j9448a02@lnx159sneakemail.com.invalid> - 2021-07-26 10:14 +0200
Re: ArrayObject vs array "J.O. Aho" <user@example.net> - 2021-07-26 11:11 +0200
Re: ArrayObject vs array Arno Welzel <usenet@arnowelzel.de> - 2021-07-26 12:16 +0200
csiph-web