Re: Why no overloading in PHP5?

From: Ashmodai (ashmodai_at_mushroom-cloud.com)
Date: 01/30/05


Date: Sun, 30 Jan 2005 03:09:53 +0100

Terje Slettebų scribbled something along the lines of:
> "Michael Fesser" <netizen@gmx.net> wrote in message
> news:e6edv0dfabi0db38u0qqm0d4kuq3kb2tbm@4ax.com...
>>In some cases you can solve such issues with interfaces.
>
>
> Yes, for regular function calls. However, if you have a function like:
>
> function add($a, $b)
> {
> return $a + $b;
> }
>
> then without operator overloading, this function simply can't work for
> objects of user-defined types (classes).

Yes, but PHP has only recently evolved into a (less or more) OOP
language and was never meant to care about types.
The entire problem of user-defined types only exists when you're using
instances of classes (i.e. objects).

Without classes PHP's approach works well. Once you're using classes,
you need to be a bit more careful.

The OCP may be a bit harmed by PHP's approach, but traditional function
overloading would not work in PHP because of the way it treats types.

I think in PHP it's better to think of classes as something different
than types. An object is of type "object", so to say.
It seems awfully wrong from the perspective of a C++ or Java programmer
but we're not talking about C++ or Java anyway.

Arrays are very different from those in C++ too so I don't see what your
problem is.

As for overloading in PHP, I think the name is descriptive and correct,
but I can see why you were confused about its use.

--
Ashmo


Relevant Pages

  • Re: Why no overloading in PHP5?
    ... but PHP has only recently evolved into a OOP ... The entire problem of user-defined types only exists when you're using ... overloading would not work in PHP because of the way it treats types. ... It seems awfully wrong from the perspective of a C++ or Java programmer ...
    (comp.lang.php)
  • Re: [PHP] accessing variables within objects
    ... Philip Thompson wrote: ... You will want to look at using the Overloading feature of PHP5. ... This would get rid of a lot of your NOTICEs from PHP. ... "Some men are born to greatness, some achieve greatness, ...
    (php.general)
  • Re: Object of class Person could not be converted to string
    ... the language had been better planned from the start. ... Implement operator overloading in its entirety and allow the base ... of PHP 5, __toStringmethod is used if applicable. ... variable type in a string context, you can no longer do that. ...
    (comp.lang.php)
  • Re: [PHP] accessing variables within objects
    ... You will want to look at using the Overloading feature of PHP5. ... This would get rid of a lot of your NOTICEs from PHP. ... I would add a method something like the following to your class and it should fix the problems with trying to access properties that do not exist. ...
    (php.general)
  • Re: Why no overloading in PHP5?
    ... >> Given that PHP isn't strongly type, I don't really see the need. ... Overloading allows you to do things ... PHP, the answer is at least twofold. ... typing strength of a language is extremely important here. ...
    (alt.php)