From d7775a9fadbe01d83ff88d549d5401e507fbfb02 Mon Sep 17 00:00:00 2001 From: SteamPixel Date: Mon, 8 Feb 2021 11:00:50 +0100 Subject: [PATCH] Added example for injecting variables to local scope --- index.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 7ff5288..a4c2033 100644 --- a/index.php +++ b/index.php @@ -29,6 +29,7 @@ function navi() {
  • PHP Info
  • Non english route: german
  • Non english route: arabic
  • +
  • Inject variables to local scope
  • Arrow function test (please enable this route first)
  • aTrailingSlashDoesNotMatter
  • aTrailingSlashDoesNotMatter/
  • @@ -135,8 +136,21 @@ Route::add('/الرقص-العربي', function() { echo 'Arabic example. Non english letters should work too
    '; }); +// Use variables from global scope +// You can use for example use() to inject variables to local scope +// You can use global to register the variable in local scope +$foo = 'foo'; +$bar = 'bar'; +Route::add('/global/([a-z-0-9-]*)', function($param) use($foo) { + global $bar; + navi(); + echo 'The param is '.$param.'
    '; + echo 'Foo is '.$foo.'
    '; + echo 'Bar is '.$bar.'
    '; +}); + // Return example -// Returned data gets echoed +// Returned data gets printed Route::add('/return', function() { navi(); return 'This text gets returned by the add method';