Use an array filter :

if (count(array_filter($data, function ($entry) {
        return !($entry instanceof CriterioDigital);
})) > 0) {
    throw new \DomainException('an array of CriterioDigital must be provided');
}
Answer from ceadreak on Stack Overflow
🌐
Experts Exchange
experts-exchange.com › questions › 28694698 › PHP-how-to-use-instanceof-on-an-array.html
Solved: PHP, how to use instanceof on an array | Experts Exchange
July 4, 2015 - Both your responses did help though, but I had to spend a bit more time going through your links. I now know I have to use gettype() first, and if it says object, then I can use getclass() to determine what class it is. gettype() would've also returned 'array' if the variable were an array, which was what I was looking for.
Discussions

Hmm.. shouldn't is_array() check for instanceof ArrayAccess ?
I've come across this before and, however inconvenient, it is logical. is_array checks specifically for type. Similar to is_string & __toString. If is_array was to accept decorated objects as you described then testing for true arrays would be even more hacky; !is_object? Wat. Without knowing how you are trying to use is_array its hard to provide a decent solution. I would probably create a utility is_iterable or is_traversable .. you get the idea. More on reddit.com
🌐 r/lolphp
22
6
April 8, 2013
php - How to check if variable is array?... or something array-like - Stack Overflow
With $var = array(1,2,3); the results ... and $var instanceof Traversable = false. 2016-12-11T06:49:16.063Z+00:00 ... @ADTC Yeah, just checked. Arrays do not implement Iterator and therefore don't work with Traversable. 2016-12-11T12:02:36.693Z+00:00 ... You don't need to specifically check for Traversable as others have hinted it in their answers, because all objects - like all arrays - are traversable in PHP... More on stackoverflow.com
🌐 stackoverflow.com
Issue with instanceof checks with a `class-string<T>` param
Instanceof between array|object and class-string will always evaluate to false. https://phpstan.org/r/6324ace5-d6e3-467c-8e4c-53aedaa239f8 More on github.com
🌐 github.com
6
March 4, 2020
Newest Questions - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers More on stackoverflow.com
🌐 stackoverflow.com
🌐
HashBangCode
hashbangcode.com › article › php-instanceof-operator-tips
PHP instanceof Operator Tips | #! code
Passing in the previously created user object and an array that contains the instance types we are looking for as strings returns true. var_dump(isInstanceOf($user, ['UserInterface', 'ProductInterface', 'OrderInterface'])); // Returns true · The instanceof operator will also work for child objects.
🌐
PHP
php.net › manual › en › language.operators.type.php
PHP: Type - Manual
« Array · Preface · Language Reference · Operators · instanceof is used to determine whether a PHP variable is an instantiated object of a certain class: Example #1 Using instanceof with classes ·
🌐
W3Schools
w3schools.com › php › func_var_is_array.asp
PHP is_array() Function
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
Rip Tutorial
riptutorial.com › instanceof (type operator)
PHP Tutorial => instanceof (type operator)
For checking whether some object is of a certain class, the (binary) instanceof operator can be used since PHP version 5.
🌐
W3Schools
w3schools.com › php › keyword_instanceof.asp
PHP instanceof Keyword
The instanceof keyword is used to check if an object belongs to a class. The comparison returns true if the object is an instance of the class, it returns false if it is not. Read more about object and classes in our PHP OOP Tutorial.
🌐
Reddit
reddit.com › r/lolphp › hmm.. shouldn't is_array() check for instanceof arrayaccess ?
r/lolphp on Reddit: Hmm.. shouldn't is_array() check for instanceof ArrayAccess ?
April 8, 2013 -

I find it kinda odd that is_array() does not check for instance of ArrayAccess. If you introduce collection like object in your code, you gotta recheck all of in_array() usage and change it to:

if (is_array($input) || $input instanceof \ArrayAccess) {

And since the purpose of the ArrayAccess interface is 'to provide accessing objects as arrays' , shouldn't is_array() return true?

I know that my $input in that case is object, that's why is_array() returns false, but isn't that kinda 'logical' error?

The only reason I am using is_array() on an array/variable, is cause there is no other way to tell if I can run array related functions on it, aka if it fulfills the contract of ArrayAccess so I can access it as an array.

The information that actually it is an object or not, is secondary/irrelevant at this point to me.

Edit: forgot to add context, here it is:

if (is_array($input) || $input instanceof \ArrayAccess) {
    array_walk_recursive($input, [$this,'sanitizeInputToken']);
    return $input;
}

Please note guys, I am not looking on how to solve this particular 'problem'. A wrapper method comes to mind or what not. I am just puzzled by PHP behaviour in that case.

Anyways thanks all for posting!

Find elsewhere
🌐
ProcessWire
processwire.com › community support › api & templates
[SOLVED] A question for PHP pros (variable as instanceof argument) - API & Templates - ProcessWire Support Forums
February 24, 2019 - Could somebody please tell me why this works ... $templates = $this->wire('templates'); $messageTemplates = array(); $className = 'FieldtypeMessageMeta'; foreach ($templates as $t) { foreach ($t->fields as $f) { if ($f->type instanceof $className) { $messageTemplates[] = $t->name; bre...
🌐
GeeksforGeeks
geeksforgeeks.org › php › what-is-the-difference-between-is_a-function-and-instanceof-in-php
What is the difference between is_a() function and instanceof in PHP? - GeeksforGeeks
July 11, 2025 - The is_a() is a function, whereas instanceof is a language construct. The is_a() function will be significantly slower since it has all the overhead of executing a function call. In case of callback in functions (like array_map) instanceof is not a function, it is a language construct, so it cannot use as callback.
🌐
GitHub
github.com › phpstan › phpstan › issues › 3060
Issue with instanceof checks with a `class-string<T>` param · Issue #3060 · phpstan/phpstan
March 4, 2020 - Instanceof between array|object and class-string<T of LoyaltyCorp\RequestHandlers\Request\RequestObjectInterface> will always evaluate to false. https://phpstan.org/r/6324ace5-d6e3-467c-8e4c-53aedaa239f8
Author: phpstan
🌐
Reintech
reintech.io › blog › mastering-php-is-array-function-array-validation
Mastering PHP's `is_array()` Function for Array Validation
April 14, 2023 - This guide explores practical applications, edge cases, and integration patterns that professional PHP developers encounter in production environments. The is_array() function performs a type check on a variable, returning a boolean value based on whether the variable is an array type.
🌐
W3Schools
w3schools.com › php › php_arrays_functions.asp
PHP Array Functions
PHP has a set of built-in functions that you can use on arrays.