php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40212 signature mismatch for abstract/concrete method does not produce a fatal error
Submitted: 2007-01-23 15:18 UTC Modified: 2007-01-24 18:32 UTC
From: alex dot dean at pni dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2007-01-23 (snap) OS: Ubuntu GNU/Linux 2.6.15-27-386
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alex dot dean at pni dot com
New email:
PHP Version: OS:

 

 [2007-01-23 15:18 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-24 00:25 UTC] tony2001@php.net
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.
 [2007-01-24 15:25 UTC] alex dot dean at pni dot com
An addition to the manual on how to define concrete functions that match their abstract versions, with some comments on usage of default values, would probably clear this up for me (and possibly others).
 [2007-01-24 18:32 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is expected behavior.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 10:01:32 2024 UTC