开发者

Variable variables: when useful? [duplicate]

开发者 https://www.devze.com 2023-01-13 02:28 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: What's an actual use of variable variables?
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

What's an actual use of variable variables?

OK, this question may look a little bit point-whoreish, but I'd really like to know: when are variable variables useful? I haved programmed in PHP for several year开发者_开发问答s, but I've never used them. For me it looks rather funny than useful.

What are some real life examples of variable variables?

Update:

I'm really sorry about your votes. The linked 'duplicate' may be really a dupe except one thing: the examples listed there show me why not to use variable variables.


Never. This feature should be banned from the language as well as its other children diseases such as register globals, magic quotes, etc.


I have seen it used in some MVC frameworks to initialize variables in the View object.

foreach ($this->vars as $key => $value)
{
    // some test would be here so there are no conflicts
    $$key = $value;
}

You can then access the the variabels in templates.

I'm not saying this is a good use though. Probably a case of poor design.


It's useful for setting up configuration files dynamically. Check PHP and Variable Variables for a better idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消