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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!