Wednesday 5 May 2021

Php: class_exists: Check whether class is defined or not

Signature

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

 

Description

Checks if the class has been defined

 

employee.php

<?php

class Employee{
    
}
?>

 

class_exist_demo.php

#!/usr/bin/php

<?php

    $is_exist = class_exists('Employee');
    echo "is Employee exist : ";
    var_dump($is_exist);

    include 'employee.php';

    $is_exist = class_exists('Employee');
    echo "\nis Employee exist : ";
    var_dump($is_exist);

?>

 

Output

$ ./class_exist_demo.php 

is Employee exist : bool(false)

is Employee exist : bool(true)

 

 

 

 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment