Double dollar sign php
Possible Duplicate:
What does $$ (dollar dollar or double dollar) mean in PHP?
I found myself using this kind of code in one of my controllers:
foreach(get_object_vars($this->view) as $property=>$value){
$$property = $value;
}
Is there any problem with using the $$property to "localize" view properties into simple $variables?
edit:
I should add that this code is run in the scope of a view-specific method, so there's no problem of overriding local variables. This is to divert some of you guys from pointing out the problem of overriding local variables.
The problem with $$ in PHP is that you create unknown variable names, that may override variable names you already use. It is a source for subtle programming errors, and should generally not be used.
Well, you could just use extract()
function. Also that fragment: get_object_vars($this->view)
indicates that you should rather have some array to store those variables, not an object.
Nope, that's the way to do it and the only way if I'm not mistaken. Though my question would be to ask why you'd want to do that instead of using the object variable.
链接地址: http://www.djcxy.com/p/59102.html上一篇: 价值调用和php中的引用调用之间的区别,还有$$意味着什么?
下一篇: 双美元符号的PHP