Jump to content

Recommended Posts

<?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

Link to comment
https://forums.phpfreaks.com/topic/115833-include-a-file-into-a-class/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.