Re: PHP 5.1 - operator overloading

From: Date: Thu, 03 Feb 2005 16:40:35 +0000
Subject: Re: PHP 5.1 - operator overloading
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-14571@lists.php.net to get a copy of this message
TS>>If $a is an object of a class, then they would both be in the class TS>>definition. One is called "add", and the other is called "operator+". TS>>What's TS>>the problem with that? The problem is that you can't really know what $a is - PHP is typeless. You'll have to trace all the program up to $a's assignment and hope you didn't miss reassignment on the way. TS>>It would if operator overloading was allowed on free functions (as it is in TS>>C++). E..g: You can't do it like in C++, because in C++ function signature includes argument types, and in PHP it does not. I.e., you can't write two operators - one for complex+int and one for complex+complex. In general, it's too much trouble for too little gain - except for select things like complex and matrices (and maybe two more things like this) I don't see any value in having, say, + overloaded. Using good old methods will never fail you. -- Stanislav Malyshev, Zend Products Engineer stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115

« previous php.internals (#14571) next »