Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2012, 06:47 PM   PM User | #1
Hybrid
New to the CF scene

 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Hybrid is an unknown quantity at this point
[HELP] New way to write Variables

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.

Example:
Instead of
PHP Code:
echo "Hello $username"
I would like to do this:
PHP Code:
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
PHP Code:
$this->setParams("username"$_CONFIG['users']['name']) 
Thank you in advance.
Hybrid is offline   Reply With Quote
Old 02-16-2012, 11:46 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:29 AM.


Advertisement
Log in to turn off these ads.