Getting the following errors running PHP 5.4:

Warning: Illegal string offset 'pathauto' in pathauto_field_attach_form() (line 300 of /sites/all/modules/pathauto/pathauto.module).
Warning: Illegal string offset 'pathauto' in pathauto_field_attach_form() (line 319 of /sites/all/modules/pathauto/pathauto.module).
Warning: Illegal string offset 'pathauto' in pathauto_field_attach_form() (line 329 of /sites/all/modules/pathauto/pathauto.module).

Files: 
CommentFileSizeAuthor
#15 illegalstringoffset-1580466-15.patch894 bytesmasipila
#8 openatrium-with-php5-5--1580466.patch1.64 KBsobi3ch
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch openatrium-with-php5-5--1580466.patch. Unable to apply patch. See the log in the details link for more information. View
#7 illegalstringoffset-1580466-6.patch1022 bytesIgnigena
PASSED: [[SimpleTest]]: [MySQL] 316 pass(es). View
#6 pathauto.module.zip6.78 KBhoebekewim
#4 illegalstringoffset-1580466-4.patch824 bytesIgnigena
FAILED: [[SimpleTest]]: [MySQL] 316 pass(es), 0 fail(s), and 12 exception(s). View
#2 illegalstringoffset-1580466-2.patch899 bytesIgnigena
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/pathauto/pathauto.module. View

Comments

Ignigena’s picture

I was able to surpress the errors by changing the function at line 294 to the following. It's not the most clean or compact code and I can't guarantee it's a good solve but hopefully this helps figure out the issue:

NEW (starts at line 294 of pathauto.module)

<?php
if (!isset($entity->path['pathauto'])) {
    if (!empty($id)) {
      module_load_include('inc', 'pathauto');
      $uri = entity_uri($entity_type, $entity);
      $path = drupal_get_path_alias($uri['path'], $langcode);
      $pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
      $pathauto_array = array(
          $entity->path,
          "pathauto" => ($path != $uri['path'] && $path == $pathauto_alias),
      );
      //$entity->path["pathauto"] = ($path != $uri['path'] && $path == $pathauto_alias);
      $entity->path=$pathauto_array;
    }
    else {
    $pathauto_array = array(
          $entity->path,
          "pathauto" => TRUE,
      );
      //$entity->path['pathauto'] = TRUE;
      $entity->path=$pathauto_array;
    }
  }
?>

OLD (starts at line 294 of pathauto.module)

<?php
if (!isset($entity->path['pathauto'])) {
    if (!empty($id)) {
      module_load_include('inc', 'pathauto');
      $uri = entity_uri($entity_type, $entity);
      $path = drupal_get_path_alias($uri['path'], $langcode);
      $pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
      $entity->path["pathauto"] = ($path != $uri['path'] && $path == $pathauto_alias);
    }
    else {
      $entity->path['pathauto'] = TRUE;
    }
  }
?>
Ignigena’s picture

Version:7.x-1.1» 7.x-1.x-dev
Status:Active» Needs review
StatusFileSize
new899 bytes
FAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/pathauto/pathauto.module. View

It seems like $entity->path is sometimes a string not an array which is what is causing the warnings in PHP 5.4. I've attached a patch against the latest dev branch with my solution above cleaned up a tiny bit. I'm sure there's a more "proper" way of fixing this, so feel free to point out anything I've done wrong. Hopefully this at least helps push the issue along.

Status:Needs review» Needs work

The last submitted patch, illegalstringoffset-1580466-2.patch, failed testing.

Ignigena’s picture

Status:Needs work» Needs review
StatusFileSize
new824 bytes
FAILED: [[SimpleTest]]: [MySQL] 316 pass(es), 0 fail(s), and 12 exception(s). View

Trying again ... sorry.

Status:Needs review» Needs work

The last submitted patch, illegalstringoffset-1580466-4.patch, failed testing.

hoebekewim’s picture

StatusFileSize
new6.78 KB

I don't know if this is the correct solution but it seems to fix the error:

Line 294 in pathauto.module:

if (!isset($entity->path['pathauto'])) {
    if (!empty($id)) {
      module_load_include('inc', 'pathauto');
      $uri = entity_uri($entity_type, $entity);
      $path = drupal_get_path_alias($uri['path'], $langcode);
      $pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
      if(isset($entity->path)){
            $entity->path = array(
                  $entity->path,
                  'pathauto' => ($path != $uri['path'] && $path == $pathauto_alias),
            );
      }
      else{
            $entity->path = array(
                  'pathauto' => ($path != $uri['path'] && $path == $pathauto_alias),
            );
      }
     
    }
    else {
            $entity->path = array('pathauto' => TRUE);
    }
  }

