Variable variables: when useful? [duplicate]

十年热恋 提交于 2019-11-29 08:08:19
Your Common Sense

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.

ArK

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!