Home  >  Article  >  Backend Development  >  How to determine whether a class exists in php

How to determine whether a class exists in php

青灯夜游
青灯夜游Original
2022-02-10 10:12:153563browse

In PHP, you can use the class_exists() function to determine whether the specified class exists. The function of this function is to check whether the class has been defined. The syntax is "class_exists('class name')"; if the specified class If it has been defined (exists), it returns true, otherwise it returns false.

How to determine whether a class exists in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, you can use the class_exists() function To determine whether the specified class exists.

The class_exists() function can check whether the specified class has been defined.

Syntax:

class_exists(string $class, bool $autoload = true): bool
  • class: class name. Name matching is case-insensitive.

  • autoload: Whether to call __autoload by default.

Return value:

  • If the class pointed to by class has been defined, this function returns true , otherwise return false.

Example 1: Check whether class HelloWorld has been defined

class_exists() will try to call _autoload by default, if you don’t want class_exists() When calling _autoload, you can set the autoload parameter to FALSE.

Example 2: autoload parameter example

Recommended learning: "PHP Video Tutorial"

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

Statement:
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