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

From: Date: Sun, 21 Apr 2013 05:30:24 +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-178562@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:         dmittner at llnw dot com
 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:

I've got to add my vote to this feature.

My use case consists of data validation methods. If called statically the 
validation tests are limited to things like string length, contents, etc. If 
called on an object it would include those tests (probably calling the static 
form of itself) and also comparative tests to other object conditions.

I sympathize with backwards compatibility but sometimes you have to push 
forward. Case and point, some people I know are working with a Java-based system 
that doesn't support Java 7, so when building new servers they have to 
explicitly install an older version. Cutting a line between major PHP versions 
seems similarly viable.

I'd also cite Magic Quotes which are completely removed in 5.4, which could 
similarly break older PHP4 compatibility. The precedent is set.

Failing all that, how about a configuration option?


Previous Comments:
------------------------------------------------------------------------
[2012-11-20 02:13:10] capitaine dot gloumi at gmail dot com

The "backward compatibility" should set to deprecated any static call of object 
method, and use it IF NO static method with the same name exist.

I use static method and object method with same name in lot of paterns, it's 
useful in lot of case.

------------------------------------------------------------------------
[2012-11-19 03:27:35] aharvey@php.net

If a class is namespaced, by definition it isn't PHP 4 compatible.

------------------------------------------------------------------------
[2012-11-15 23:23:31] jpmarois at hotmail dot com

aharvey@php.net:

Sure, go Microsoft's way and move forward by staying behind for the sake of 
"compatibility".

Please explain why, "As of PHP 5.3.3, methods with the same name as the last 
element of a namespaced class name will no longer be treated as constructor.". If 
PHP wont even initialize a "compatible" PHP 4 class anymore, how is it relevant to 
preserve instance methods being called statically?

------------------------------------------------------------------------
[2012-09-11 01:59:54] aharvey@php.net

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.

------------------------------------------------------------------------
[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?

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


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 (#178562) next »