The function features_var_export first check if the first parameter '$var' is an object like so :

if (is_object($var)) {
  $output = method_exists($var, 'export') ? $var->export() : features_var_export((array) $var);
}

and the last thing the function does, is replacing '***BREAK***' with '\n' only if '$init' is TRUE

if ($init) {
  $output = str_replace("***BREAK***", "\n", $output);
}

if you pass an object with arrays , everything works good, but if you pass an array of objetcs, the replacement happens too early and it adds spaces in the string.

anyway, this patch solve the problem !

doing this :

if (is_object($var)) {
  $output = method_exists($var, 'export') ? $var->export() : features_var_export((array) $var, $prefix, FALSE);
}

instead of this :

if (is_object($var)) {
  $output = method_exists($var, 'export') ? $var->export() : features_var_export((array) $var);
}
CommentFileSizeAuthor
features.patch727 bytesemman31
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpotter’s picture

Version: 6.x-1.2 » 7.x-1.x-dev

Unfortunately, that just goes back to how the code used to be. See this issue #1505044: features_var_export adds additional prefix to multiline strings contained in objects.

So we need a way to handle both cases properly and I cannot commit the patch as it is. Also marking this for D7 since we fix stuff in D7 first and then back-port to D6.

emman31’s picture

Both patch are (almost) same !

I don't have a D7 version right now, can't try it on Drupal 7

mpotter’s picture

I think the problem might be that you are not using the latest 1.x-dev version of Features. The current code is:
$output = method_exists($var, 'export') ? $var->export() : features_var_export((array) $var, '', FALSE);
which is different than what your patch is applied against. So your patch doesn't apply.

emman31’s picture

Well, this Issue is a duplicate of the one you linked.
And I just checked on D7 code and it seems already ported to D7.

Only one thing though, is it ok to call features_var_export with an empty string as $prefix parameter ? Shouldn't we pass the same prefix instead ? (It's the only difference between my patch and the one already applied)

kenorb’s picture