PHP | Reflection getModifierNames() Function

The Reflection::getModifierNames() function is an inbuilt function in PHP which is used to return an array of the specified modifier names.

Syntax:

array Reflection::getModifierNames( int $modifiers )

Parameters: This function accepts single parameter $modifiers which is Bitfield of the modifiers. Here the bitfield is a data structure consisting of a number of adjacent computer memory locations.

Return Value: This function returns an array of the specified modifier names.

Below programs illustrate the Reflection::getModifierNames() function in PHP:
Program 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declaring a class Testing
class Testing
      
    // Calling a function GeeksforGeeks() with
    // two modifier named as public and static
    public static function GeeksforGeeks()
    {
        return;
    }
}
  
// ReflectionMethod is called on the class Testing and
// their member as funtion GeeksforGeeks()
$GeeksforGeeks = new ReflectionMethod('Testing', 'GeeksforGeeks');
  
// Calling the getModifierNames() function and printing
// an array of modifier names
echo implode(' ', Reflection::getModifierNames($GeeksforGeeks->getModifiers()));
?>

chevron_right


Output:

public static

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declaring a class Testing
class Testing
      
    // Calling a function GFG() with
    // two modifier named as public and static
    final public function GFG()
    {
        return;
    }
}
  
// ReflectionMethod is called on the class Testing and
// their member as funtion GFG()
$GFG = new ReflectionMethod('Testing', 'GFG');
  
// Calling the getModifierNames() function and printing
// an array of modifier names
echo implode(' ', Reflection::getModifierNames($GFG->getModifiers()));
?>

chevron_right


Output:

final public

Reference: https://www.php.net/manual/en/reflection.getmodifiernames.php




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.