I've placed my pathauto.module file in the annex.

Ignigena’s picture

Status:Needs work» Needs review
StatusFileSize
new1022 bytes
PASSED: [[SimpleTest]]: [MySQL] 316 pass(es). View

Good call hoebekewim on the addition of the isset check. Addressed a few minor coding standards issues and rolled this into a patch, attached below.

sobi3ch’s picture

Issue summary:View changes
StatusFileSize
new1.64 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch openatrium-with-php5-5--1580466.patch. Unable to apply patch. See the log in the details link for more information. View

I don't know this is useful but I'm adding patch that's working with Warning message in PHP 5.5 with openatrium 1.12

openatrium-with-php5-5--1580466.patch (1.64 KB)

Status:Needs review» Needs work

The last submitted patch, 8: openatrium-with-php5-5--1580466.patch, failed testing.

masipila’s picture

Status:Needs work» Reviewed & tested by the community

Patch in comment #7 reviewed and tested. Changing status to RTBC.

DamienMcKenna’s picture

Dave Reid’s picture

Status:Reviewed & tested by the community» Needs review
  1. +++ b/pathauto.module
    @@ -297,10 +297,20 @@ function pathauto_field_attach_form($entity_type, $entity, &$form, &$form_state,
    +      if(isset($entity->path)) {

    Missing space in between if and the condition.

  2. +++ b/pathauto.module
    @@ -297,10 +297,20 @@ function pathauto_field_attach_form($entity_type, $entity, &$form, &$form_state,
    +        $entity->path = array(
    +          $entity->path,
    +          'pathauto' => ($path != $uri['path'] && $path == $pathauto_alias),
    +        );
    +      }
    +      else {
    +        $entity->path = array(
    +          'pathauto' => ($path != $uri['path'] && $path == $pathauto_alias),
    +        );

    What are the effects of this since this is redefining $entity->path only if it's defined?

sobi3ch’s picture

Can not apply patch from #7 on branch 7.x-1.x

$ git apply -v illegalstringoffset-1580466-6.patch
Checking patch pathauto.module...
error: while searching for:
      $uri = entity_uri($entity_type, $entity);
      $path = drupal_get_path_alias($uri['path'], $langcode);
      $pathauto_alias = pathauto_create_alias($entity_type, 'return', $uri['path'], array($entity_type => $entity), $bundle, $langcode);
      $entity->path['pathauto'] = ($path != $uri['path'] && $path == $pathauto_alias);
    }
    else {
      $entity->path['pathauto'] = TRUE;
    }
  }


error: patch failed: pathauto.module:297
error: pathauto.module: patch does not apply

laptop:/var/www/sandbox/drupal/pathuto-issue-1580466/sites/all/modules/pathauto (7.x-1.x)*
$ patch -p1 < illegalstringoffset-1580466-6.patch
patching file pathauto.module
Hunk #1 FAILED at 297.
1 out of 1 hunk FAILED -- saving rejects to file pathauto.module.rej
Dave Reid’s picture

masipila’s picture

The patch from #7 does not apply anymore to the latest 7.x-1.x branch (and not to 7.x-1.3) because the line numbers have changed. Attached is a new patch that does apply to the latest dev.

@Dave Reid / comment #12:
1. The if isset coding standard is now fixed
2. I believe the reason why $entity->path is redefined is this:

Before the patch
dpm($entity->path);

  • This shows that my $entity->path contains only a string value of the path. The notable thing is that $entity->path is not an array.
  • As a result, I'm getting an illegal offset warning a few lines later here:
    $form['path']['pathauto'] = array(
        '#type' => 'checkbox',
        '#title' => t('Generate automatic URL alias'),
        '#default_value' => $entity->path['pathauto'],
        '#description' => t('Uncheck this to create a custom alias below.'),
        '#weight' => -1,
      );

After the patch
The patch ensures that $entity->path will be an array. If it has been set previously, $entity->path[0] will be the actual path and $entity->path['pathauto'] will be the result of ($path != $uri['path'] && $path == $pathauto_alias). As a result, the '#default_value' => $entity->path['pathauto'] will not throw an illegal offset warning.

edit: fixed the version from 1.4 to 1.3 in the beginning. I meant to say that the patch #7 did not apply to 1.3.