Jump to content

**SOLVED** how can I extend multiple classes?


drkstr

Recommended Posts

can you be more specific? if you're looking to have one class that extends multiple ones, it ain't gonna happen. however, if you're wanting to simply extend multiple levels, you can just continue lik this:
[code]
<?php
class Organism {
  var $distinction;
 
  function Organism($distinction) {
    $this->distinction = $distinction;
  }
}

class Person extends Organism {
  function Person() {
    parent::Organism("Human");
  }
}

class User extends Person {
  var $username;

  function User($username) {
    parent::Person();
    $this->username = $username;
  }
}
?>
[/code]

at least, i think i got all my references correct :P ... coding on the fly lends itself to errors!

hope this helps
Link to comment
Share on other sites

Darn, I guess it's not going to happen then. I have a data template and a service template and I wanted to extend them both into an actual "library" object which is customized for it's actual use. I'm going to have a *lot* of these objects, so I was trying to get around rewriting the same code over and over. I gues I will just extend the service template and make an isntance of the data object in the child. The data template doesn't have that much code, and the only thing that will change in the service template is the name of the class, so I guess it would make sence to just get rid of the data template and just duplicate the code in each of the data objects.

Thanks for the quick reply!
...drkstr
Link to comment
Share on other sites

so... why not create a third class that has member variables that are actually instances of the first two objects? then, you could write member functions that would access given portions of either of the other two classes and [b]act[/b] as though you had joined the classes into one.

make sense?
Link to comment
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.