class MyClass { // Class definition } if (object_exists('MyClass')) { echo 'The MyClass object exists'; } else { echo 'The MyClass object does not exist'; }
$obj = new MyClass(); if (object_exists($obj)) { echo 'The instantiated MyClass object exists'; } else { echo 'The instantiated MyClass object does not exist'; }This function is a part of the PHP core and doesn't require any package or library.