PHP | ReflectionFunction __toString() Function
The ReflectionFunction::__toString() function is an inbuilt function in PHP which is used to return the string representation of the specified function.
Syntax:
string ReflectionFunction::__toString( void )
Parameters: This function does not accept any parameters.
Return Value: This function returns the string representation of the specified function.
Below programs illustrate the ReflectionFunction::__toString() function in PHP:
Program 1:
php
<?php
function Company( $Company_Name , $Role )
{
return sprintf("%s %s\r\n", $Company_Name , $Role );
}
$function = new ReflectionFunction( 'company' );
$A = $function ->__toString();
echo $A ;
?>
|
Output:
Function [ <user> function Company ] {
@@ /home/a39c30763ecfc7f257d02e44de746b22.php 4 - 7
- Parameters [2] {
Parameter #0 [ <required> $Company_Name ]
Parameter #1 [ <required> $Role ]
}
}
Program 2:
php
<?php
function Trial1( $First_Args , $Second_Args )
{
return sprintf("%s %s\r\n", $First_Args , $Second_Args );
}
function Trial2( $First_Args , $Second_Args )
{
return sprintf("%s %s\r\n", $First_Args , $Second_Args );
}
$function = new ReflectionFunction( 'Trial1' );
$function = new ReflectionFunction( 'Trial2' );
echo $function ->__toString();
echo $function ->__toString();
?>
|
Output:
Function [ <user> function Trial2 ] {
@@ /home/09f598906ca0bfcad4613b5dea41c27b.php 9 - 12
- Parameters [2] {
Parameter #0 [ <required> $First_Args ]
Parameter #1 [ <required> $Second_Args ]
}
}
Function [ <user> function Trial2 ] {
@@ /home/09f598906ca0bfcad4613b5dea41c27b.php 9 - 12
- Parameters [2] {
Parameter #0 [ <required> $First_Args ]
Parameter #1 [ <required> $Second_Args ]
}
}
Reference: https://www.php.net/manual/en/reflectionfunction.tostring.php
Last Updated :
07 Feb, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...