PHP instanceof
In this chapter you will learn:
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/* j av a 2 s. c om*/
class Person {
}
$bill = new Person();
if ($bill instanceof Person) {
print("Is a person");
}
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter: