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 // Initializing a user-defined function function Company( $Company_Name , $Role ) { return sprintf("%s %s\r\n", $Company_Name , $Role ); } // Using ReflectionFunction() over the specified // function company $function = new ReflectionFunction( 'company' ); // Calling the __toString() function $A = $function ->__toString(); // Getting the string representation of the // above specified function echo $A ; ?> |
Function [ <user> function Company ] { @@ /home/a39c30763ecfc7f257d02e44de746b22.php 4 - 7 - Parameters [2] { Parameter #0 [ <required> $Company_Name ] Parameter #1 [ <required> $Role ] } }
Program 2:
php
<?php // Initializing some user-defined functions 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 ); } // Using ReflectionFunction() over the above // specified functions $function = new ReflectionFunction( 'Trial1' ); $function = new ReflectionFunction( 'Trial2' ); // Calling the __toString() function and // Getting string representation of the // above specified function echo $function ->__toString(); echo $function ->__toString(); ?> |
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