I have a very strange and repeatable problem with a flag I've created with 7.x-2.1. Loading the flag via an export (I'm exporting and deploying using Features) kills Drupal with the error

PHP Fatal error:  Cannot access property started with '\0' in /opt/my-site/drupal/sites/all/modules/contrib/flag/flag.inc on line 213

The cause turns out to be the exported flag.

It looks something like this:

>
$flags = array();
// Exported flag: "Mail Me On New Posts To This Group".
$flags['subscribe_group_content'] = array(
  '' . "\0" . '*' . "\0" . 'defaultValues' => array(
    'isOverridden' => FALSE,
    'overridesApplied' => FALSE,
    'ogContext' => FALSE,
    'fid' => '2',
    'content_type' => 'node',
    'name' => 'subscribe_group_content',
    'title' => 'Mail Me On New Posts To This Group',
    'global' => '0',
    'types' => array(
      0 => 'chapter_group',
      1 => 'dacountry_group',
      2 => 'region_group',
      3 => 'topic_group',
    ),
    'flag_short' => 'Subscribe me to emails for this group',
    'flag_long' => 'Send me mail on new messages',
    'flag_message' => 'You are subscribed to email notifications',
    'unflag_short' => 'Stop sending me email for this group',
    'unflag_long' => 'Stop sending me email notifications on new content',
    'unflag_message' => 'Email notifications have been turned off.',
    'unflag_denied_text' => '',
    'link_type' => 'toggle',
    'roles' => array(
      'flag' => array(
        0 => '11',
        1 => '7',
      ),
      'unflag' => array(
        0 => '11',
        1 => '7',
      ),
    ),
    'weight' => 0,
    'show_on_form' => 0,
    'access_author' => '',
    'show_on_page' => 1,
    'show_on_teaser' => 1,
    'show_contextual_link' => 0,
    'i18n' => 0,
    'module' => 'group_content_notification_system',
    'locked' => array(
      'name' => 'name',
    ),
  ),
  'isOverridden' => FALSE,
  'overridesApplied' => FALSE,
  'ogContext' => FALSE,
  'content_type' => 'node',
  'title' => 'Mail Me On New Posts To This Group',
  'global' => '0',
  'types' => array(
    0 => 'chapter_group',
    1 => 'dacountry_group',
    2 => 'region_group',
    3 => 'topic_group',
  ),
  'flag_short' => 'Subscribe me to emails for this group',
  'flag_long' => 'Send me mail on new messages',
  'flag_message' => 'You are subscribed to email notifications',
  'unflag_short' => 'Stop sending me email for this group',
  'unflag_long' => 'Stop sending me email notifications on new content',
  'unflag_message' => 'Email notifications have been turned off.',
  'unflag_denied_text' => '',
  'link_type' => 'toggle',
  'roles' => array(
    'flag' => array(
      0 => '11',
      1 => '7',
    ),
    'unflag' => array(
      0 => '11',
      1 => '7',
    ),
  ),
  'weight' => 0,
  'show_on_form' => 0,
  'access_author' => '',
  'show_on_page' => 1,
  'show_on_teaser' => 1,
  'show_contextual_link' => 0,
  'i18n' => 0,
  'module' => 'group_content_notification_system',
  'locked' => array(
    'name' => 'name',
  ),
  'api_version' => 2,
);
return $flags;

The issue is the truly weird

'' . "\0" . '*' . "\0" . 'defaultValues' => array(

If I edit out the part before 'defaultValues', everything works as expected. But this line in the export kills PHP deader than a doornail.

Not sure why this occurs, or how.

Comments

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

My exported flag looks like this:

  $flags = array();
  // Exported flag: "Bookmarks".
  $flags['bookmarks'] = array(
    'entity_type' => 'node',
    'title' => 'Bookmarks',
    'global' => '0',
    'types' => array(
      0 => 'article',
    ),
    'errors' => array(),
    'flag_short' => 'Bookmark this',
    'flag_long' => 'Add this post to your bookmarks',
    'flag_message' => 'This post has been added to your bookmarks',
    'unflag_short' => 'Unbookmark this',
    'unflag_long' => 'Remove this post from your bookmarks',
    'unflag_message' => 'This post has been removed from your bookmarks',
    'unflag_denied_text' => '',
    'link_type' => 'toggle',
    'weight' => 0,
    'show_in_links' => array(
      'full' => 'full',
      'teaser' => 'teaser',
      'rss' => 0,
      'search_index' => 0,
      'search_result' => 0,
    ),
    'show_as_field' => 0,
    'show_on_form' => 1,
    'access_author' => '',
    'show_contextual_link' => 0,
    'i18n' => 0,
    'api_version' => 3,
    'module' => 'test_2013236',
    'locked' => array(
      0 => 'name',
    ),
  );
  return $flags;

Do you maybe have modules that either alter the flag object, or alter Features exports?

gildir’s picture

Version: 7.x-2.1 » 7.x-3.3
Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

I'm having the same issue with the newer version of flag. I have og_flag (3.x) installed as well, though that module does not appear to be setting up anything special for features export.

$flags['flag_leadership'] = array(
    '' . "\0" . '*' . "\0" . 'defaultValues' => array(
      'isOverridden' => FALSE,
      'overridesApplied' => FALSE,
      'ogContext' => FALSE,
      'fid' => 1,
      'entity_type' => 'node',
      'name' => 'flag_leadership',

Same issue at the beginning:

'' . "\0" . '*' . "\0" . 'defaultValues' => array(
joachim’s picture

Can you do some debugging in Features to see where those extra strings are coming from?

gildir’s picture

The issue is that og_flag introduces protected fields when extending the flag classes. These are prefaced with "\0*\0" on array cast (likewise private fields are prefaced with "\0class\0") since PHP 5.3.0. This is likely happening at the array cast on line 37 of flag.export.inc.

This causes the following when clearing the cache (and similar errors at other times):

Fatal error:  Cannot access property started with '\0' in public/sites/all/modules/contrib/flag/includes/flag/flag_flag.inc on line 156

Stack trace:
  1. {main}() public/index.php:0
  2. menu_execute_active_handler() public/index.php:21
  3. call_user_func_array() public/includes/menu.inc:517
  4. admin_menu_flush_cache() public/includes/menu.inc:517
  5. drupal_flush_all_caches() public/sites/all/modules/contrib/admin_menu/admin_menu.inc:898
  6. actions_synchronize() public/includes/common.inc:7449
  7. actions_list() public/includes/actions.inc:275
  8. drupal_alter() public/includes/actions.inc:166
  9. flag_action_info_alter() public/includes/module.inc:1101
 10. flag_get_flags() public/sites/all/modules/contrib/flag/includes/flag.actions.inc:71
 11. flag_get_default_flags() public/sites/all/modules/contrib/flag/flag.module:1882
 12. flag_flag::factory_by_array() public/sites/all/modules/contrib/flag/flag.module:1972
joachim’s picture

Project: Flag » OG Flag
Version: 7.x-3.3 »
Component: Miscellaneous » Code

Thanks for the debugging! That's really helpful.

Moving this to the OG Flag project.