双重美元符号php [英] Double dollar sign php

查看:98
本文介绍了双重美元符号php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
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;
}

使用$$属性将视图属性本地化"为简单的$ variables是否有问题?

Is there any problem with using the $$property to "localize" view properties into simple $variables?

我应该补充一点,该代码在特定于视图的方法范围内运行,因此不存在覆盖局部变量的问题.这是为了使你们中的一些人摆脱指出覆盖局部变量的问题.

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.

推荐答案

PHP中$$的问题是您创建了未知的变量名,这些变量名可能会覆盖已经使用的变量名.它是产生细微编程错误的根源,通常不应使用.

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.

这篇关于双重美元符号php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