Lecture
The instanceof operator is used to determine whether the current object is an instance of the specified class.
The instanceof operator was added in PHP5 . Previously, the is_a () function was used, which is currently not recommended for use; it is more preferable to use the instanceof operator.
<?php
class A { }
class B { }
$thing = new A;
if ($thing instanceof A) {
echo 'A';
} if ($thing instanceof B) {
echo 'B';
}
?>
Since the $ thing object is an instance of class A , and not at all B , only the first block based on class A will be executed:
A
See also the description of the get_class () and is_a () functions.
Comments
To leave a comment
Running server side scripts using PHP as an example (LAMP)
Terms: Running server side scripts using PHP as an example (LAMP)