Re: PHP 5.1 - operator overloading
| From: | Stanislav Malyshev | Date: | Thu, 03 Feb 2005 19:38:17 +0000 |
| Subject: | Re: PHP 5.1 - operator overloading | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-14588@lists.php.net to get a copy of this message | ||
TS>>When you say "typeless", i think you mean "not statically typed".
TS>>I've been
Not only, but in this case it is the main trait I meant.
TS>>through this discussion elsewhere - a variable will at any one time have a
TS>>well-defined type (or unset), which you may overload on, so the language is
That's the whole point - in PHP there's no mechanism you could overload
function based on the types of their parameters, neither statically nor
dynamically. To add this thing would be a very major change and will open
galactic-size can of worms (think "implicit conversions", "converting
constructors", "multiple inheritance", etc.). And this would seriously
complicate function call logic - which is very bad, because, unlike
statically-typed language, we can not offload this complexity to one-time
compile stage.
TS>>Yes, variables are dynamically typed, but when you call a function, you
TS>>typically have an idea of what its type is. Otherwise, the "type hints" for
TS>>PHP 5 would be pointless! By your argument.
Type hints check if the argument passed to function is of the right type.
They don't make PHP call different functions on different argument types.
TS>>That's right, so we'd really need function overloading to be able to use the
TS>>free function form, which I think is another good idea (function
TS>>overloading).
See above.
TS>>> - except for select things like
TS>>> complex and matrices (and maybe two more things like this) I don't see any
TS>>> value in having, say, + overloaded. Using good old methods will never fail
TS>>> you.
TS>>
TS>>Neither will assembly code.
What is with that assembly code that you keep mentioning it? Assembly code
is entirely irrelevant to the discussion, since, as I already explained
once, difference between assebmly code and higher-level programming
languages in in complexity incapsulation, while difference between
operator overloading and using method is purely syntactical - operator
overloading can be translated one-to-one to method calls without exposing
any complexity, while translating method call to assemly exposes a lot of
complexity.
--
Stanislav Malyshev, Zend Products Engineer
stas@zend.com http://www.zend.com/ +972-3-6139665 ext.115