|
Posted by Michael Fesser on 11/16/07 13:50
..oO(DiamondEagle)
>Michael Fesser wrote:
>>
>> It's probably the PECL extension of the same name.
>>
>> http://pecl.php.net/package/operator
>
>Aaah! Thanks!
>
>The summary for the Operator package on that page says that it's:
>"Operator overloading for Objects", but nothing more. What does that
>mean?
Overloading an operator means to define your own methods for it, so you
can use all the predefined operators even with your own objects.
Let's say for example we have a class for complex numbers. The simple
mathematical operators +, -, ... won't work anymore, because complex
numbers have their own rules. So in order to perform calculations with
them, you have to define and use your own methods, e.g.
$c1 = new Complex(5, 7);
$c2 = new Complex(23, 42);
$c1->add($c2); // $c1 becomes (28, 49)
Now with operator overloading you could change the behaviour of the
predefined operators, so that you can still use the nicer syntax, but
internally they will automatically call your method instead:
$c1 = $c1 + $c2; // will call $c1->add(), same result as above
Micha
Navigation:
[Reply to this message]
|