|
|
@@ -73,9 +73,12 @@ class Collection extends IteratorIterator implements CollectionInterface, Serial
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Throws an exception.
|
|
|
+ * Dynamic method handler
|
|
|
*
|
|
|
- * Collection doesn't permit access to methods of the inner iterator.
|
|
|
+ * Collections do not allow access to methods of the inner iterator,
|
|
|
+ * if that iterator is one of the PHP base classes as many of
|
|
|
+ * these methods allow in-place mutation which breaks the immutability
|
|
|
+ * Collection tries to provide.
|
|
|
*
|
|
|
* @param string $name Method name.
|
|
|
* @param array $args Method arguments.
|
|
|
@@ -84,6 +87,10 @@ class Collection extends IteratorIterator implements CollectionInterface, Serial
|
|
|
*/
|
|
|
public function __call($name, $args)
|
|
|
{
|
|
|
+ if (!method_exists(ArrayIterator::class, $name)) {
|
|
|
+ $inner = $this->getInnerIterator();
|
|
|
+ return call_user_func_array([$inner, $name], $args);
|
|
|
+ }
|
|
|
throw new BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $name));
|
|
|
}
|
|
|
|