IMO we are trying to force a strict programming here that is incompatible with PHP's loose character.Well, I don't get the point in relation to *constructors* at all.. I mean, forcing the same signature for each constructor seems unreasonable to me (_when explicitely called_, of couse).. there is no such thing as a contract for constructor interfaces per default -- as you usually don't call those explicitely (but when calling the parent's constructor), that doesn't make too much (any) sense to me. Could someone elaborate on the advantages of enforcing the same signature of constructors (as long as the constructor doesn't get implicitely called, of course)?
The following example for instance is very common in Java AVT programming:> [snip]
Yeah indeed, and extending/changing the constructor interface is simply a natural thing when extending a class (by inheritance). Maybe I'm completely missing the point, though, it might be too early for me.
Furthermore with the new implementation we disallow "the PHP way for overloaded methods" using a variable parameter count:>
> [...]
I'm less sure about normal functions. It probably makes sense to check for matching signatures there (you can always handle optional additional parameters by using default values/func_get_args(), [1]).
Cheers, Michael
[1] Why is it that func_get_args() can't get used as a function parameter directly, btw?
PS: I'm rather sorry to always bring in my personal views/opinions into such discussions without actually contributing code to PHP5. In case that is displeasing for [some|the core] people, I can of course stop doing so ;) In the meanwhile, I hope that the percentage of posts without braindead typos (as in the first IDIVL one) might enrich ongoing discussions.
<?php
class Base { function doSomething(MyClass $obj) { } }
class Extended extends Base { function doSomething() { $args = func_get_args();
switch (count($args)) { case 0: return parent::doSomething(new MyClass());
case 1: if ($args[0] instanceof MyClass) { return parent::doSomething($args[0]); } return parent::doSomething(new MyClass($args[0]));
default: throw new IllegalArgumentException(); } } }
?>
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php