Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

get_class
class
php
communitycreator

What is the get_class method in PHP?

Programming Bytes

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The get_class method can be used to get the class name of the object.

Syntax

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.

Code

Let’s call the get_class method using the class object.

<?php
class 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.

Code 2

Let’s call the get_class method inside the method of the class.

<?php
class 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.

RELATED TAGS

get_class
class
php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring