Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is "$$" in PHP

I saw this code

if (is_null($$textVarName)) {
$$textVarName = $_defaultTexts[$type];
}

what is code "$$" ?

like image 269
meotimdihia Avatar asked Nov 12 '10 23:11

meotimdihia


People also ask

What is the difference between $$ and in PHP?

PHP $ and $$ Variables. The $var (single dollar) is a normal variable with the name var that stores any value like string, integer, float, etc. The $$var (double dollar) is a reference variable that stores the value of the $variable inside it. To understand the difference better, let's see some examples.

What is $_ in PHP?

PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL.

What does &$ mean in PHP?

passing argument through reference (&$) and by $ is that when you pass argument through reference you work on original variable, means if you change it inside your function it's going to be changed outside of it as well, if you pass argument as a copy, function creates copy instance of this variable, and work on this ...

What is == and === in PHP?

== Operator: This operator is used to check the given values are equal or not. If yes, it returns true, otherwise it returns false. Syntax: operand1 == operand2. === Operator: This operator is used to check the given values and its data type are equal or not. If yes, then it returns true, otherwise it returns false.


2 Answers

It's evil is what it is.

That will take the value that's in $textVarName and use that as a variable name. For example:

$foo = 'hello';
$hello = 'The Output';
echo $$foo; // displays "The Output"
like image 63
VoteyDisciple Avatar answered Sep 27 '22 20:09

VoteyDisciple


foreach($_POST as $key=>$value)$$key=$value;

now, automagically, if the previous form had a field named 'username' you now have a variable called $username that holds the value submitted in the form. not the greatest or secure method, but when you have a pocket full of nails, this is a heck of a hammer

this is pretty bad practice and is never encouraged but all PHP coders I know secretly sorta like it.

like image 22
FatherStorm Avatar answered Sep 27 '22 20:09

FatherStorm