Re: Dinamically adding methods to an object instance?

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

 



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@xxxxxxxxxxxxxxx
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
*    --- Now supporting PHP5 ---
****************************************/

Attachment: signature.asc
Description: This is a digitally signed message part


[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