When to use a variable variable in PHP?

2019-02-10 14:44发布

I've been developing in PHP for a while now, and I still have not had a task where I've had to use variable variables. Can anyone give me examples where using them is a good idea ? Or were they included in the language just for fun ?

8条回答
冷血范
2楼-- · 2019-02-10 15:34

Never use them; an "array" is always a better solution.

查看更多
孤傲高冷的网名
3楼-- · 2019-02-10 15:35

I generally find them in places where the code smells bad. Maybe references a static configuration variable etc... But why wouldn't the usual associative array have been a better solution. Seems like a security hole waiting to happen.

I suppose you might be able to use them in templates effectively.

查看更多
登录 后发表回答