Odd Custom PHP Variables

Creating custom-named PHP variables is pretty easy:

${'username'} = 'User1010'; // same as $username = 'User1010';

But did you know that you can create variables with spaces? The following will work:

${'name of user'} = 'David Walsh';
echo ${'name of user'};

I can't see any reason to do this, but it's possible.


Comments

  1. Shawn

    Reminds me of a templating variable. Could possibly be used in the case of having non-programming html-designers making the pages.

    Hopefully someone else knows more about the benifits of this. :)

  2. Sat Pirott

    I’m really not sure, but as I used flash and dynamic variable creation, this somehow looks familiar for me. It makes sence in flash, but I don’t know why I should do this in php. I mean, arrays are better that that, right?
    I dunno! Makes me wondering …

  3. Astropos

    echo ${‘name of user’};

    lol, thats useful innit? ;)

    Great site btw. cheers.


Be Heard!

Share your thoughts without being a jerk! And wrap your code in <code> tags, f00!

Name*:
Email*:
Website: