Given an array like array('apple', 'pear', 'banana');
features_var_export() would export something like
array(
0 => 'apple',
1 => 'pear',
2 => 'banana',
);
However, it should really export without those keys:
array(
'apple',
'pear',
'banana',
);
And the reason is that if we export (and commit with a VCS), the first example and then change our array to array('apple', 'pear', 'lemon', 'banana');
we would get an absolute mess in our git diff, because all of those keys will have changed so unaffected lines would show as changed.
drupal_var_export has a very elegant solution to this problem:
$export_keys = array_values($var) != $var;
If the array_values of the array match the array itself then don't bother putting indexes before each key.
I was concerned about performance on this, so I've been profiling for a few weeks on some of my larger features and it's not adding more than a couple of milliseconds per rebuild so I'm happy to propose this as a patch.
Comment | File | Size | Author |
---|---|---|---|
features_var_export.patch | 803 bytes | Angry Dan | |
Comments
Comment #1
Angry Dan CreditAttribution: Angry Dan commentedComment #2
mpotter CreditAttribution: mpotter commentedMy concern with this is it will cause a lot of existing features to get marked as overridden and require re-exporting. This isn't something I can do this close to the 2.0 release, so postponing this till after then.