1

We're running PHP 5.3.10-1ubuntu3.15 with Suhosin-Patch, and I just ran across the weirdest thing. I keep getting an Array to string conversion error.

Here is some code with line numbers:

115 $report['report'][$key]['report'] = array();
116 watchdog('ranking_report_field', 'key is a: ' . gettype($key), array(), WATCHDOG_NOTICE);
117 $report['report'][$key]['report'] = array(
    '#markup' => "<p>No information available.</p><p>For questions, <a href='mailto:$emailAddr'>email</a> your account executive ($emailAddr).</p>",
);

Here are Drupal's (sequential) logs for those line numbers:

Notice: Array to string conversion in foo() (line 115 of /var/www/...
key is a: string
Notice: Array to string conversion in foo() (line 117 of /var/www/...

So far as I can tell there's no array to string conversion that should be taking place. Someone help me out with a second pair of eyes, please - or is this some kind of bug that just hit PHP?

4
  • sscce.org ... Commented Nov 11, 2014 at 23:23
  • try var_dump($report); Commented Nov 11, 2014 at 23:25
  • What is the value of $key? Then does $report['report'][$key] already exist and is an array? Commented Nov 11, 2014 at 23:32
  • Sorry guys, I'll update the question to be a little more helpful. Commented Nov 11, 2014 at 23:38

1 Answer 1

1

One of the array keys is mapped to a string not an array. Here is a program for how such an error could occur.

<?php

$key = 0;

$report = array();
$report['report'] = array();
$report['report'][$key] = 'report';

// Array to string conversion error
$report['report'][$key]['report'] = array();

// what I assume you are expecting is
$report['report'][$key] = array();
$report['report'][$key]['report'] = array(); // no more notices

NOTE: at his time the OP has not included info for how the array is created

Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand. What is all this? What is "the seconds report key"?
It looks like I was loosing my mind. The structure of $report was intermittently changing, so I was having trouble tracking this one down. Thanks for your help robbmj!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.