get_called_class

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

get_called_classThe "Late Static Binding" class name

Descrizione

get_called_class(): string

Gets the name of the class the static method is called in.

Elenco dei parametri

Questa funzione non contiene parametri.

Valori restituiti

Returns the class name.

Errori/Eccezioni

If get_called_class() is called from outside a class, an Error is thrown. Prior to PHP 8.0.0, an E_WARNING level error was raised.

Log delle modifiche

Versione Descrizione
8.0.0 Calling this function from outside a class, will now throw an Error. Previously, an E_WARNING was raised and the function returned false.

Esempi

Example #1 Using get_called_class()

<?php

class foo {
static public function
test() {
var_dump(get_called_class());
}
}

class
bar extends foo {
}

foo::test();
bar::test();

?>

Il precedente esempio visualizzerà:

string(3) "foo"
string(3) "bar"

Vedere anche:

  • get_parent_class() - Restituisce il nome della classe genitrice di un oggetto o di una classe
  • get_class() - Restituisce il nome della classe di un oggetto
  • is_subclass_of() - Verifica se l'oggetto ha questa classe come una dei suoi genitori o la implementa