
|
[Discuz!] Warning: Illegal string offset 'parameter' in php file
http://stackoverflow.com/questions/12191528/warning-illegal-string-offset-parameter-in-php-file
问题现象:自从把php版本升级到5.6后,在论坛的设置了主题分类的版块发帖时,出现报错
Warning: Illegal string offset 'typeid' in E:\All\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
原因:$thread['typeid'] 应该是两个分开的string, 但是php5.6 把它看成一个整体的array了。
解决方法: 把 $thread['typeid'] 改为 $thread->typeid 即可。
报错代码- <option value="0">Types</option><? if(is_array($forum['threadtypes']['types'])) { foreach($forum['threadtypes']['types'] as $typeid => $name) { ?><option value="<?=$typeid?>"<? if($thread['typeid'] == $typeid) { ?> selected="selected"<? } ?>><? echo strip_tags($name);; ?></option><? } } ?></select>
Copy Code 修改后代码- <option value="0">Types</option><? if(is_array($forum['threadtypes']['types'])) { foreach($forum['threadtypes']['types'] as $typeid => $name) { ?><option value="<?=$typeid?>"<? if($thread->typeid == $typeid) { ?> selected="selected"<? } ?>><? echo strip_tags($name);; ?></option><? } } ?></select>
Copy Code 这样修改代码后,要把网站服务器重启下才会生效,另外注意 如果出现这样的一行 代码,
$thread['typeid'] = ********
那么不要修改等号前的 。
**************************************************************************
根治的方法是 把 php版本 换到 php5.3及以下。
https://stackoverflow.com/questions/15361392/However, this warning message is new to PHP 5.4. Old versions didn't warn if this happened. They would silently convert 'type' to 0, then try to get character 0 (the first character) of the string. So if this code was supposed to work, that's because abusing a string like this didn't cause any complaints on PHP 5.3 and below. (A lot of old PHP code has experienced this problem after upgrading.) |
EQ中文世纪地图集地址:
www.ceqmap.com |
|