For what it's worth, I used variable variables when making a DB class for a project I was working on last year.
It isn't something you can easily debug and it is complicated. That said, it isn't the gates to hell that it is represented as. It's a tool, and it can make code cleaner if you want it to.
function __tostring(){
$items = ['title','header','comment']
foreach($items as $item){
echo $this->$item;
}
}
Make that list of class variables much longer and you start to see the benefits in certain cases.
There are times when I do miss variable variables.
There is actually a little more to getattr in that __dict__ just has attributes local to that instance where as getattr (also instance.attribute syntax) also accesses class attributes, non-bound methods, and properties. Additionally, these non-local attributes can also be inherited from parent classes.
It isn't something you can easily debug and it is complicated. That said, it isn't the gates to hell that it is represented as. It's a tool, and it can make code cleaner if you want it to.
function __tostring(){ $items = ['title','header','comment'] foreach($items as $item){ echo $this->$item; } }
Make that list of class variables much longer and you start to see the benefits in certain cases.
There are times when I do miss variable variables.