It looks like you're new here. If you want to get involved, click one of these buttons!
session_start();
$globvar = 'this has not changed...';
$globvar1 = 'this has not changed...';
function AnyFunction(){
echo "\n\nFunction declared outside of extension";
}
//safe place
$extension_vars=array(); function includeInPolaroidScope($extension){// scope
// get global vars
foreach ($GLOBALS As $name => $value){
eval('global $'.$name.';');
}
unset($name,$value); //important
$funcs_glob= get_defined_functions();//outside functions
include($extension.'/default.php'); // inlcude the extension
$vars_in_scope = get_defined_vars();// (in scope)
foreach($vars_in_scope As $name => $value){
if(!in_array($name, array('extension','funcs_glob')) && !array_key_exists($name,$GLOBALS)){ // not global
$extension_vars[$extension][$name] = $value;
}
// no need to unset local variables
}
$funcs_curr= get_defined_functions();// current functions
foreach($funcs_curr['user'] As $name){
if(!in_array($name,$funcs_glob["user"])){ //inside functions
if(($pos = strpos($name,'_')) ===false && substr($name,0,$pos)!=strtolower($extension)){
die("Invalid function name '$name'. Extension functions/callbacks must be prefixed by name e.g. 'ExtensionName_FunctionName'");
}
}
}
}// end scope
<?php
$localvar = 'this is local...';
$globvar = 'this has changed...';
$_SESSION['hi'] = 'hi'; //super global
function MyExtension_AnyFunction(){
echo "\n\nFunction declared inside of extension (must have prefix)";
}
echo 'global $globvar='.$globvar.' global $globvar1='.$globvar1.' local $localvar='.$localvar;
?> //include extension
includeInPolaroidScope('MyExtension');
echo "\n\n*Outside scope*";
echo "\n\n\$extension_vars=";
var_export($extension_vars);//only relevant
echo "\n\n\$localvar=";
var_export(@$localvar);//not set
MyExtension_AnyFunction();
AnyFunction();global $globvar=this has changed... global $globvar1=this has not changed... local $localvar=this is local...
*Outside scope*
$extension_vars=array (
'MyExtension' =>
array (
'localvar' => 'this is local...',
),
)
$localvar=NULL
Function declared inside of extension (must have prefix)
Function declared outside of extensiongrep is your friend.
Comments
grep is your friend.
grep is your friend.