Php class operator instanceof

Source: Internet
Author: User
Php type operator instanceof looks like this in some php books. The instanceof operator is introduced in PHP5. Is_a () was used before, but is_a () is outdated. it is best to use instanc php type operator instanceof

The type operator instanceof does not seem to be mentioned in some php books. in the case of php, I just mentioned that I did not elaborate on it. I just excerpted it from the manual for remarks.

The instanceof operator is introduced in PHP 5. Is_a () was used before, but is_a () is outdated. it is best to use instanceof.


1. used to determine whether a variable belongs to an instance of a class;

2. it is used to determine whether a variable is an instance that inherits the subclass of a parent class;

3. it is used to determine whether a variable is an instance of an object that implements an interface.


Before PHP 5.1.0, if the class name to be checked does not exist, instanceof will call _ autoload (). In addition, a fatal error occurs if the class is not loaded. You can avoid this problem by using dynamic class reference or using a string variable containing the class name:

Example #6 avoid class name searches and fatal errors caused by instanceof in PHP 5.0

$ D = 'notmyclass ';
Var_dump ($ a instanceof $ d); // no fatal error here
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.