Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determining a PHP object's name

Tags:

object

oop

php

In Java (well, Android's version at least) all objects have a getClass() method which returns the object's class and you can then call getSimpleName() to get the human-readable name of the object. This is great for logging. I'd like to be able to do something similar in a PHP program I've been working on. Is there any way to find out what type of object "this" is?

like image 765
Jeremy Logan Avatar asked Dec 29 '09 18:12

Jeremy Logan


2 Answers

return get_class($this);
like image 127
Victor Nicollet Avatar answered Sep 28 '22 02:09

Victor Nicollet


I think this php.net man page may have the answers your looking for: http://php.net/manual/en/function.get-class.php

like image 21
Thomas Vincent Avatar answered Sep 28 '22 03:09

Thomas Vincent