Skip to content

Instantly share code, notes, and snippets.

@f3ath
Created January 18, 2018 20:39
Show Gist options
  • Save f3ath/fb47834ec3a0fbc437a252facc876fe2 to your computer and use it in GitHub Desktop.
Save f3ath/fb47834ec3a0fbc437a252facc876fe2 to your computer and use it in GitHub Desktop.
Local scope in included files
<?php
$foo = require __DIR__ . '/foo.php';
var_dump($foo);
var_dump(isset($innerVar));
<?php
return (function() {
$innerVar = 'This var is invisible';
return 'This is what gets returned';
})();
[f3ath@proton playground]$ php bar.php
/home/f3ath/project/playground/bar.php:3:
string(26) "This is what gets returned"
/home/f3ath/project/playground/bar.php:4:
bool(false)
[f3ath@proton playground]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment