The get_class
method can be used to get the class name of the object.
get_class(object $object = ?): string
This method takes the object as an argument. The argument is optional if this method is called from inside the class method.
This method returns the class name.
Let’s call the get_class
method using the class object.
<?phpclass MyClass {function printClassName(){echo get_class(). "\n";}}$obj = new MyClass();echo get_class($obj). "\n";?>
In the code above, we have used the get_class
method to get the class name of the object.
Let’s call the get_class
method inside the method of the class.
<?phpclass MyClass {function printClassName(){echo get_class(). "\n";}}$obj = new MyClass();echo $obj->printClassName(). "\n";?>
In the code above, we have called the get_class
method inside the method of the MyClass
.
Find more example here.