Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [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.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •