Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Warning: Illegal string offset

Tags:

string

php

offset

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.

like image 611
Eriberto Mota Avatar asked Oct 05 '22 08:10

Eriberto Mota


1 Answers

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

like image 176
vimist Avatar answered Oct 06 '22 20:10

vimist