We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Member Group Returned Object Size - Huge!

Developer Preview

JohnD's avatar
JohnD
114 posts
10 years ago
JohnD's avatar JohnD

Running the code:

$member_groups = ee('Model')->get($member_groups)->limit(1)->all();

returns an object with the first few lines:

Member Groups EllisLab\ExpressionEngine\Service\Model\Collection Object ( [association:EllisLab\ExpressionEngine\Service\Model\Collection:private] => [elements:protected] => Array ( [0] => EllisLab\ExpressionEngine\Model\Member\MemberGroup Object

My

print_r()

of this object takes up 160,858 lines on my 27 inch monitor and 20MB of file space. A

var_dump

yields only 133 lines, but at the bottom gives me:

protected '_facade' => 
            object(EllisLab\ExpressionEngine\Service\Model\Facade)[462]
              ...
          protected '_validator' => 
            object(EllisLab\ExpressionEngine\Service\Validation\Validator)[551]
              ...
          protected '_associations' => 
            array (size=12)
              ...
          protected '_property_types' => 
            array (size=101)
              ...
          protected '_filters' => 
            array (size=4)
              ...
          protected '_clean_backups' => 
            array (size=0)
              ...
          protected '_mixin_manager' => 
            object(EllisLab\ExpressionEngine\Library\Mixin\Manager)[443]
              ...

so I can’t really tell what’s in there and/or why I should care.

Could we not have an option to just give us the contents of the table in which we are interested?

Ultimately - are there plans to document what the “facade” stuff is all about and why it needs to be in the object?

I don’t make these comments lightly, but the ability to segment a large object into manageable chunks (say, for debugging) is only doable when you already know something about its structure before you start.

Suggestions/rebuttals welcome.

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
10 years ago
Pascal Kriete's avatar Pascal Kriete

Hi John,

It’s a lot of object references, so luckily the actual object isn’t very big at all.

Could we not have an option to just give us the contents of the table in which we are interested?

I think what you’re looking for here is $model->getValues() (alias: toArray(), which might be easier to remember), if you var_dump that you should see a fairly nicely sized array of fields.

Ultimately - are there plans to document what the “facade” stuff is all about and why it needs to be in the object?

These related objects are largely private and supporting. The facade in question is essentially equivalent to the object that you get when you call ee('Model'). It’s unfortunate that php dumps them even though they are not publicly accessible.

       
JohnD's avatar
JohnD
114 posts
10 years ago
JohnD's avatar JohnD

Hi Pascal - to get the member group table contents, I re-tried using ->asArray():

$member_groups = ee('Model')->get($member_groups)->filter('group_id', '!=', 1)->all()->asArray();

That returns an array of objects, each with protected elements. That’s fine, except that each member group is returned with “protected ‘_facade’ =>” etcetera at the end.

I can deal with that by casting to an array and splitting off the parts I need, but it seems a naff/hacky (not to mention frowned-upon) way to get around the fact that the elements are protected, when all I needed to do in the first place was run a query on the member groups table. I know, run a query = disruptive.

Is there a native way to return whatever parts I want from each object - something like a foreach over an array? The documents mention:

Partial Data TODO Explain the fields() method.

Is the answer in there?

Thanks

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
10 years ago
Pascal Kriete's avatar Pascal Kriete

Hi John,

toArray() should do what you’re looking for. asArray() on the collection just unwraps the collection, whereas toArray() is a method on the model that will actually convert the model to a more meaningful array of public fields. Calling a model method on a collection automatically applies it to all contained models. For example:

$member_groups = ee('Model')->get($member_groups)->filter('group_id', '!=', 1)->all();
var_dump($member_groups->toArray());
// is equivalent to
foreach ($member_groups as $group)
{
    var_dump($group->toArray());
}
       
JohnD's avatar
JohnD
114 posts
10 years ago
JohnD's avatar JohnD

Thank you Pascal for your help on this - your replies have helped me to get to a better grip on my EE V3 conversions, and have gone a long way to show how I can better help myself in the future.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.