Forgot your password?
typodupeerror

Submission Summary: 0 pending, 1 declined, 0 accepted (1 total, 0.00% accepted)

PHP

+ - Should PHP have Operator Overloading ?

Submitted by
garett_spencley
garett_spencley writes "I recently began the design phase on a new, rather large, project and am taking an object oriented approach. I considered using Java or C++ but have decided to chose PHP due largely to the amount of features built-in that I would otherwise have to implement myself or find 3rd party libraries for.

This project will implement several APIs and one thing that I would like to build into the design of those APIs is type enforcement. PHP has type hinting but only for classes and arrays. In order to strongly type a variable you have to use functions like is*() and settype() etc. and throw your own errors throughout all of your code. It would be ideal if I could create classes for various types and use operator overloading to perform operations without having to use methods or do a lot of type checking that might be forgotten, done incorrectly and, at the very least, clutter up the code.

Upon doing some reading it seems that there is very strong opposition from the PHP developers to include operator overloading in any near future version. From the Zend website:

"Jason Greene was interested in seeing the engine adopt some form of operator overloading. Both Andrei Zmievski and Zeev Suraski agreed that although this feature might have a chance at being useful, it would very likely make things far too complex. At this stage, it is highly doubtful Operator overloading will make it into the second version of the engine — if ever."

So my question is: what does Slashdot think ? Would PHP benefit from operator overloading or would it "make things far too complex" ?"

Of course you can't flap your arms and fly to the moon. After a while you'd run out of air to push against.

Working...