Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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');
});
over 4 years ago · Santiago Trujillo Report

0

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, ...)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!