LemonInflux Posted July 21, 2008 Share Posted July 21, 2008 <?php class parent { var $child; function parent() { $this->child = new child; } } class child extends parent { var $var; } ?> Normally, I'd call parent->child->var to get the child var. However, I want to be able to include a file, in which I can use $this->var to call the var. I don't mean include a file containing the class, I mean include a separate file that can be treated as if it is in the child. Is there a way to do this? I'm sorry if this is badly explained, but I can't think of a clear way to do this. I think the zend framework uses something like this, because you set things as $this->view->var and retrieve them in the view as $this->var. But I couldn't work out how they did it Any help is appreciated. Thanks in advance, Tom Quote Link to comment https://forums.phpfreaks.com/topic/115833-include-a-file-into-a-class/ Share on other sites More sharing options...
Daniel0 Posted July 21, 2008 Share Posted July 21, 2008 Include the file within a class or eval the code. In that way you'll be able to access $this for whatever object the file is called within. Quote Link to comment https://forums.phpfreaks.com/topic/115833-include-a-file-into-a-class/#findComment-595978 Share on other sites More sharing options...
LemonInflux Posted July 22, 2008 Author Share Posted July 22, 2008 ..You mean a straight forward include() would work? Quote Link to comment https://forums.phpfreaks.com/topic/115833-include-a-file-into-a-class/#findComment-596300 Share on other sites More sharing options...
Daniel0 Posted July 22, 2008 Share Posted July 22, 2008 Yes. If you include it from within the class then you should be within the scope of that class and $this should consequently be available to you. Quote Link to comment https://forums.phpfreaks.com/topic/115833-include-a-file-into-a-class/#findComment-596454 Share on other sites More sharing options...
LemonInflux Posted July 22, 2008 Author Share Posted July 22, 2008 Woah, ok Thanks, I'll try it in a bit! Topic solved ---------------- Now playing: Enter Shikari - The Feast (Demo) via FoxyTunes Quote Link to comment https://forums.phpfreaks.com/topic/115833-include-a-file-into-a-class/#findComment-596471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.