get_class
Returns the class name of an object.
Syntax
get_class(object $object): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $object | object | The 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
DateTimeImmutableNotes
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.