Re: PHP 5.1
| From: | Terje Slettebø | Date: | Thu, 03 Feb 2005 23:59:09 +0000 |
| Subject: | Re: PHP 5.1 | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-14617@lists.php.net to get a copy of this message | ||
>From: "Greg Beaver" <cellog@php.net>
> Terje Slettebø wrote:
> > 1) $result=$c1.multiply($c2).divide($c1.add($c2));
> >
> > 2) $result=($c1 * $c2) / ($c1 + $c2);
> >
> > They sure aren't to me. Moreover, they are not the same: operator
> > overloading enable you to use infix notation, whereas functions use
prefix,
> > only.
>
> Um, you're wrong. Infix is quite easy to do using (static or
> non-static) functions:
>
> 3) $result = Complex::divide(Complex::multiply($c1, $c2),
Complex::add($c1, $c2));
Let me rewrite your expression as an abstract expression:
result = op(op(c1, c2), op(c1, c2))
Here, "op" is the function name ("add", etc.). As you can see, your
expression is still one using prefix operators ("op arg1 arg2"), rather than
infix ("arg1 op arg2"). I'm afraid your correction is incorrect.
Your example is the same as 1), above, using static functions.
Regards,
Terje