Title: InputValidator
Published: March 29, 2023
Last modified: November 8, 2023

---

# class InputValidator {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/?output_format=md#source)

[ Back to top](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/?output_format=md#wp--skip-link--target)

Input validation utilities.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/?output_format=md#methods)󠁿

| Name | Description | 
| [InputValidator::has_array_access](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/has_array_access/) | Verify whether a received input parameter is _accessible as if it were an array_. | 
| [InputValidator::is_curl_handle](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/is_curl_handle/) | Verify whether a received input parameter is a Curl handle. | 
| [InputValidator::is_iterable](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/is_iterable/) | Verify whether a received input parameter is “iterable”. | 
| [InputValidator::is_numeric_array_key](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/is_numeric_array_key/) | Verify whether a received input parameter is usable as an integer array key. | 
| [InputValidator::is_string_or_stringable](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/is_string_or_stringable/) | Verify that a received input parameter is of type string or is “stringable”. | 
| [InputValidator::is_stringable_object](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/is_stringable_object/) | Verify whether a received input parameter is “stringable”. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wporg-requests-utility-inputvalidator/?output_format=md#source)󠁿

    ```php
    final class InputValidator {

    	/**
    	 * Verify that a received input parameter is of type string or is "stringable".
    	 *
    	 * @param mixed $input Input parameter to verify.
    	 *
    	 * @return bool
    	 */
    	public static function is_string_or_stringable($input) {
    		return is_string($input) || self::is_stringable_object($input);
    	}

    	/**
    	 * Verify whether a received input parameter is usable as an integer array key.
    	 *
    	 * @param mixed $input Input parameter to verify.
    	 *
    	 * @return bool
    	 */
    	public static function is_numeric_array_key($input) {
    		if (is_int($input)) {
    			return true;
    		}

    		if (!is_string($input)) {
    			return false;
    		}

    		return (bool) preg_match('`^-?[0-9]+$`', $input);
    	}

    	/**
    	 * Verify whether a received input parameter is "stringable".
    	 *
    	 * @param mixed $input Input parameter to verify.
    	 *
    	 * @return bool
    	 */
    	public static function is_stringable_object($input) {
    		return is_object($input) && method_exists($input, '__toString');
    	}

    	/**
    	 * Verify whether a received input parameter is _accessible as if it were an array_.
    	 *
    	 * @param mixed $input Input parameter to verify.
    	 *
    	 * @return bool
    	 */
    	public static function has_array_access($input) {
    		return is_array($input) || $input instanceof ArrayAccess;
    	}

    	/**
    	 * Verify whether a received input parameter is "iterable".
    	 *
    	 * @internal The PHP native `is_iterable()` function was only introduced in PHP 7.1
    	 * and this library still supports PHP 5.6.
    	 *
    	 * @param mixed $input Input parameter to verify.
    	 *
    	 * @return bool
    	 */
    	public static function is_iterable($input) {
    		return is_array($input) || $input instanceof Traversable;
    	}

    	/**
    	 * Verify whether a received input parameter is a Curl handle.
    	 *
    	 * The PHP Curl extension worked with resources prior to PHP 8.0 and with
    	 * an instance of the `CurlHandle` class since PHP 8.0.
    	 * https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.resource2object
    	 *
    	 * @param mixed $input Input parameter to verify.
    	 *
    	 * @return bool
    	 */
    	public static function is_curl_handle($input) {
    		if (is_resource($input)) {
    			return get_resource_type($input) === 'curl';
    		}

    		if (is_object($input)) {
    			return $input instanceof CurlHandle;
    		}

    		return false;
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/requests/src/utility/inputvalidator.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/Requests/src/Utility/InputValidator.php#L19)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/Requests/src/Utility/InputValidator.php#L19-L109)

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwporg-requests-utility-inputvalidator%2F)
before being able to contribute a note or feedback.