Jump to content

Archived

This topic is now archived and is closed to further replies.

drkstr

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

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

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
Ahh, That's a great idea!

I'll just change the protected data/methods to public, and I'll be good to go.

Thanks for the help!
...drkstr

Share this post


Link to post
Share on other sites

×

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.