PHP | get_called_class() Function
Last Updated :
27 Apr, 2020
The get_called_class() function is an inbuilt function in PHP which is used to get the class name where the static method is called.
Syntax:
string get_called_class( void )
Parameters: This method does not accept any parameter.
Return Value: This function returns the class name on success and returns False if it is called from outside a class.
Below programs illustrate the get_called_class() function in PHP:
Program 1:
<?php
class GFG {
public $Geek_name = "Welcome to GeeksforGeeks" ;
public function Geeks() {
var_dump(get_called_class());
}
}
GFG::Geeks();
?>
|
Program 2:
<?php
class GFG {
public function Geeks() {
var_dump(get_called_class());
}
public function GeeksforGeeks() {
var_dump(get_called_class());
}
}
GFG::Geeks();
GFG::GeeksforGeeks();
class_alias( 'GFG' , 'GeeksforGeeks' );
GeeksforGeeks::Geeks();
GeeksforGeeks::GeeksforGeeks();
?>
|
Output:
string(3) "GFG"
string(3) "GFG"
string(3) "GFG"
string(3) "GFG"
Reference: https://www.php.net/manual/en/function.get-called-class.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...