#48804 [Bgs]: Overriding results in declaration error
| From: | christian dot achatz at adventure-php-framework | Date: | Sat, 18 Jul 2009 21:08:08 +0000 |
| Subject: | #48804 [Bgs]: Overriding results in declaration error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-139905@lists.php.net to get a copy of this message | ||
ID: 48804
User updated by: christian dot achatz at adventure-php-framework
Reported By: christian dot achatz at adventure-php-framework
Status: Bogus
Bug Type: Class/Object related
Operating System: CentOS 5.3 (final)
PHP Version: 5.3.0
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2009-07-18 00:21:35] felipe@php.net
This error is due the default value required for the param., not
because the variable name.
------------------------------------------------------------------------
[2009-07-05 15:49:34] 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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48804&edit=1