Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double dollar sign php

Tags:

syntax

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.

like image 593
Slavic Avatar asked Nov 14 '10 20:11

Slavic


1 Answers

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.

like image 130
Erik Avatar answered Sep 29 '22 12:09

Erik