Add field collection table in code I am creating a form to collect data for a specific content type which has a field collection in it. 

So basically I am creating nodes manually through form API. 
What I need to do is to add a field collection table to my form which corresponds to the field collection I declared in the node type. 

I have got how the table is rendered in the original add content form, which is like this:

[field_student_grades] =&gt; Array
    (
        [#type] =&gt; container
        [#attributes] =&gt; Array
            (
                [class] =&gt; Array
                    (
                        [0] =&gt; field-type-field-collection
                        [1] =&gt; field-name-field-student-grades
                        [2] =&gt; field-widget-field-collection-table
                    )

            )

        [#weight] =&gt; 5
        [#tree] =&gt; 1
        [#language] =&gt; und
        [und] =&gt; Array
            (
                [0] =&gt; Array
                    (
                        [#entity_type] =&gt; field_collection_item
                        [#entity] =&gt; FieldCollectionItemEntity Object
                            (
                                [fieldInfo:protected] =&gt; 
                                [hostEntity:protected] =&gt; stdClass Object
                                    (
                                        [uid] =&gt; 1


But I do not know how to deal with the [und] and [hostEntity:protected] and stdClass Object in code.
You can't access Protected members directly.

you'll need to extend the class that represents that object to provide getter methods for the protected properties.