You are here: Re: What is the php_operator.dll extension « PHP Programming Language « IT news, forums, messages
Re: What is the php_operator.dll extension

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация