开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