Variable variables in PHP - What is their purpose?

后端 未结 4 1435
耶瑟儿~
耶瑟儿~ 2020-12-03 14:43

In PHP there\'s a functionality officially called \"Variable Variables\" where one can assign variable variables. A variable variable takes the value of one variable as the

4条回答
  •  抹茶落季
    2020-12-03 15:16

    This has some uses when referencing variables within classes, and there are some cases where these can actually be required (such as in __get(), __set(), __isset(), and __unset()). However, in most cases it is unwise to use them on global variables.

    Be aware that you should NEVER directly accept end-user input when it comes to variable variables. Instead a wrapper function should be used to ensure that only specific inputs are allowed.

    In most cases, variable variables are not required, and it is recommended that you avoid them when possible.

提交回复
热议问题