[nycphp-talk] Two objects of the same type in same script
David Krings
ramons at gmx.net
Wed Jul 25 14:45:27 EDT 2007
Allen Shaw wrote:
> David Krings wrote:
>> ...I will need three editor
>> components on the page and now wonder on how to add a second editor
>> object. ...
>>
>> Currently, I got this:
>> $oFCKeditor = new FCKeditor('sbtext');
>> ...
>> When I now want to initiate a new editor, do I change it like this:
>> $oFCKeditor = new FCKeditor('sbnotes') ;
>> or like this
>> $oFCKeditorNotes = new FCKeditor('sbnotes');
>>
>> So, unrelated to the editor, how do I instantiate a second instance of
>> an object?
>>
>
> Your second choice is the one you want. The code "new
> FCKeditor('whatever')" returns a distinct FCKeditor object, which you
> should store in a distinct variable. If you just use the same variable
> as for the first object, $oFCKeditor, you'll overwrite the value of that
> variable and lose the object.
>
> OO concepts can be daunting at times, but in this case it's a simple
> matter of storing someting in a variable. If you wrote:
>
> $fruit = 'apple'; // I need some fruit
> $fruit = 'pear'; // I need another kind of fruit
>
> then you'd expect the 'apple' value to be overwritten and gone. Same
> with the objects.
>
> Hope this helps.
>
> - Allen
It definitely does! Thank you very much! :)
More information about the talk
mailing list