PHP Warning: Illegal string offset

本小妞迷上赌 提交于 2019-12-10 14:46:53

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/16088530/php-warning-illegal-string-offset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!