php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48804 Overriding results in declaration error
Submitted: 2009-07-05 15:49 UTC Modified: 2009-07-18 21:08 UTC
Votes:5
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:1 (20.0%)
From: christian dot achatz at adventure-php-framework Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.0 OS: CentOS 5.3 (final)
Private report: No CVE-ID: None
 [2009-07-05 15:49 UTC] christian dot achatz at adventure-php-framework
Description:
------------
As of PHP 5.3.0 my custom class (PageControllerInputFilter) is not compiling any more. Reason for this is:

Declaration of PageControllerInputFilter::filter() should be compatible with that of AbstractFilter::filter().

Rewriting the filter() function to signature "filter($filterInstruction,$input = null)" would solve the problem, but this is no implementation of the filter() method (e.g. interface behaviour) on PageControllerInputFilter, but overriding. Hence, the name of the variables must not be spellt equally. Even in JAVA, you can freely choose your variable names when overriding a method from a super-class.

Tests were executed using PHP compiled from source on my centos machine using

[root@centos53 ~]# md5sum /root/php53-source/php-5.3.0.tar.bz2
846760cd655c98dfd86d6d97c3d964b0  /root/php53-source/php-5.3.0.tar.bz2
[root@centos53 ~]# ./configure --with-apxs2=$(which apxs) --prefix=/root/php53/ --with-zlib --without-pear
[root@centos53 ~]# make
[root@centos53 ~]# make install

Reproduce code:
---------------
abstract class AbstractFilter extends coreObject {

   function AbstractFilter(){
   }

   function filter($filterInstruction,$input = null){
      return $input;
   }

}

class PageControllerInputFilter extends AbstractFilter {

   function PageControllerInputFilter(){
   }

   function filter($instruction,$content){
      return $content;
   }

}

Definition of the class coreObject can be seen here:
http://adventurephpfra.svn.sourceforge.net/viewvc/adventurephpfra/branches/php5/1.10/core/pagecontroller/pagecontroller.php?revision=573&view=markup

Expected result:
----------------
No fatal, no declaration warning.

Actual result:
--------------
Declaration of PageControllerInputFilter::filter() should be compatible with that of AbstractFilter::filter().
Fatal error: Class 'PageControllerInputFilter' not found in /var/www/html/php53/apps/core/filter/PageControllerInputFilter.php on line 82.

Package to test this behaviour can be found here:
http://media.adventure-php-framework.org/php53/adventure-demopack-1.10-RC1-2009-07-05-1404-php5.tar.gz. Just extract into document root and call via browser.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-18 00:21 UTC] felipe@php.net
This error is due the default value required for the param., not because the variable name.
 [2009-07-18 21:08 UTC] christian dot achatz at adventure-php-framework
Hello felipe,

I'm not sure, if I have understood your answer. Defining a default value using

$input = null

should - in my opinion - let the developer skip this argument in derived classes. This behaviour has always been up to PHP, since overloading is not supported. Hence, the behaviour is not consistent, though.

Thanks for a futher answer on this topic.

Christian
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Aug 23 22:01:28 2019 UTC