PHP | Reflection getModifiers() Function
Last Updated :
17 Dec, 2019
Improve
The Reflection::getModifiers() function is an inbuilt function in PHP which is used to return an array of the specified modifier names.
Syntax:
php
php
int Reflection::getModifiers( void )Parameters: This function does not accept any parameters. Return Value: This function returns a bitfield of the access modifiers for the specified class. Below programs illustrate the Reflection::getModifiers() function in PHP: Program 1:
<?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 function GeeksforGeeks()
$GeeksforGeeks = new ReflectionMethod('Testing', 'GeeksforGeeks');
// Calling the getModifiers() function and printing
// an array of modifiers
echo implode(' ', Reflection::getModifierNames(
$GeeksforGeeks->getModifiers()));
?>
<?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 function GeeksforGeeks()
$GeeksforGeeks = new ReflectionMethod('Testing', 'GeeksforGeeks');
// Calling the getModifiers() function and printing
// an array of modifiers
echo implode(' ', Reflection::getModifierNames(
$GeeksforGeeks->getModifiers()));
?>
Output:
Program 2:
public static
<?php
// Declaring a class Departments
class Departments {
// Calling some function with
// different modifiers
public function IT() {
return;
}
final public function CSE() {
return;
}
private function ECE() {
return;
}
}
// ReflectionMethod is called on the above class
// with their members
$A = new ReflectionMethod('Departments', 'IT');
$B = new ReflectionMethod('Departments', 'CSE');
$C = new ReflectionMethod('Departments', 'ECE');
// Calling the getModifiers() function and printing
// an array of modifiers
echo implode(' ', Reflection::getModifierNames(
$A->getModifiers())). "\n";
echo implode(' ', Reflection::getModifierNames(
$B->getModifiers())). "\n";
echo implode(' ', Reflection::getModifierNames(
$C->getModifiers())). "\n";
?>
<?php
// Declaring a class Departments
class Departments {
// Calling some function with
// different modifiers
public function IT() {
return;
}
final public function CSE() {
return;
}
private function ECE() {
return;
}
}
// ReflectionMethod is called on the above class
// with their members
$A = new ReflectionMethod('Departments', 'IT');
$B = new ReflectionMethod('Departments', 'CSE');
$C = new ReflectionMethod('Departments', 'ECE');
// Calling the getModifiers() function and printing
// an array of modifiers
echo implode(' ', Reflection::getModifierNames(
$A->getModifiers())). "\n";
echo implode(' ', Reflection::getModifierNames(
$B->getModifiers())). "\n";
echo implode(' ', Reflection::getModifierNames(
$C->getModifiers())). "\n";
?>
Output:
Reference: https://secure.php.net/manual/en/reflectionclass.getmodifiers.php
public final public private