1
Reply

How can we determine whether a PHP variable is an instantiated object of a certain class?

Roshan Rathod

Roshan Rathod

4y
1.9k
0
Reply

    instanceof is used to determine whether a PHP variable is an instantiated object of a certain class.

    1. <?php
    2. class MyClass
    3. {
    4. }
    5. class NotMyClass
    6. {
    7. }
    8. $a = new MyClass;
    9. var_dump($a instanceof MyClass);
    10. var_dump($a instanceof NotMyClass);
    11. ?>

    output:

    bool(true)
    bool(false)