Posted by Ignigena on May 15, 2012 at 8:37pm
5 followers
| 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)
<?phpif (!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)
<?phpif (!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
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.
#3
The last submitted patch, illegalstringoffset-1580466-2.patch, failed testing.
#4
Trying again ... sorry.
#5
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.
#7
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.