Re: Dinamically adding methods to an object instance?
| From: | Robby Russell | Date: | Mon, 15 Nov 2004 18:17:33 +0000 |
| Subject: | Re: Dinamically adding methods to an object instance? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202063@lists.php.net to get a copy of this message | ||
On Mon, 2004-11-15 at 18:56 +0100, Francisco M. Marzoa Alonso wrote:
> I've seen that's possible to add public members to objects dinamically,
> such as:
>
> <?php
>
> class TestClass {
> public $One=1;
> }
>
> $Obj = new TestClass ();
> $Obj->Two = 2;
>
> echo $Obj->Two;
> ?>
>
> There'll be a public "Two" member that's not defined in the class.
>
Hmm, don't think that you can do this. You could do something like this
though:
class foo
{
var $bar = array();
function foo()
{
$this->bar['One'] = 1;
}
}
$obj =& new foo();
$obj->bar['Two'] = 2;
print_r($obj);
----
foo Object
(
[bar] => Array
(
[One] => 1
[Two] => 2
)
)
> Is it possible to add methods dinamically to an object instance in same
> way? how? will these methods have access to private and protected
> members of the class of the object?
>
> Thanks a lot in advance...
>
--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | robby@planetargon.com
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
* --- Now supporting PHP5 ---
****************************************/
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc