Add methods to object dinamically

From: Date: Tue, 26 Oct 2004 16:13:10 +0000
Subject: Add methods to object dinamically
Groups: php.general 
Request: Send a blank email to php-general+get-200367@lists.php.net to get a copy of this message
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.

« previous php.general (#200367) next »