Community Documentation

Fatal error: Unsupported operand types in common.inc

Last updated January 23, 2009. Created by Dave Reid on January 22, 2009.
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.

Comments

No contrib module identified

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

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.

I found this code

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.

Fatal error line 2831

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

You can try showing more backtrace information:

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

url() calls

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

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

Another Fatal Error

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.

This came in real handy in

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

Actually, the error is being

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.

This error may also come up

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

undoIT- Thank you very, very

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

This fixed my problem too...

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.

This was imminently helpful!

This was imminently helpful! Thanks!

Is not working in D7.... any

Is not working in D7....
any hint

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x, Drupal 7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.