I've tried to include the contents from a list of files:
$files = [
'a.php',
'b.php',
];
$contents = array_map('require', $files);
But this didn't work. The error I get is:
Warning: array_map() expects parameter 1 to be a valid callback, function 'require' not found or invalid function name
Why is this and is there a way to make it work?
Because require isn't a function, it's a language construct.
You'll need to create a valid callback function to do the actual require, or use an autoloader
As everyone already noticed - it is a language construct.
You can try this
$includes = array('a.php', 'b.php');
array_map(function($file){
require $file;
}, $includes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With