<?php
class MyModel
{
}
class Collection implements \ArrayAccess, \Iterator
{
private $storage = array();
public function offsetExists($offset)
{
return isset($this->storage[$offset]);
}
public function offsetGet($offset)
{
return $this->storage[$offset];
}
public function offsetSet($offset, $value)
{
if (null === $offset) {
$this->storage[] = $value;
} else {
$this->storage[$offset] = $value;
}
}
public function offsetUnset($offset)
{
echo 'trying to unset' . PHP_EOL;
$this->storage[$offset] = null;
}
public function current()
{
return current($this->storage);
}
public function next()
{
return next($this->storage);
}
public function key()
{
return key($this->storage);
}
public function valid()
{
return key($this->storage) !== null;
}
public function rewind()
{
reset($this->storage);
}
public function count()
{
return count($this->storage);
}
}
class MyCollectionModel
{
private $collection;
public function __construct()
{
$this->collection = new Collection();
}
public function addElement($element)
{
$this->collection[] = $element;
}
public function removeMyModels()
{
foreach ($this->collection as $index => $value) {
if ($value instanceof MyModel) {
unset ($this->collection[$index]);
}
}
}
}
// Создем коллекцию
$myCollection = new MyCollectionModel();
// Заполняем своими можельками
for ($i = 0; $i < 10; $i++) {
$myCollection->addElement(new MyModel());
}
// Удаляем свои модельки
$myCollection->removeMyModels();
// Сука, ебучая PHP!!!
print_r($myCollection);
Deprecated: Return type of Collection::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 11
Deprecated: Return type of Collection::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 16
Deprecated: Return type of Collection::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 21
Deprecated: Return type of Collection::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 30
Deprecated: Return type of Collection::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 36
Deprecated: Return type of Collection::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 41
Deprecated: Return type of Collection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 46
Deprecated: Return type of Collection::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 51
Deprecated: Return type of Collection::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/7hYBN on line 56
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
MyCollectionModel Object
(
[collection:MyCollectionModel:private] => Collection Object
(
[storage:Collection:private] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
)
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/7hYBN on line 7
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/7hYBN on line 7
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
trying to unset
MyCollectionModel Object
(
[collection:private] => Collection Object
(
[storage:private] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
)
Output for 5.0.0 - 5.0.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/7hYBN on line 7
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/7hYBN on line 7
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOL
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/7hYBN on line 32
trying to unsetPHP_EOLMyCollectionModel Object
(
[collection:private] => Collection Object
(
[storage:private] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
)
)
)
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting '{' in /in/7hYBN on line 7
Process exited with code 255.