Add methods to object dinamically

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've seen that's possible to add members to objects dinamically, in example:

class MyClass {
   private $a;
}

$MyObject = new MyClass ();
$MyObject->b = 1;

Now $MyObject has a public member called 'b' that has a value of '1'.

The question is, is it possible to add methods in the same way?

I meant something such as:

function sum ( $this ) {
   return $this->a+$this->b;
}

$MyObject->sum = sum;

Note that code will not work, but it illustrates what I'm asking for.

TIA.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux