Re: Interface inheritance
| From: | George Schlossnagle | Date: | Tue, 20 Apr 2004 14:54:04 +0000 |
| Subject: | Re: Interface inheritance | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-9423@lists.php.net to get a copy of this message | ||
On Apr 20, 2004, at 10:48 AM, Ferdinand Beyer wrote:
On 20 Apr 2004 at 17:38, Stanislav Malyshev wrote:This is probably a bad argument since while PHP doesn't currently allow type hinting based on whether a parameter is an array vs. a scalar, it's technically feasible and their is no good auto-casting from array to scalar or vice-versa. A better argument is expecting different types of scalars. That would be much harder with PHP's typing semantic. GeorgeFB>>interface A {requires objectFB>> public function doSomething($integer1, $integer2);FB>>} FB>> FB>>interface B { FB>> public function doSomething(MyObject $obj); FB>>} FB>> FB>>class Impl implements A, B FB>>{FB>> // "Overloaded" - supports both doSomething() interfaces FB>> public function doSomething() FB>> { FB>> // Use var_args to distinquish the two doSomething()'s FB>> }FB>>} The problem here that you can't know if Impl would actually accept MyObject or two integers as arguments. So if some methodwith interface A and it's passed Impl, it cannot actually be sure itcanuse it as an A object.Impl guarantees that by implementing interface A. What if Impl::doSomething() would accept exactly two parameters, but expects them to be arrays? IMO you cannot enforce this strictness with loose types...