PHP instanceof

Description

PHP instanceof is an operator. instanceof returns true if the object on the lefthand side is of the same class, or a descendant of, the class given on the righthand side.

You can also use the instanceof keyword to check whether an object implements an interface.

Syntax

PHP instanceof has the syntax of.

$varaibleName instanceof ClassName

Example

For example, given the code &aBook = new ComputerBook;.


<?PHP//w  ww .  ja v  a 2  s . com
class Person {
}
$bill = new Person();

if ($bill instanceof Person) { 
   print("Is a person");
}
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions