Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

class_exists

Description

The class_exists of Class / Object for PHP checks if the class has been defined.

Syntax

class_exists(
    string $class,
    bool $autoload = true
): bool

Parameters

class

The class name. The name is matched in a case-insensitive manner.

autoload

Whether to autoload if not already loaded.

Return

Returns true if class is a defined class, false otherwise.

Examples

1 · class

<?php

class myclass
{
}

$class = "myclass";

$return = class_exists($class);

var_export($return);

true

2 · autoload · false

<?php

spl_autoload_register();

class myclass
{
}

$class = "myclass";
$autoload = false;

$return = class_exists($class, $autoload);

var_export($return);

true

3 · autoload · true

<?php

spl_autoload_register();

class myclass
{
}

$class = "myclass";
$autoload = true;

$return = class_exists($class, $autoload);

var_export($return);

true
HomeMenu