<p><strong>Is there a way in PHP to overwrite a method declared by one interface in an interface extending that interface?</strong></p>

<p>The Example:</p>

<p>I'm probably doing something wrong, but here is what I have:</p>

<pre><code>interface iVendor{
    public function __construct($vendors_no = null);
    public function getName();
    public function getVendors_no();
    public function getZip();
    public function getCountryCode();
    public function setName($name);
    public function setVendors_no($vendors_no);
    public function setZip($zip);
    public function setCountryCode($countryCode);
}

interface iShipper extends iVendor{
    public function __construct($vendors_no = null, $shipment = null);
    public function getTransitTime($shipment = null);
    public function getTransitCost($shipment = null);
    public function getCurrentShipment();
    public function setCurrentShipment($shipment);
    public function getStatus($shipment = null);
}
</code></pre>

<p>Normally in PHP, when you extend something, you can overwrite any method contained therein (right?). However, when one interface extends another, it won't let you. Unless I'm thinking about this wrong... When I implement the iShipper interface, I don't have to make the Shipper object extend the Vendor object (that implements the iVendor interface). I just say:</p>

<pre><code>class FedEx implements iShipper{}
</code></pre>

<p>and make FedEx implement all of the methods from iVendor and iShipper. However, I need the <code>__construct</code> functions in iVendor and iShipper to be unique. I know I could take out the <code>$shipment = null</code>, but then it wouldn't be as convenient to create Shippers (by just passing in the vendors_no and the shipment while instantiating).</p>

<p>Anyone know how to make this work? My fallback is to have to set the shipment by calling <code>$shipper-&gt;setShipment($shipment);</code> on the Shipper after I instantiate it, but I'm hoping for a way to get around having to do that...</p>

<p><em>A little more explanation for the curious:</em><br>
<em>The FedEx Object has methods that go to the FedEx site (using cURL) and gets an estimate for the Shipment in question. I have a UPS Object, a BAXGlobal Object, a Conway Object, etc. Each one has COMPLETELY different methods for actually getting the shipping estimate, but all the system needs to know is that they are a "shipper" and that the methods listed in the interface are callable on them (so it can treat them all exactly the same, and loop through them in a "shippers" array calling <code>getTransitX()</code> to find the best shipper for a shipment).</em>  </p>

<p><em>Each "Shipper" is also a "Vendor" though, and is treated as such in other parts of the system (getting and putting in the DB, etc. Our data design is a pile of crap, so FedEx is stored right alongside companies like Dunder Mifflin in the "Vendors" table, which means it gets to have all the properties of every other Vendor, but needs the extra properties and methods supplied by iShipper).</em></p>

[{'answer_id': 16245, 'author': 'Ryan Ahearn', 'author_id': 75, 'author_profile': 'https://Stackoverflow.com/users/75', 'pm_score': 4, 'selected': True, 'text': '<p><a href="https://stackoverflow.com/questions/16155/making-one-interface-overwrite-a-method-it-inherits-from-another-interface-in-p#16196">@cmcculloh</a> Yeah, in Java you don\'t define constructors in Interfaces.  This allows you to both extend interfaces and also have a class that implements multiple interfaces (both allowed, and very useful in many cases) without worrying about having to satisfy a particular constructor.</p>\n\n<p><em>EDIT:</em></p>\n\n<p><em>Here\'s my new model:</em></p>\n\n<p><em>A. Each interface no longer has a constructor method.</em><br>\n<em>B. All Shippers (UPS, FedEx, etc) now implement iShipper (which extends iVendor) and extend the abstract class Shipper (which has all common non-abstract methods for shippers defined in it, getName(), getZip() etc).</em><br>\n<em>C. Each Shipper has it\'s own unique _construct method which overwrites the abstract __construct($vendors_no = null, $shipment = null) method contained in Shipper (I don\'t remember why I\'m allowing those to be optional now though. I\'d have to go back through my documentation...).</em></p>\n\n<p>So:</p>\n\n<pre><code>interface iVendor{\n    public function getName();\n    public function getVendors_no();\n    public function getZip();\n    public function getCountryCode();\n    public function setName($name);\n    public function setVendors_no($vendors_no);\n    public function setZip($zip);\n    public function setCountryCode($countryCode);\n}\n\ninterface iShipper extends iVendor{\n    public function getTransitTime($shipment = null);\n    public function getTransitCost($shipment = null);\n    public function getCurrentShipment();\n    public function setCurrentShipment($shipment);\n    public function getStatus($shipment = null);\n}\n\nabstract class Shipper implements iShipper{  \n    abstract public function __construct($vendors_no = null, $shipment = null);  \n    //a bunch of non-abstract common methods...  \n}\n\nclass FedEx extends Shipper implements iShipper{  \n    public function __construct($vendors_no = null, $shipment = null){\n        //a bunch of setup code...\n    }\n    //all my FedEx specific methods...\n}\n</code></pre>\n\n<p><em>Thanks for the help!</em><br>\n<em>ps. since I have now added this to "your" answer, if there is something about it you don\'t like/think should be different, feel free to change it...</em></p>\n'}, {'answer_id': 16409, 'author': 'mk.', 'author_id': 1797, 'author_profile': 'https://Stackoverflow.com/users/1797', 'pm_score': 0, 'selected': False, 'text': "<p>You could drop off the constructor and just put them in each individual class. Then what you have is each class has its own __construct, which is probably the same depending on if it is a shipper or vendor. If you want to only have those constructs defined once I don't think you want to go down that route. </p>\n\n<p>What I think you want to do is make an abstract class that implements vendor, and one that implements shipper. There you could define the constructors differently. </p>\n\n<pre><code>abstract class Vendor implements iVendor {\n    public function __construct() {\n        whatever();\n    }\n}\n\nabstract class Shipper implements iShipper {\n    public function __construct() {\n        something();\n    }\n}\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/16155', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/58/']