1

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 :(

1
  • What exactly is not working? Commented Aug 24, 2021 at 12:32

2 Answers 2

3

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');
});
Sign up to request clarification or add additional context in comments.

Comments

2

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, ...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.