ID:               9331
 Comment by:       C01t dot te at gmail dot com
 Reported By:      jgsmith at tamu dot edu
 Status:           Suspended
 Bug Type:         Feature/Change Request
 Operating System: Irix 6, Solaris 7, OpenBSD 2.8
 PHP Version:      4.0.4pl1
 New Comment:

Operator overloading will open a new chapter in PHP's objects usage.

And I think that perhaps it could be done through interfaces. May be
included in SPL. 

For example

interface MathOperators
{
   function operatorAdd($object);
   function operatorSub($object);
   function operatorMul($object);
   function operatorDiv($object);
   function operatorInc($object);
   function operatorDec($object);
}

One who needs these functionality just implements this interface (or
interfaces for each operation) and here it is, and operator overloading
:-)


Previous Comments:
------------------------------------------------------------------------

[2007-08-11 07:58:14] nibujoshua at gmail dot com

it is very bad, that there is no operator overloding capability for PHP

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

[2007-04-21 16:49:14] dionyziz at deviantart dot com

I think there are many other people who would like to see this feature
implemented. Is there any chance it could be made available in PHP6?

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

[2001-02-20 01:00:44] [EMAIL PROTECTED]

I hardly believe this will be implemented anytime soon or
accepted at all,
suspending (for the records)

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

[2001-02-19 02:07:25] jgsmith at tamu dot edu

It would be nice to have operator overloading available for 
classes.  Something along the lines of Perl and C++.  I'm 
sure there are other OO languages that provide similar 
functionality.  This would go a long way to allowing the 
creation of object classes that are similar to those built 
into the language.

At least one class I'm wanting to create that could use this 
is an ordered set -- use +,-,*,/ for set union, asymmetric 
difference, intersection, and difference, for example.

Perhaps borrowing the C++ syntax wouldn't be a great burden. 

function operator+(objectClass,objectClass) { ... }

Unfortunately, this would require prototyping of class 
methods, but this is already implicately done for the 
operators (as far as the coder is concerned, even if not in 
fact).

Perhaps one way around the need for an explicit prototype is 
to consider the first argument of the binary operation (the 
left operand) as the governing class for finding the method.  
Then $A+$B == $A->operator+($B) and the function declaration 
is reduced to 

class A {
  function operator+($B) { ... }
}

I think this is important enough to the development of the 
language, and I didn't find mention of it in any of the 
documentation or archives I searched, that I am submitting 
it as a bug report for t

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


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

Reply via email to