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

2011-12-21 Thread mac at macnewbold dot com
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] he...@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


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

2012-09-10 Thread mac at macnewbold dot com
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: 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:

ahar...@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?


Previous Comments:

[2012-09-10 03:00:14] ahar...@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.

--------------------
[2011-12-21 18:26:14] mac at macnewbold dot com

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.




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


#40888 [Com]: Sorts should be stable

2009-10-22 Thread mac at macnewbold dot com
 ID:   40888
 Comment by:   mac at macnewbold dot com
 Reported By:  jo at durchholz dot org
 Status:   Open
 Bug Type: Feature/Change Request
 Operating System: Irrelevant
 PHP Version:  4.4.5
 New Comment:

I don't see any feedback about this very old bug. It is clearly
possible to have a stable sort available in PHP, and clearly more
efficient to offer it in-core rather than at the user level. Is this
simply a WONTFIX?

Philosophically, I strongly believe that the developer should be the
one to decide whether they want to use a less efficient stable sort or a
more efficient but unstable sort on a case by case basis, not the
language designers. As it stands, we're all forced to use much less
efficient solutions when we require a stable sort.


Previous Comments:


[2007-03-22 08:00:37] jo at durchholz dot org

Description:

The manual says this on sorting:

"If two members compare as equal, their order in the sorted array is
undefined. Up to PHP 4.0.6 the user defined functions would keep the
original order for those elements, but with the new sort algorithm
introduced with 4.1.0 this is no longer the case as there is no solution
to do so in an efficient way."

Bug #18299 requests that the old ("stable") sort behavior be restored.
This is denied on the grounds that there is no efficient implementation
for that.

Now it *is* possible to stabilize any sort algorithm, by comparing key
positions if values compare equal.

Um, well, I can imagine that it's inefficient to determine the position
of a key. In that case, I'd propose to introduce a SORT_STABLE flag and
have the engine create a key=>position array when sorting with
SORT_STABLE.
That would still be more efficient than trying to stabilize the sort at
the PHP level. There, I'd have to do the following to get a stable
sort:
* Make a copy of the array,
  wrapping each value in an array ($position, $value)
* Sort with a user-defined function. Have that function compare
  $values, and if these compare equal, compare $positions.
* Unwrap the $values from the resulting sorted array.
In effect, this means the engine will have to construct and garbage
collect an array for each array element, so this is horribly inefficient
compared to any in-engine solution...






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