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

From: Date: Tue, 11 Sep 2012 01:59:54 +0000
Subject: Bug #40837 [Nab]: 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-173307@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
 Updated by:         aharvey@php.net
 Reported by:        nick dot telford at gmail dot com
 Summary:            static and non-static functions can't have the same
                     name
 Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Irrelevant
 PHP Version:        5.2.1
 Block user comment: N
 Private report:     N

 New Comment:

It breaks compatibility with any PHP 4 compatible code that uses static method calls. That's
(obviously) less important than it once was, but there's still plenty of legacy code out there.


Previous Comments:
------------------------------------------------------------------------
[2012-09-10 15:29:23] mac at macnewbold dot com

aharvey@php.net :

What would the impacts be of deprecating static calls to non-static methods? They would seem to not
make much sense, since any uses of $this inside the method (which would be pretty typical since it
is a non-static method) would fail with "Fatal error: Using $this when not in object
context". What is the value of being able to attempt a static call on a non-static method?

------------------------------------------------------------------------
[2012-09-10 03:00:14] aharvey@php.net

For the record, there's no way this can be implemented as it stands: for backward compatibility
reasons, instance methods can be called statically, so the name has to be distinct to disambiguate
between static and instance methods. The call type is not enough.

------------------------------------------------------------------------
[2012-09-07 22:33:55] accounts dot php at nickawilliams dot com

I also support this proposal. On numerous occasions throughout my career writing 
PHP I have found a need for this. While there are workarounds that work, they are 
all fairly verbose, convoluted, and/or difficult to follow. Please consider 
reopening this!

------------------------------------------------------------------------
[2012-08-04 00:46:35] billco at fnarg dot com

Same here!  This is a very useful pattern in other languages, where the same method name can be used
in both static and non-static contexts.

For example, a search() method in static context could create a new result object, while the
non-static form would search within an existing result set.

While it is possible to mimic this sort of behaviour by first creating a "blank" object,
it leads to dual-purpose methods (a big "if" statement), resulting in messy,
unmaintainable code.  Why arbitrarily force developers to violate good OOP practices ?

------------------------------------------------------------------------
[2012-06-28 08:15:27] info at renemaas dot de

Yeah this would be really helpful. I hope anybody of the PHP team will implement 
this kind of "stupid" feature. If not them please provide a "cool" solution for 
using static and non-static functions.

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=40837


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


Thread (20 messages)

« previous php.bugs (#173307) next »