Hi!

On 9/17/11 6:27 AM, Richard Quadling wrote:
With the recent BC with regard the locking of the constructor's
signature for subclasses, what is the expected mechanism for allowing
a subclass to have additional parameters?

I think the whole "strict parameters" thing has gone into somewhat wrong direction and now we seem to have tons of useless errors and restrictions. For example, handling of bug #51421 seems to be wrong - there should be no problem if child method's signature is more permissive than the parent's. I do not see any point in it except puristic "enforcement" for the sake of enforcement, which doesn't seem to have any practical purpose.

As for signature being more restrictive, in general case this should not be allowed as it is a LSP violation. The case can be made that ctor is not actually called on a real object but instead are used directly and statically, so more restrictive ctors are OK, but this is not true in the case of factories - i.e., if you do something like this:

abstract class Base {
  function __construct($foo, $bar) { /* blah */ }
  function createBase($concrete, $foo, $bar) {
if(!is_a($concrete, __CLASS__)) { throw new Exception("$concrete is not my descendant, can not create!"); }
      return new $concrete($foo, $bar);
  }

This would fail if some concrete descendant of Base has additional restrictions on its ctor. So in this case the prohibition of additional restrictions is appropriate as well.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to