PHP - get_parent_class
Trieda
Metóda - get_parent_class
(PHP 4, PHP 5, PHP 7)
Returns the name of the parent class of an object or class.
Procedurálne
- function get_parent_class (mixed $object) : string
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $object | mixed | An instance of a class or its name. The parameter is optional if called within the class. |
Mávratovej hodnoty
Vracia: string
Returns the name of the class from which the class or instance specified in the parameter is inherited.
Príklady
<?php
class Person
{
// Variables, constructor, methods ...
}
class Programmer extends Person
{
function getMyParent()
{
// the parameter of the function is optional
echo "My parent is " , get_parent_class() , ".";
}
}
class WebDeveloper extends Programmer
{
// Variables, constructor, methods ...
}
$programmer = new Programmer();
$programmer->getMyParent();
// the function parameter is the object
echo "The parent of Programmer is " , get_parent_class($programmer) , ".";
// the function parameter is the class name
echo "The parent of WebDeveloper is " , get_parent_class("WebDeveloper") , ".";
Výstupem je:
My parent is Person. The parent of Programmer is Person. The parent of WebDeveloper is Programmer.
Súvisiace manuály
- function is_subclass_of (mixed $object, string $class_name, bool $allow_string = TRUE) : bool
