PHP警告:非法的字符串偏移量 [英] PHP Warning: Illegal string offset
问题描述
我是PHP的新手. 今天,PHP已从5.3.3迁移到5.4.4版本(从Debian Squeeze迁移到Debian Wheezy),在此之后,我从Apache日志中得到了此错误:
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警告:xyz中的非法字符串偏移量'phptype'
该行是:
self::$conn[$dsn['phptype']] = $mdb2;
我需要帮助来还原系统.
I need help to restore the system.
推荐答案
<?php
$a = 'Hello';
echo $a['whatever'];
?>
正如评论中的某些人所说的那样,执行类似的操作可能会导致该错误.如您在上面的示例中看到的,$a
是一个字符串而不是一个数组.这意味着您无法使用键来访问它(但是,如果您想获取字符串中的第三个字母,则可以执行$a[2]
.)
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]
).
您需要检查self::$conn
和$dsn
实际上是数组而不是字符串.正如ÁlvaroG. Vicario在评论中所说,您可以通过转储变量来做到这一点:
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)
这篇关于PHP警告:非法的字符串偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!