Re: Inheritance/compatibility behavior
| From: | Stanislav Malyshev | Date: | Tue, 29 Apr 2008 16:11:18 +0000 |
| Subject: | Re: Inheritance/compatibility behavior | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-37307@lists.php.net to get a copy of this message | ||
Hi!
Sam Barrow wrote:
I want to make two classes: abstract class a { abstract public function go($a); } final class b extends a { abstract public function go(array $a); }LSP violation here: a accepts go("away") but b doesn't.
This will not work, I get an error that the two must be compatible. Wouldn't it be a good idea to allow any type hint for a parameter that does not specify a type hint?No, because of the LSP. Subtypes should not strengthen preconditions. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com