Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

get_class()

get_class() is a PHP native function, that returns the name of the class of an object.

get_class() returns the full name of the class, including its namespace and original letter cases.

get_class() may be replaced by the magic method __CLASS__ when operating on $this. It may also be replaced with an object in other situation, such as fetching a static constant, or instantiating a new object.

<?php

namespace Zoo\Savanna;

class Elephpant {}

$trunk = new Elephpant;
print get_class(); //Zoo\Savanna\Elephpant

$herd = new $trunk;
print get_class(); //Zoo\Savanna\Elephpant

?>

Documentation

See Also