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

159
Views
PHP: cómo pasar mi variable en mi función

Alguien me puede ayudar con eso... Cómo pasar una variable ( $membreConf ) en eso:

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

Actualmente, no está funcionando :(

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

En este caso, falta la declaración de use . Ver ejemplo #3 de 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

Debes pasarlo a la función anónima usando la palabra clave use :

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

Consulte aquí la documentación oficial , por ejemplo, este fragmento de código:

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

También puede pasar varias 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!