Skip to content
Advertisement

PHP – how to pass my variable in my function

Someone can help me with that… How to pass a variable ($membreConf) in that:

$membreConf = '/home/mapubs/conf_maplate.php';
$route = new Route();
$route->add('/', function(){ include($membreConf); include('home.php'); });

Presently, is not working 🙁

Advertisement

Answer

In this case, the use statement is missing. See example #3 of https://www.php.net/manual/en/functions.anonymous.php

$membreConf = '/home/mapubs/conf_maplate.php';
$route = new Route();
$route->add('/', function() use ($membreConf) {
    include($membreConf);
    include('home.php');
});
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement