Jump to content

Function to load vars?


aximbigfan

Recommended Posts

I made an app in PHP, where a large string of vars is loaded (and can be reloaded in certain instances to validate them).

 

Basically, I want to have a function where vars are loaded, but I don't want them to be global, because they need to stay in the validation functions.

 

So, I know this won't work, but this is what I want to do:

 

INSTEAD of this:

$var1 = $systemvars['var1']
$var2 = $systemvars['var2']
ect.....

 

I WANT to do this:

function load_vars()
{
$var1 = $systemvars['var1']
$var2 = $systemvars['var2']
ect.....
}

function valid()
{
load_vars);
if (isset($var1 ))
echo "hi!";
}

 

Thanks.

chris

Link to comment
https://forums.phpfreaks.com/topic/95001-function-to-load-vars/
Share on other sites

You could use constants if the values don't change.

Pardon my possibly wrong terminology, but constants are basically in the same scope and globals; they can be used anywhere.

 

<?php
define('system_var1', 'valuehere');
//Then to call it..
echo system_var1;  //You don't use $ with constants.  And can't be called from within string, gotta concatenate em...
echo 'System Var1='.system_var1;
?>

 

Link to comment
https://forums.phpfreaks.com/topic/95001-function-to-load-vars/#findComment-486712
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.