Thursday, October 16, 2025
HomeLanguagesPHP | get_called_class() Function

PHP | get_called_class() Function

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
  
// Create a class
class GFG {
    public $Geek_name = "Welcome to neveropen"; 
      
    public function Geeks() {
        var_dump(get_called_class());
    }
}
  
GFG::Geeks();
  
?>


Output:

string(3) "GFG"

Program 2:




<?php
  
// Create a class
class GFG {
  
    public function Geeks() {
        var_dump(get_called_class());
    }
      
    public function neveropen() {
        var_dump(get_called_class());
    }
}
  
GFG::Geeks();
GFG::neveropen();
  
class_alias('GFG', 'neveropen');
  
neveropen::Geeks();
neveropen::neveropen();
  
?>


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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11953 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS