How to pull all instance variables of an object as local variables into the scope of an method from that object?
I have an class with some instance variables. It's purpose is for templating.
So this class has a fetchTemplate() method which includes a PHP template file.
In my template file, I can access any variable that has been assigned to the template, by writing:
echo $this->theVariable
If there was a way to "pull" all arbitrary instance variables into the local variables scope of fetchTemplate(), it would be possible to simply write:
开发者_Go百科echo $theVariable
I slightly remember that there was something....
You can cast the object to an array and use extract()
:
extract( (array)$this );
but I think it will just work on public
variables.
精彩评论