View Full Version : [HELP] New way to write Variables

02-16-2012, 07:47 PM
I'm creating an Administrative Panel. For the Administrative Panel, I'm going to be using the same variables in multiple files. Since I will be releasing this Admin Panel, I want to make it user friendly. How can I write variables in brackets or something else so the developer can easily see what I did.

Instead of

echo "Hello $username";
I would like to do this:

echo "Hello {username}";

I believe this will be better and more organized, expecially because the configuration file will be large. I don't want the server variables and the client variables being confused.
The variables that I want to have the "{ }" should be declared in a global file. Something like

$this->setParams("username", $_CONFIG['users']['name'])

Thank you in advance.

02-17-2012, 12:46 AM
The latter requires you to write a template system to search and replace for existence of {}. Then you simply use a pattern match or you can use str_replace as well if you let it search for every possibility of known values, and replace the value as necessary.
This will of course create overhead since replacements and searching is slower than direct variable evaluation. Impact would still be minimal.
Don't name your variable $_CONFIG. $_ is reserved for anything super, and __ for anything magical. Using either creates a potential that in the future it will cause either an error or an unintended overwrite.