Hello Jeff, Sunday, November 5, 2006, 7:09:26 PM, you wrote:
> On Nov 3, 2006, at 1:11 PM, Marcus Boerger wrote: >> Liskov applies to static methods as soon as calls via objects are common >> which is true for PHP. Actually in PHP static methods are inherited as any >> other method (also true for a lot of other languages). Now given Liskov >> rules you can as well add default parameter values as add new parameters >> with default values and even change type hints (when respecting the rules >> correctly). With C++ the first language has proven that changing default >> parameter values is a bad idea. There however mainly because they are bound >> at compile time based on the compile time types, which results in default >> values that are mostly not what you would expect. In PHP it might work as >> expected but then all programmers that come from langiages like C++ get >> confused. Also it would disallow a few optimizer things later (going the C++ >> way of compile time function invocatoin binding). The same holds for new >> additional parameters. In most languages that is no option because it would >> effectively be a different function. In PHP it would eventually work but add >> more confusion that it would help. The last point, changing type hints in >> derived class' methods, was discussed at PDM and declined. The main reason >> for that decision were that all languages we knew of do not support it and >> that most people even do not understand the rules which are quite the >> opposite of what most people think. > Hi Marcus, > Enlightening explanation in a long and confusing thread. > To restate the last point for clarification, if the PHP's rules were > following Liskov's rules, this > php -d"error_reporting=8191" -r 'class Foo {} class FooBar extends Foo > {} class T {function f(FooBar $x){}} class S extends T {function f(Foo > $x){}}' > and possibly > php -d"error_reporting=8191" -r 'class T {function f(StdClass $x){}} > class S extends T {function f($x){}}' > would not be E_STRICT violations as they currently are. In both > examples the subclass weakens the parent classes' preconditions (type > hints). So PHP's E_STRICT rules are (intentionally) 'stricter' than > Liskov's rules. Yes, both above are correct for Liskov and Lambda Calculus however it is the opposite of what most people expect. Thus we decided against it last year. So in PHP the typehint has to be as in the root class. Best regards, Marcus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php