Roshan Rathod
How can we determine whether a PHP variable is an instantiated object of a certain class?
By Roshan Rathod in PHP on Aug 16 2020
  • Rajanikant Hawaldar
    Sep, 2020 27

    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)

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS