Fatal error: Unsupported operand types in common.inc

Last modified: January 23, 2009 - 05:12

This error happens because the parameters to url() changed in Drupal 6. The most common problem is an enabled module hasn't fully converted it's code from Drupal 5 and is causing the error. To find which module is the problem, change the following code to the function url() in ./includes/common.inc (down around line 1300 or so):

<?php
function url($path = NULL, $options = array()) {
 
// Merge in defaults.
 
$options += array(
   
'fragment' => '',
   
'query' => '',
   
'absolute' => FALSE,
   
'alias' => FALSE,
   
'prefix' => ''
 
);
?>

To the following:

<?php
function url($path = NULL, $options = array()) {
  if (!
is_array($options)) {
    echo
"<pre>";
   
$backtrace = debug_backtrace();
   
var_export($backtrace[0]);
    die();
  }
 
// Merge in defaults.
 
$options += array(
   
'fragment' => '',
   
'query' => '',
   
'absolute' => FALSE,
   
'alias' => FALSE,
   
'prefix' => ''
 
);
?>

Now instead of the fatal error, you will get a result similar to:

array (
  'file' => '/www/drupal-6/sites/all/modules/admin_links/admin_links.module',
  'line' => 65,
  'function' => 'url',
  'args' =>
  array (
    0 => 'node/62/edit',
    1 => NULL,
    2 => NULL,
    3 => true,
  ),
)

The 'file' line should give you a clue as to which module is calling url() incorrectly. In this case, it would be the 'admin_links' module. Then search the module's issue queue to see if anyone else has reported the same problem. If not, file a new bug report so the maintainer can fix the problem. Be sure to include the data from the debugging report in the bug report that you file.

No contrib module identified

markj - March 14, 2009 - 21:25

Here's what is being printed out for me when I hit cron.php (using Drupal 6.10, real path to common.inc replaced with generic values to hide site identity):

array (
  'file' => '/path/to/my/includes/common.inc(1651) : eval()\'d code',
  'line' => 16,
  'function' => 'url',
  'args' =>
  array (
    0 => 'node',
    1 => NULL,
    2 => NULL,
    3 => true,
  ),
)

Anyone else seen this?

eval()\'d code = PHP code in node bodies

markj - May 1, 2009 - 02:16

Found the problem, it was outdated l() calls in a PHP snippet in a node body. Same would probably happen for PHP code in blocks or anywere else it can be used as well.

Fatal error line 2831

zorroposada - March 30, 2009 - 08:29

Initial error message:

Fatal error: Unsupported operand types in /path/to/my/includes/common.inc on line 2831

Tried above troubleshooting code but in line 2831 with $elements instead of $options and:

array (
  'file' => '/path/to/my/includes/common.inc',
  'line' => 2869,
  'function' => 'drupal_render',
  'args' =>
  array (
    0 => 0,
  ),
)

You can try showing more

Dave Reid - May 1, 2009 - 14:53

You can try showing more backtrace information:

<?php
 
if (!is_array($elements)) {
    echo
"<pre>";
   
$backtrace = debug_backtrace();
   
var_export($backtrace);
    die();
  }
?>

Freelance developer | davereid.net | Pro Drupal Development Book
Please help sponsor my attendance at DrupalConSF 2010

url() calls

sunset_bill - May 12, 2009 - 15:10

Seen lots of discussion on this, but I haven't seen any simple how-to-fix for dummies like me trying to use url() in a block. Hoping to save somebody else a lot of looking, it's a matter of adding another set of parens in the params to url():

$url = url("node/$node->nid", NULL,NULL,FALSE);

becomes
$url = url("node/$node->nid", (NULL,NULL,FALSE));

and common.inc is happy.

These things are self-evident,
but the obvious bears repetition. :-)

SB

Incorrect $options array

Dave Reid - June 18, 2009 - 13:26

The documentation for URL clearly states that it needs two parameters. The location to link to, and an array of options like this: array('absolute' => TRUE, 'query' => 'field=value'). Your code will not work.

http://api.drupal.org/api/function/url/6

Freelance developer | davereid.net | Pro Drupal Development Book
Please help sponsor my attendance at DrupalConSF 2010

 
 

Drupal is a registered trademark of Dries Buytaert.