what is “$$” in PHP

前端 未结 3 1315
野趣味
野趣味 2020-12-03 05:38

I saw this code

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

what is code \"$$\" ?

相关标签:
3条回答
  • 2020-12-03 06:05

    For reference, see: http://php.net/manual/en/language.variables.variable.php

    0 讨论(0)
  • 2020-12-03 06:11

    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"
    
    0 讨论(0)
  • 2020-12-03 06:20
    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.

    0 讨论(0)
提交回复
热议问题