PHP: Get name of the class of an object

Hello friends,

While working with PHP class and object hierarchy, sometimes it is difficult to know and get class name of a particular object.

To make it easy and to get class name information of an object, we can use “get_class()” function of PHP.

Where, get_class() has an object as an argument, and it returns the class name of the given object.

For Example:

class ExampleClass
{
}
$object1 = new ExampleClass();
echo get_class($object1);

And it will print the class name of the $object1.

Hope this will help you.

Speak Your Mind

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: