PHP | ReflectionMethod __toString() Function
Last Updated :
23 Dec, 2019
The ReflectionMethod::__toString() function is an inbuilt function in PHP which is used to return the string representation of the specified method object.
Syntax:
string ReflectionMethod::__toString ( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the string representation of the specified method object.
Below programs illustrate the ReflectionMethod::__toString() function in PHP:
Program 1:
<?php
class Company {
function GFG() {}
}
$A = new ReflectionMethod( 'Company' , 'GFG' );
$B = $A ->__toString();
var_dump( $B );
?>
|
Output:
string(94) "Method [ <user> public method GFG ] {
@@ /home/43d46426def0fce620e2e2cf2bf10e7a.php 6 - 6
}
"
Program 2:
<?php
class Department1 {
private function hr( $name ) {
return 'HR' . $name ;
}
}
class Department2 {
static function Coding() {}
}
class Department3 {
protected function marketing(){}
}
$A = new ReflectionMethod( 'Department1' , 'hR' );
$B = new ReflectionMethod( 'Department2' , 'Coding' );
$C = new ReflectionMethod( 'Department3' , 'marketing' );
var_dump( $A ->__toString());
var_dump( $B ->__toString());
var_dump( $C ->__toString());
?>
|
Output:
string(158) "Method [ <user> private method hr ] {
@@ /home/2aa9608c9056b85288d53e96d9de3310.php 6 - 8
- Parameters [1] {
Parameter #0 [ <required> $name ]
}
}
"
string(106) "Method [ <user> static public method Coding ] {
@@ /home/2aa9608c9056b85288d53e96d9de3310.php 12 - 12
}
"
string(105) "Method [ <user> protected method marketing ] {
@@ /home/2aa9608c9056b85288d53e96d9de3310.php 17 - 17
}
"
Reference: https://www.php.net/manual/en/reflectionmethod.tostring.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...