Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

get_class

Returns the class name of an object.

Syntax

get_class(object $object): string

Parameters

ParameterTypeDescription
$objectobjectThe object.

Return value

stringThe full class name.

Examples

The class name, and the ::class form:

<?php
 
$date = new DateTimeImmutable();
 
echo get_class($date), "\n";
echo $date::class;

Output:

DateTimeImmutable
DateTimeImmutable

Notes

To check whether an object belongs to a class or its descendant, use the instanceof operator rather than comparing names.

See also

  • method_exists — Checks whether a class or an object has a method.
  • gettype — Returns the name of a value's type.

In the tutorial

  • Classes and objects — What classes and objects are in PHP, how to describe properties and methods and create objects.

Thanks for reading!

Donate to the site — we work hard for you.