Jump to content

Recommended Posts

Ran into the same problem: http://www.phpfreaks.com/forums/index.php/topic,152955.0.html

However, if you're into interfaces, you can have one class implement multiple interfaces.

interface Honest {
function etc();
}
interface Rock {
function stuff();
}
class Frankenstein implements Honest, Rock {
function etc() { echo "blerg\n"; }
function stuff() { echo "blarg\n"; }
}
$obj=new A;
$obj->etc();
$obj->stuff();

Of course, you can't put any meat into your interface method declarations...

That would be incorrect usage of a interfaces. Interfaces are used to, well... implement interfaces for the class. It's used to ensure that an object implements certain functionality. E.g. you may have an interface called XMLable. You can then check if the object is a valid object for your usage (i.e. if it contains functionality to return XML data for the object) like this:

<?php
if( !($object instanceof XMLable ) ) {
throw Exception('Invalid object. Object must implemennt XMLable');
}

// OR

class SomeClass {
// ...

public function doSomething( XMLable $object ) {
	// do something in here with $object which is ensured to have implemented XMLable
}

// ...
}
?>

 

In the latter example, if $object is not an object which implements XMLable then it will result in a catchable fatal error.

  • 8 months later...

Hi

 

I have this same issue and was wondering if someone could give me some advice on multiple extends, my situation is below:

 

Class A: Finished object that doesn't extend anything

Class B: Finished object that doesn't extend anything

Class C: Not developed but needs to inherit everything from A and B

 

Normally I have things extend A or B but I now need a new object to extend both, therefore I was wondering is that possible to achieve this without altering A and/or B so that one of them extends the other before I can create C?

 

Ideally I would like to keep A and B unchanged as they are standard objects I use for various things but I haven't needed them together before.

 

Thanks in advance.

 

 

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.