PHP | ReflectionClass getDefaultProperties() Function
The ReflectionClass::getDefaultProperties() function is an inbuilt function in PHP which is used to return the default properties including inherited properties from a specified class.
Syntax:
ReflectionClass::getDefaultProperties(void) : array
Parameters: This function does not accept any parameter.
Return Value: This function returns an array of default properties. These properties are having space for property’s keys and its values. The key is the name of the property and values are the default value of the property. And it also returns NULL if the property is not having any default values.
Below programs illustrate the ReflectionClass::getDefaultProperties() function in PHP:
Program 1:
<?php
class College {
protected $College_Name = 'IIT Delhi' ;
}
class Departments extends College {
public $Dept1 = 'CSE' ;
private $Dept2 = 'ECE' ;
public static $Dept3 = 'EE' ;
}
$ReflectionClass = new ReflectionClass( 'Departments' );
var_dump( $ReflectionClass ->getDefaultProperties());
?>
|
Output:
array(4) {
["Dept3"]=>
string(2) "EE"
["Dept1"]=>
string(3) "CSE"
["Dept2"]=>
string(3) "ECE"
["College_Name"]=>
string(9) "IIT Delhi"
}
Program 2:
<?php
class College {
protected $College_Name = 'IIT Delhi' ;
}
class Departments extends College {
public $Dept1 ;
private $Dept2 ;
public static $Dept3 ;
}
$ReflectionClass = new ReflectionClass( 'Departments' );
var_dump( $ReflectionClass ->getDefaultProperties());
?>
|
Output:
array(4) {
["Dept3"]=>
NULL
["Dept1"]=>
NULL
["Dept2"]=>
NULL
["College_Name"]=>
string(9) "IIT Delhi"
}
Reference: https://www.php.net/manual/en/reflectionclass.getdefaultproperties.php
Last Updated :
30 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...