Download & Extend

Illegal string offset in PHP 5.4

Project:Pathauto
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

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

Comments

#1

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;
    }
  }
?>

#2

Version:7.x-1.1» 7.x-1.x-dev
Status:active» needs review

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.

AttachmentSizeStatusTest resultOperations
illegalstringoffset-1580466-2.patch899 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Invalid PHP syntax in sites/default/modules/pathauto/pathauto.module.View details | Re-test

#3

Status:needs review» needs work

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

#4

Status:needs work» needs review

Trying again ... sorry.

AttachmentSizeStatusTest resultOperations
illegalstringoffset-1580466-4.patch824 bytesIdleFAILED: [[SimpleTest]]: [MySQL] 316 pass(es), 0 fail(s), and 12 exception(s).View details | Re-test

#5

Status:needs review» needs work

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

#6

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.

AttachmentSizeStatusTest resultOperations
pathauto.module.zip6.78 KBIgnoredNoneNone

#7

Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
illegalstringoffset-1580466-6.patch1022 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 316 pass(es).View details | Re-test
nobody click here