Update

As of PHP 5.3.9, the functionality of is_a() has changed. The original answer below states that is_a() must accept an Object as the first argument, but PHP versions >= 5.3.9 now accept an optional third boolean argument $allow_string (defaults to false) to allow comparisons of string class names instead:

class MyBaseClass {}
class MyExtendingClass extends MyBaseClass {}

// Original behavior, evaluates to false.
is_a(MyExtendingClass::class, MyBaseClass::class);

// New behavior, evaluates to true.
is_a(MyExtendingClass::class, MyBaseClass::class, true);

The key difference in the new behavior between instanceof and is_a() is that instanceof will always check that the target is an instantiated object of the specified class (including extending classes), whereas is_a() only requires that the object be instantiated when the $allow_string argument is set to the default value of false.


Original

Actually, is_a is a function, whereas instanceof is a language construct. is_a will be significantly slower (since it has all the overhead of executing a function call), but the overall execution time is minimal in either method.

It's no longer deprecated as of 5.3, so there's no worry there.

There is one difference however. is_a being a function takes an object as parameter 1, and a string (variable, constant, or literal) as parameter 2. So:

is_a($object, $string); // <- Only way to call it

instanceof takes an object as parameter 1, and can take a class name (variable), object instance (variable), or class identifier (class name written without quotes) as parameter 2.

$object instanceof $string;      // <- string class name
$object instanceof $otherObject; // <- object instance
$object instanceof ClassName;    // <- identifier for the class
Answer from ircmaxell on Stack Overflow
🌐
PHP
php.net › manual › en › language.operators.type.php
PHP: Type - Manual
As of PHP 8.0.0, instanceof can now be used with arbitrary expressions.
🌐
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.
Discussions

php - Instanceof and namespaces - Stack Overflow
I am facing an unexpected behaviour trying to use the following: $object instanceof $class 1/ PHP 'instanceof' keyword and namespaces work well together, as explained in the official doc. 2/ Some... More on stackoverflow.com
🌐 stackoverflow.com
Negative instanceof reported as false and method_exists not detected
When using a DateTimeInterface we get an error saying dat setTimezone method doesn't exists. Which is kinda true because it isn't defined in the php interface. So to work around this I tried defining method_exists and instanceof so that is passes PHPStan's check but it didn't. More on github.com
🌐 github.com
November 23, 2022
is_a() vs. instanceof
#externals - Opening PHP's #internals to the outside More on externals.io
🌐 externals.io
6
August 11, 2004
Type is not resolvable via match and instanceof check
$a = match (true) { $date instanceof HelloWorld => 1, default => false }; Now it is clear that if $date is instance of HellowWorld the $a is int, otherwise it is bool. But phpstan doesn't understand that and treats $a always as int|false type. More on github.com
🌐 github.com
April 5, 2024
Top answer
1 of 10
231

Update

As of PHP 5.3.9, the functionality of is_a() has changed. The original answer below states that is_a() must accept an Object as the first argument, but PHP versions >= 5.3.9 now accept an optional third boolean argument $allow_string (defaults to false) to allow comparisons of string class names instead:

class MyBaseClass {}
class MyExtendingClass extends MyBaseClass {}

// Original behavior, evaluates to false.
is_a(MyExtendingClass::class, MyBaseClass::class);

// New behavior, evaluates to true.
is_a(MyExtendingClass::class, MyBaseClass::class, true);

The key difference in the new behavior between instanceof and is_a() is that instanceof will always check that the target is an instantiated object of the specified class (including extending classes), whereas is_a() only requires that the object be instantiated when the $allow_string argument is set to the default value of false.


Original

Actually, is_a is a function, whereas instanceof is a language construct. is_a will be significantly slower (since it has all the overhead of executing a function call), but the overall execution time is minimal in either method.

It's no longer deprecated as of 5.3, so there's no worry there.

There is one difference however. is_a being a function takes an object as parameter 1, and a string (variable, constant, or literal) as parameter 2. So:

is_a($object, $string); // <- Only way to call it

instanceof takes an object as parameter 1, and can take a class name (variable), object instance (variable), or class identifier (class name written without quotes) as parameter 2.

$object instanceof $string;      // <- string class name
$object instanceof $otherObject; // <- object instance
$object instanceof ClassName;    // <- identifier for the class
2 of 10
57

Here is performance results of is_a() and instanceof:

Test name       Repeats         Result          Performance     
instanceof      10000           0.028343 sec    +0.00%
is_a()          10000           0.043927 sec    -54.98%

Test source is here.

