Re: adding a new property to an object instance

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

 



* Skrol29 <skrol29@xxxxxxxxxxx>:
> It's seems to be allowed to add a new property (a member ?) to an object
> instance in both PHP 4 and 5.
> For example:
> **************************
> class Test {
>   var $Prop1 = 'anything';
> }
> $MyObj = new Test;
> $MyObj->Prop2 = 'hello';
> **************************
>
> But I can't found any documentation saying that it's offcially supported or
> not.
> Do you have any information about this ?
> Do you often use added properties ?

I know that it's allowed, but now that I look through the official docs,
I don't see where that behaviour is explicitly made clear. But yes, you
can add properties on the fly at any time -- which is why it's good to
declare any that you KNOW will be used in the class via the 'var'
declarations. That way you have at least documented that those are
reserved.

-- 
Matthew Weier O'Phinney           | mailto:matthew@xxxxxxxxxx
Webmaster and IT Specialist       | http://www.garden.org
National Gardening Association    | http://www.kidsgardening.com
802-863-5251 x156                 | http://nationalgardenmonth.org

-- 
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