PHP | ReflectionMethod isPrivate() Function
Last Updated :
30 Dec, 2019
The ReflectionMethod::isPrivate() function is an inbuilt function in PHP which is used to return TRUE if the specified method is private, otherwise returns FALSE.
Syntax:
bool ReflectionMethod::isPrivate( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns TRUE if the specified method is private, otherwise returns FALSE.
Below programs illustrate the ReflectionMethod::isPrivate() function in PHP:
Program 1:
<?php
class Company {
private function GFG() {}
}
$A = new ReflectionMethod( 'Company' , 'GFG' );
$B = $A ->isPrivate();
var_dump( $B );
?>
|
Program 2:
<?php
class Department1 {
public function hr( $name ) {
return 'HR' . $name ;
}
}
class Department2 {
private function Coding() {}
}
class Department3 {
function marketing(){}
}
$A = new ReflectionMethod( 'Department1' , 'hR' );
$B = new ReflectionMethod( 'Department2' , 'Coding' );
$C = new ReflectionMethod( 'Department3' , 'marketing' );
var_dump( $A ->isPrivate());
var_dump( $B ->isPrivate());
var_dump( $C ->isPrivate());
?>
|
Output:
bool(false)
bool(true)
bool(false)
Reference: https://www.php.net/manual/en/reflectionmethod.isprivate.php
Share your thoughts in the comments
Please Login to comment...