ReflectionClass::getProperties ($filter): arrayParameters:this function takes filterparameters, which helps to remove some reflected properties.Return value:this function returns an array of reflected properties.The following programs illustrate the function ReflectionClass::getProperties() in PHP:
Program 1:
// Definition of a class named Departments
class
Departments {
public
$Dept1
=
’CSE’
;
private
$Dept2
=
’ECE’
;
public
static
$Dept3
=
’EE’
;
}
// Using ReflectionClass over the Departments class
$ReflectionClass
=
new
ReflectionClass (
’Departments’
);
// Call the getProperties() function through the filter
// ReflectionProperty::IS_PUBLIC which
// will reflect the results of public properties only
$A
=
$ReflectionClass
-> getProperties (ReflectionProperty::IS_PUBLIC);
// Get array of reflected properties
var_dump (
$A
);
?>
Output: array (2) {[0] = > object (ReflectionProperty) # 2 (2) {["name"] = > string (5) "Dept1" ["class"] = > string (11) "Departments"} [1] = > object (ReflectionProperty) # 3 (2) {["name"] = > string (5) "Dept3" ["class"] = > string (11) "Departments"}}
Program 2:
// Definition of a class named Company
class
Company {
public
$C1
;
private
$C2
;
public
static
$C3
;
}
// Using ReflectionClass over the Company class
$ReflectionClass
=
new
ReflectionClass (
’Company’
);
// Call the getProperties() function without
// any filter
$A
=
$ReflectionClass
-> getProperties();
// Get array of reflected properties
var_dump (
$A
);
?>
Exit:array (3 ) {[0] = > object (ReflectionProperty) # 2 (2) {["name"] = > string (2) "C1" ["class"] = > string (7) "Company"} [1] = > object (ReflectionProperty) # 3 (2) {["name"] = > string (2) "C2" ["class"] = > string (7) "Company"} [2] = > object (ReflectionProperty) # 4 (2) {["name"] = > string (2) "C3" ["class"] = > string (7) "Company"}}
Link: https : //www.php.net/manual/en/reflectionclass.getproperties.php