PHP: Is it possible to retrieve the class name of a child class?

Use get_class($this) It works for sub-class, sub-sub-class, the parent class, everything. Just try it! ;).

Use get_class($this). It works for sub-class, sub-sub-class, the parent class, everything. Just try it!

;).

Class Person { public function __construct() { echo get_class($this); } } class Bob extends Person { //do some stuff } $b = new Bob; prints Bob as explained in "Example #2 Using get_class() in superclass" at docs.php.net/get_class.

Class Bob extends Person { //do some stuff } class Person { public function __construct() { var_dump(get_class($this)); // Bob var_dump(get_class()); // Person } } new Bob; Source: php.net/manual/en/function.get-class.php.

Same here - he wanted the child class. – Franz Dec 10 '09 at 23:13 This code is now correct since it has been edited. – Kevin Dec 10 '09 at 23:17 1 In my haste, I placed the main logic in the wrong location.

I'm going to use my CLASS constant idea to do one more edit. – simeonwillbanks Dec 10 '09 at 23:20.

CLASS__.", and my parent is named " , get_parent_class($this) , ". My name is ". __CLASS__.", and I have a child named " , get_class($this) , ".

My name is Person, and I have a child named Bob. I'm Bob, and my parent is named Person.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions