note 126720 added to class.filteriterator
| From: | Anonymous at main dot php dot net | Date: | Mon, 27 Dec 2021 23:15:21 +0000 |
| Subject: | note 126720 added to class.filteriterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217429@lists.php.net to get a copy of this message | ||
Filter object collection by method:
<?php
/**
* @method object current()
*/
class CollectionFilterIterator extends FilterIterator
{
private $methodName;
private $methodArguments;
public function function __construct(Iterator $collection, string $methodName, array
$methodArguments = [])
{
parent::__construct($collection);
$this->methodName = $methodName;
$this->methodArguments = array_values($methodArguments);
}
public function accept(): bool
{
return (bool)
$this->current()->{$this->methodName}(...$this->methodArguments);
// or call_user_func_array([$this->current(), $this->methodName],
$this->methodArguments);
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 31.129.215.166)
----
Manual Page -- https://php.net/manual/en/class.filteriterator.php
Edit -- https://main.php.net/note/edit/126720
Del: integrated -- https://main.php.net/note/delete/126720/integrated
Del: useless -- https://main.php.net/note/delete/126720/useless
Del: bad code -- https://main.php.net/note/delete/126720/bad+code
Del: spam -- https://main.php.net/note/delete/126720/spam
Del: non-english -- https://main.php.net/note/delete/126720/non-english
Del: in docs -- https://main.php.net/note/delete/126720/in+docs
Del: other reasons-- https://main.php.net/note/delete/126720
Reject -- https://main.php.net/note/reject/126720
Search -- https://main.php.net/manage/user-notes.php