wppaste
WordPress

FilteredIterator

Source
wp-includes/Requests/src/Utility/FilteredIterator.php:20
Iterator for arrays requiring filtered values

Compatibility

WordPress
core
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 1

$callbackcallableprivate
Callback to run as a filter

Methods · 5

  • __construct()Create a new iterator
  • __unserialize()Prevent unserialization of the object for security reasons.
  • __wakeup()Perform reinitialization tasks.
  • current()Get the current item's value after filtering
  • unserialize()Prevent creating a PHP value from a stored representation of the object for security reasons.

Source code

final class FilteredIterator extends ArrayIterator {	/**	 * Callback to run as a filter	 *	 * @var callable	 */	private $callback; 	/**	 * Create a new iterator	 *	 * @param array    $data     The array or object to be iterated on.	 * @param callable $callback Callback to be called on each value	 *	 * @throws \WpOrg\Requests\Exception\InvalidArgument When the passed $data argument is not iterable.	 */	public function __construct($data, $callback) {		if (InputValidator::is_iterable($data) === false) {			throw InvalidArgument::create(1, '$data', 'iterable', gettype($data));		} 		parent::__construct($data); 		if (is_callable($callback)) {			$this->callback = $callback;		}	} 	/**	 * Prevent unserialization of the object for security reasons.	 *	 * @phpcs:disable PHPCompatibility.FunctionNameRestrictions.NewMagicMethods.__unserializeFound	 *	 * @param array $data Restored array of data originally serialized.	 *	 * @return void	 */	#[ReturnTypeWillChange]	public function __unserialize($data) {}	// phpcs:enable 	/**	 * Perform reinitialization tasks.	 *	 * Prevents a callback from being injected during unserialization of an object.	 *	 * @return void	 */	public function __wakeup() {		unset($this->callback);	} 	/**	 * Get the current item's value after filtering	 *	 * @return string	 */	#[ReturnTypeWillChange]	public function current() {		$value = parent::current(); 		if (is_callable($this->callback)) {			$value = call_user_func($this->callback, $value);		} 		return $value;	} 	/**	 * Prevent creating a PHP value from a stored representation of the object for security reasons.	 *	 * @param string $data The serialized string.	 *	 * @return void	 */	#[ReturnTypeWillChange]	public function unserialize($data) {}}

Changelog

Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/Requests/src/Utility/FilteredIterator.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.