Bug #40837 [Com]: static and non-static functions can't have the same name

From: Date: Wed, 21 Dec 2011 18:26:14 +0000
Subject: Bug #40837 [Com]: static and non-static functions can't have the same name
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-166033@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=40837&edit=1

 ID:                 40837
 Comment by:         mac at macnewbold dot com
 Reported by:        nick dot telford at gmail dot com
 Summary:            static and non-static functions can't have the same
                     name
 Status:             Bogus
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Irrelevant
 PHP Version:        5.2.1
 Block user comment: N
 Private report:     N

 New Comment:

I agree with martijntje and nick.telford - the static function and normal function of the same name
shouldn't have any conflict, and it would be extremely helpful to be able to define the same
function for use both statically and non-statically.

In the meantime, I'm going to try using __call() and __callStatic() to pretend like this
feature actually exists.


Previous Comments:
------------------------------------------------------------------------
[2011-11-26 22:17:42] martijntje at martijnotto dot nl

I have no idea why this bug is closed as 'bogus'. Just because the documentation 
states it is a certain way does not mean that it is right.

I, for one, believe that it should be possible to create both a static and a 
member function with the same name. There would never be any confusion as to 
which function should be called due to the difference of using the :: or -> 
operator.

------------------------------------------------------------------------
[2007-03-16 17:40:02] helly@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

.

------------------------------------------------------------------------
[2007-03-16 16:44:17] nick dot telford at gmail dot com

Description:
------------
When declaring two functions in a class (methods) non-static and static functions may not use the
same names.

While I understand this, this is essentially wrong since static methods and non-static methods are
entirely different.

This also leads me on to another bug/feature suggestion I'm about to file about not being able
to overload static attributes with __set/__get.

Reproduce code:
---------------
class Example {
    public static function test() {}
    public function test() {}
}

$example = new Example();
$example->test();
Example::test();

Expected result:
----------------
No errors, all methods called correctly.

Actual result:
--------------
PHP errors with: Fatal error: Cannot redeclare Example::test()


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=40837&edit=1


Thread (20 messages)

« previous php.bugs (#166033) next »