Open In App

PHP ReflectionFunction export() Function

Last Updated : 26 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The ReflectionFunction::export() function is an inbuilt function in PHP which is used to return the export as a string if the return parameter is set to TRUE, otherwise NULL is returned.

 Syntax:

string ReflectionFunction::export( string $name, string $return )

Parameters: This function accepts two parameters as mentioned above and described below:

  • $name: It is the specified function which is to be exported.
  • $return: It is the Boolean value either TRUE or FALSE. If its value is set to True then it will export and if its value is set to false then it will return NULL. False is the default value.

Return Value: This function returns the export as a string if the return parameter is set to TRUE, otherwise NULL is returned. Below programs illustrate the ReflectionFunction::export() 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 export() function
$A = $function->export(Company, $return = TRUE);
 
// Getting the export as a string
echo $A;
?>


Output:

Function [ <user> function Company ] {
  @@ /home/b38c7d194c961e6b0d1d5b1c6e582d19.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
$function1 = new ReflectionFunction('Trial1');
$function2 = new ReflectionFunction('Trial2');
 
// Calling the export() function and
// Getting the export as a string
echo $function1->export(Trial1, $return = TRUE);
echo $function2->export(Trial2, $return = FALSE);
?>


Output:

Function [ <user> function Trial1 ] {
  @@ /home/2410abe3ca2b5235249f9a0c9ba035b4.php 4 - 7

  - Parameters [2] {
    Parameter #0 [ <required> $First_Args ]
    Parameter #1 [ <required> $Second_Args ]
  }
}
Function [ <user> function Trial2 ] {
  @@ /home/2410abe3ca2b5235249f9a0c9ba035b4.php 9 - 12

  - Parameters [2] {
    Parameter #0 [ <required> $First_Args ]
    Parameter #1 [ <required> $Second_Args ]
  }
}

Reference: https://www.php.net/manual/en/reflectionfunction.export.php



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads