Home > Backend Development > PHP Problem > How to determine whether methods and attributes exist in php

How to determine whether methods and attributes exist in php

王林
Release: 2023-03-13 12:16:02
Original
2827 people have browsed it

php method to determine whether methods and attributes exist: [method_exists(mixed $object,string $method_name);property_exists(mixed $class,string $property);].

How to determine whether methods and attributes exist in php

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

php determines whether a method in the class exists:

bool method_exists (mixed $object, string $method_name) Check whether the method of the class exists, for example:

$directory=new Directory;
if(!method_exists($directory,'read')){
    echo '未定义read方法!';
}
Copy after login

PHP determines whether a property in the class has been defined:

bool property_exists(mixed $class, string $property) Check whether the property of the class exists, for example:

$directory=new Directory;
if(!property_exists($directory,'li')){
    echo '未定义li属性!';
}
Copy after login

Recommended learning: phptraining

The above is the detailed content of How to determine whether methods and attributes exist in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template