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
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
Share on other sites

One more thing...

 

Say I want to inject this into something:

$var = "var"
$var2 = "var"

 

is there some way I could make just a one line solution to this? For example

 

function test()
{
<one line code to inject var "table" here>

echo $var;

 

Chris

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.