🌐
ZetCode
zetcode.com › php › instanceof-keyword
PHP instanceof - Type Checking in PHP
April 16, 2025 - The PHP instanceof keyword is used to determine if an object is an instance of a specific class or interface. It's essential for type checking in object-oriented PHP programming.
🌐
Exakat
php-tips.readthedocs.io › en › latest › tips › instanceof_class.html
instanceof Object - PHP tips and tricks - 1.1.349
2 weeks ago - <?php class a {} $a = new a; $b = '\\a'; var_dump($a instanceof $b); var_dump($a instanceof \a); // C is not a constant, but a class name (see use) const object = '\\a'; var_dump($a instanceof object); use a as c; var_dump($a instanceof c); // compile error : unexpected T_CLASS // var_dump($a instanceof a::class); // compile error : unexpected T_CONSTANT_ENCAPS_STRING // var_dump($a instanceof 'a'); object is a type, but it can also be used as a constant name.
🌐
HashBangCode
hashbangcode.com › article › php-instanceof-operator-tips
PHP instanceof Operator Tips | #! code
What happens then, if we are trying to detect the instance of just an Administrator object, and not a User object. Unfortunately the instanceof operator can't be used here. Instead, in order to detect just the one type of class you are looking for you'll need to use a different comparison using the get_class() PHP method.
Find elsewhere
🌐
YouTube
youtube.com › watch
Use of Instanceof Keyword in Object Oriented Programming in PHP - YouTube
It can be used to check whether an object is an instance of a class or not. (see example)#oops #php #industrialtraining #slidescope
Published: May 4, 2020
🌐
Educative
educative.io › answers › what-is-the-instanceof-keyword-in-php
What is the instanceof keyword in PHP?
The instanceof keyword will compare the variable at the left (the object) to that at the right (the class) and return a true or false value.
🌐
PHPStan
phpstan.org › blog › why-is-instanceof-type-wrong-and-getting-deprecated
Why Is instanceof *Type Wrong and Getting Deprecated? | PHPStan
February 8, 2023 - Many strings, like non-empty-string, are actually an IntersectionType of StringType and some other accessory type. So in case of some strings, your straightforward check with instanceof StringType wouldn’t work as expected. For a reliable check there’s a new method PHPStan\Type\Type::isString(): TrinaryLogic.
🌐
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() being a function takes an object as parameter one, and a string as parameter two, whereas instanceof takes an object as parameter one, and can take a class name, object instance, or class identifier (class name written without quotes) as parameter two.
🌐
GitHub
github.com › phpstan › phpstan › issues › 8416
Negative instanceof reported as false and method_exists not detected · Issue #8416 · phpstan/phpstan
November 23, 2022 - However I expected that this was reproducable by creating an own interface and classes, but apperently it aint which even suprises me more, see phpstan.org/r/31858acf-2fb0-49a1-9c66-d34ddbcc1d0d · as you narrowed the type with instanceof phpstan knows that the class-types possible and therefore no error is triggered (all possible types have the method beeing used).
🌐
Externals
externals.io › message › 12086
is_a() vs. instanceof - Externals
August 11, 2004 - The class must be loaded in order to perform an instanceof check! snip Am I misunderstanding you? consider the following: <?php · class Foo {} $foo = unserialize('O:3:"Foo":0:{}'); echo '$foo is_a Foo? '. (is_a($foo, 'Foo') ? 'yes' : 'no') ."\n"; echo '$foo instanceof Foo?
🌐
Callum Muir
cmuir.co.nz › post › php-keywords › instanceof
PHP Keywords: instanceof - Callum Muir - Web Developer
March 12, 2019 - The instanceof operator allows you to check if an object is an instance of a particular class (or a class that extends a particular class) or implements a particular interface.
🌐
GitHub
github.com › phpstan › phpstan › issues › 10843
Type is not resolvable via match and instanceof check · Issue #10843 · phpstan/phpstan
April 5, 2024 - $a = match (true) { $date instanceof HelloWorld => 1, default => false }; Now it is clear that if $date is instance of HellowWorld the $a is int, otherwise it is bool. But phpstan doesn't understand that and treats $a always as int|false type.
🌐
GitHub
github.com › phpstan › phpstan › issues › 1126
The right part of instanceof should accept a (string) variable · Issue #1126 · phpstan/phpstan
June 27, 2018 - If using a variable (with a string) in a instanceof check (e.g $object instanceof $myclass), phpstan complains that with are trying to check the instance of an object with a string. The right part of instanceof should always be string, or something that can be recognized as a class, see exemple 5 of http://php.net/manual/en/language.operators.type.php.
Author: phpstan