5

I am newbie in PHP. A PHP was migrated today from 5.3.3 to 5.4.4 version (Debian Squeeze to Debian Wheezy) and, after this, I get this error from Apache log :

> PHP Warning: Illegal string offset 'phptype' in xyz

The line is:

self::$conn[$dsn['phptype']] = $mdb2;

I need help to restore the system.

3
  • 3
    I guess either self::$conn or $dsn is a string. Commented Apr 18, 2013 at 16:37
  • 2
    var_dump(self::$conn, $dsn) Commented Apr 18, 2013 at 16:38
  • 4
    Possible duplicate of Illegal string offset Warning PHP Commented Sep 8, 2016 at 0:10

2 Answers 2

4
<?php
$a = 'Hello';
echo $a['whatever'];
?>

As some of the guys in the comments are saying, doing something like this would probably cause that error. As you can see in the example above $a is a string rather than an array. This means that you cannot access it with a key (if however you wanted to get the 3rd letter in the string it would be ok to do $a[2]).

You need to check that self::$conn and $dsn are actually arrays rather than strings. As Álvaro G. Vicario says in the comments, you can do this by dumping the variable:

var_dump(self::$conn, $dsn)

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

Comments

0

Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key. Check whether your array is proper.

Comments

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.