> 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+". What's > TS>>the problem with that? > > The problem is that you can't really know what $a is - PHP is typeless.
When you say "typeless", i think you mean "not statically typed". I've been through this discussion elsewhere - a variable will at any one time have a well-defined type (or unset), which you may overload on, so the language is definitely not typeless. An example of a typeless (or single type language, if you like) language is BCPL, where there was only one type, the machine word. As mentioned in another posting, operator overloading also exists in other dynamically typed languages, such as Python and Perl. > You'll have to trace all the program up to $a's assignment and hope you > didn't miss reassignment on the way. Yes, variables are dynamically typed, but when you call a function, you typically have an idea of what its type is. Otherwise, the "type hints" for PHP 5 would be pointless! By your argument. > 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. That's right, so we'd really need function overloading to be able to use the free function form, which I think is another good idea (function overloading). > 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 Well, you're certainly entitled to your opinion, but others, including me, think it's worth it. > - 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. Neither will assembly code. Regards, Terje -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php