ID: 40212
Updated by: [EMAIL PROTECTED]
Reported By: alex dot dean at pni dot com
Status: Open
Bug Type: Class/Object related
Operating System: Ubuntu GNU/Linux 2.6.15-27-386
PHP Version: 5CVS-2007-01-23 (snap)
New Comment:
The difference between
someMethod($argument1='',$argument2)
and
someMethod($argument1,$argument2='')
is that the latter changes number of required arguments and the former
does not.
I'm not 100% sure we want to check the default values, though.
Previous Comments:
------------------------------------------------------------------------
[2007-01-23 15:18:08] alex dot dean at pni dot com
Description:
------------
Given abstract and concrete versions of a class method, the first
argument is allowed to differ in its usage (or non-usage) of a default
value. No other arguments appear to be allowed to do this.
Reproduce code:
---------------
<?php
abstract class TheParent
{
abstract public function someMethod($argument1,$argument2);
}
class TheChild extends TheParent
{
public function someMethod($argument1='',$argument2)
{
return;
}
}
$test = new TheChild();
?>
Expected result:
----------------
I believe this should produce a fatal error, as the argument list for
TheChild::someMethod() does not match the argument list for
TheParent::someMethod().
Actual result:
--------------
In practice, this code executes without errors.
Additionally :
* If usage of default values do not match (abstract vs. concrete) for
the 2nd argument, a fatal error is produced.
* If usage of default values do not match for the first argument (as
in the reproduce code), but there is matching usage of default values
for the 2nd argument (add a default value to the abstract and concrete
someMethod() in the reproduce code), a fatal error is produced.
* Using a default value for the first argument of the abstract method,
and omitting a default argument from the first argument of the concrete
method, executes without errors.
For a single abstract/concrete method with 2 arguments, there are 16
possible combinations of usage of default arguments. I've tried all of
them by varying the argument list of the provided reproduce code, and
these are the only results that seem odd.
Apparently, the 1st argument to a method is allowed to differ from its
abstract definition in its usage of a default value, though no other
arguments are.
An addition to the Manual page on abstract methods indicating what
constitutes an identical method signature, especially in regards to
default arguments, would be very helpful.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40212&edit=1