Given an array like array('apple', 'pear', 'banana'); features_var_export() would export something like

<?php
array(
 
0 => 'apple',
 
1 => 'pear',
 
2 => 'banana',
);
?>

However, it should really export without those keys:

<?php
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:

<?php
$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.

Files: 
CommentFileSizeAuthor
features_var_export.patch803 bytesAngry Dan
PASSED: [[SimpleTest]]: [MySQL] 40 pass(es).
[ View ]

Comments

Status:Active» Needs review

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