How to use class_exists() function checks if a class have been defined in PHP

1 Answer

0 votes
class Test 
{
    public $pr = "Property from class Test";
     
    public function __construct()
    {
        echo 'Constructor activated from class Test <br />';
    }
       
    public function __destruct()
    {
        echo '<br /> Destructor activated from class Test <br />';
    }
     
    public function setProperty($val)
    {
        $this->pr = $val;
    }
     
    public function getProperty()
    {
        return $this->pr;
    }
}
   
if (class_exists('Test')) {
    $test_class = new Test();
    echo $test_class->getProperty(); 
}


/*
run:

Constructor activated from class Test
Property from class Test
Destructor activated from class Test   
   
*/

 



answered Mar 14, 2016 by avibootz
...