|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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: Code: $var1 = $systemvars['var1'] $var2 = $systemvars['var2'] ect.....I WANT to do this: Code: function load_vars() { $var1 = $systemvars['var1'] $var2 = $systemvars['var2'] ect..... } function valid() { load_vars); if (isset($var1 )) echo "hi!"; }Thanks. |
|
|||
|
Callme I think what your after is a means of setting a buch of variables and having methods appropriate to these vars without having the variables declared gloabally (Note that when I say globally I dont mean in the $_globals array but globally within the variable scope of the page).
Basically what I think you need to look at is a little basic OOP, here you can declare properties which are only avaliable in the scope of that object instance so in your case: N.B. Its been a while since ive done php so syntax may be wrong: <?php class SomeClassWithVariablesToValidate { $Var, $Varb, $Varc; public __Construct() { $this->ResetVariables(); } public ResetVariables() { $this->Var = 0; $this->Varb = 1; $this->Varc = 2; } public Validate() { if($this->Var!=null && this->Varb!=null && this->Varc!=null ) return true; return false; } } //Test usage $pointlessClass = new SomeClassWithVariablesToValidate(); if($pointlessClass->Validate()) echo "Validated"; ?> |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using Variables outside a function | ackerley1 | Web Programming Discussion Forum | 4 | 10-30-2007 07:30 PM |
| IBM Paves Express Track For VARs | DougC | Insider Reports | 0 | 08-29-2006 11:28 AM |
| Form and Function | grease | Graphics & Design Discussion Forum | 0 | 09-19-2005 12:36 AM |
| Why has this function used in that code? | abalfazl | Web Programming Discussion Forum | 2 | 03-11-2005 02:24 PM |
| MySQL/PHP Combining 3 vars into 1 | bodgekaloopie | Database Discussion Forum | 15 | 09-08-2004 05:54 PM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |