Last updated January 23, 2009. Created on January 22, 2009.
Edited by Dave Reid. Log in to edit this page.

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.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

markj’s picture

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?

markj’s picture

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.

goodspoint’s picture

Hi,

After i added your code into my common.inc, it's work.

when i access to primary menu to edit them, it's shown me as:
array (
'file' => '/modules/menu/menu.admin.inc',
'line' => 73,
'function' => 'l',
'args' =>
array (
0 => '??????',
1 => 'http://goodspoint.net/th/catalog',
2 => false,
),
)

I was search for other report on the community, but i can't see any debugging for this problem.

So, how do i solve this problem?

Can any one help me?

Thank you very much.

zorroposada’s picture

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

drush cc all

Dave Reid’s picture

You can try showing more backtrace information:

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

Senior Drupal Developer for Lullabot | www.davereid.net | @davereid

sunset_bill’s picture

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

Dave Reid’s picture

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

Senior Drupal Developer for Lullabot | www.davereid.net | @davereid

smagov’s picture

Would you help me with this problem:
Fatal error: Unsupported operand types in C:\xampp\htdocs\drupal\includes\common.inc on line 1431
I don't know what i should do.

Rob T’s picture

This came in real handy in helping me identify where my issue came from.

array (
'file' => '../includes/theme.inc',
'line' => 1218,
'function' => 'l',
'args' =>
array (
0 => 'C',
1 => 'C',
2 => 'Comment',
),
)

On my 6.16 site, the "Unsupported operand types.... common.inc on line 1592" only appeared for anonymous users. All other logged in users could browse the site as intended.

The fix for me was in user permissions. For anonymous users, the permissions have to be set in one of 2 ways:

x post comments
_ post comments without approval

or

x post comments
x post comments without approval

Both turned off resulted in the Unsupported operand types... error for anonymous users.

We have Mollom captchas and perhaps varying per-content-type comments permissions on the site, so I don't know if those are in play when triggering my particular error (ie. if it's a bug or a user config error).

Rob T’s picture

Actually, the error is being triggered by comments links on nodes and teasers for anonymous users.

The cause appears to be my template.php override of theme_links.

Coupon Code Swap’s picture

This error may also come up if you are using certain versions of PHP 5. A patch that works is posted here:

http://drupal.org/node/228435#comment-782632

BigMike’s picture

undoIT-

Thank you very, very much for this. I just upgraded a rather large site from D5.22 to D6.20 and got the dreaded error as discussed here. (My error was menu.admin.inc and line 73, PHP version is 5.2.15).

The patch will fail on D6.20 due to "global $language;" at line 1587 that is not in the original patch file.

Hoping to help someone out there, there is no need to bother with the patching process at all (I'm new to patching and find it cumbersome). Instead, to address this PHP v5 issue, simply open common.inc in your favorite text editor and insert...

  // Check for invalid options, e.g. null
  if (!is_array($options)) $options = array();  

...below the global $language line and before the " // Merge in defaults." line.

Wa-la! Everything is GREAT!!!

Many, many thanks to everyone for everything! :D
Regards,
BigMike

RoastBeats’s picture

Though I didn't start from D5... it's a rather recent (less than 3 months old) D6.

I wish I knew a bit more about what caused the problem in the first place. I'm not a big fan of tampering with core. But figured I'd let people know it works.

corina mulholland’s picture

Thanks! I'm not a Drupal expert either and after much unsuccessful messing around with trying to patch and track, this simple bit of code finally fixed my problem!

zacho’s picture

This was imminently helpful! Thanks!

webankit’s picture

Is not working in D7....
any hint

Website - www.spicmacay.com

Steve Dondley’s picture

The l() function is the next function down from the url() funciton in common.inc, around line 1586 or so.

tbisciglia’s picture

Not sure how commonly this will occur, but I managed to trigger this error when attempting to modify the content attribute of a node object in a hook_nodeapi function. My mistake was forgetting to put a pound sign in front of a custom key I added to the content attribute, as in:

<?php
function hook_message_nodeapi(&$node, $op, $arg = 0) {
  ...
 
$node->content['custom_tag'] = 'whatever';
?>

The above threw the error until I changed it to:

<?php
function hook_message_nodeapi(&$node, $op, $arg = 0) {
  ...
 
$node->content['#custom_tag'] = 'whatever';
?>

--
Tom Bisciglia
Director of MIS
www.aglimmerofhope.org