I want to require/include a file and retrieve its contents into a variable.
test.php
In PHP/7 you can use a self-invoking anonymous function to accomplish simple encapsulation and prevent global scope from polluting with random global variables:
return (function () {
// Local variables (not exported)
$current_time = time();
$reference_time = '01-01-1970 00:00';
return "seconds passed since $reference_time GMT is $current_time";
})();
An alternative syntax for PHP/5.3+ would be:
return call_user_func(function(){
// Local variables (not exported)
$current_time = time();
$reference_time = '01-01-1970 00:00';
return "seconds passed since $reference_time GMT is $current_time";
});
You can then choose the variable name as usual:
$banner = require 'test.php';