English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Class/Object function reference manual
The get_parent_class() function returns the name of the parent class of the object or class
get_parent_class ( $object );
It retrieves the name of the parent class of the object or class.
If object is an object, it returns the name of the parent class of the class to which the object instance object belongs.
If object is a string, it returns the name of the parent class of the class named by this string. This feature is in PHP 4.0.5 Added in
Number | Parameters and descriptions |
---|---|
1 | object (required) The tested object or class name. |
It returns an array of names of classes declared in the current script.
The following is the usage of this function-
<?php class f1 { function f1() { //Implement some logic } } class child extends f1 { function child() { echo "I'm " , get_parent_class($this) , "'s son "; } } class child2 extends f1 { function child2() { echo "I'm " , get_parent_class('child2') , "'s son too "; } } $foo = new child(); $bar = new child2(); ?>Test and see‹/›
It will produce the following result-
I'm f1's son I'm f1's son too