Change language

PHP ReflectionClass getProperties () function

Syntax:
ReflectionClass::getProperties ($filter): array 
Parameters: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

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method