Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda