PHP - how to pass my variable in my function

Solution:

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');
});

Answer

Solution:

You must pass it to the anonymous function using the use keyword:

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

See here the official documentation, for example this code snippet:

// Inherit $message
$example = function () use ($message) {
    var_dump($message);
};
$example();

You can also pass multiple variables:

function() use($var1, $var2, ...)

Source