Back to Forum Re New

[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   即可。
报错代码
  1. <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
修改后代码
  1. <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
当在某个版块发帖时,网址是  http://kongzheng.vicp.net/bbs/post.php?action=newthread&fid=30

出现了如下出错提示

PHP Warning:  Illegal string offset 'iconid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 91
PHP Warning:  Illegal string offset 'typeid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
PHP Warning:  Illegal string offset 'typeid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
PHP Warning:  Illegal string offset 'typeid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
PHP Warning:  Illegal string offset 'typeid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
PHP Warning:  Illegal string offset 'typeid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
PHP Warning:  Illegal string offset 'typeid' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 150
PHP Warning:  Illegal string offset 'readperm' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 395
PHP Warning:  Illegal string offset 'pricedisplay' in F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php on line 398


检查 F:\Web\WWW\bbs\forumdata\templates\16_post.tpl.php

在第91行看到 <input type="hidden" name="iconid" id="iconid" value="<?=$thread['iconid']?>" />   
把 $thread['iconid'] 改为  $thread->iconid

在第150行看到 <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>
把 $thread['typeid']  改为  $thread->typeid

在第395行看到 <p><input type="text" name="readperm" value="<?=$thread['readperm']?>" class="txt" tabindex="1" /> zero or blank means unlimit</p>
把 $thread['readperm']  改为  $thread->readperm

在第398行看到 <p><input type="text" name="price" value="<?=$thread['pricedisplay']?>" class="txt" tabindex="1" /> <?=$extcredits[$creditstransextra['1']]['unit']?> <strong>Highest</strong>: <?=$maxprice?> <?=$extcredits[$creditstransextra['1']]['unit']?>. <? if($maxincperthread) { ?>,Highest author income per thread is <?=$maxincperthread?> <?=$extcredits[$creditstransextra['1']]['unit']?><? } if($maxchargespan) { ?>,longest charging time is <?=$maxchargespan?> hours<? } ?>
把 $thread['pricedisplay']  改为  $thread->pricedisplay


注意 \forumdata\templates下面的 文件都是临时生成的,问题根源不在这里,是因为论坛程序Discuz!7.0和 Php5.6兼容性不好,目前的这种修改只能治标不治本。
EQ中文世纪地图集地址:
www.ceqmap.com
今天在论坛后台给版块改变上级版块时,又出现同样问题,两个文件报错
第一个文件  

include目录下forum.func.php的php报错

PHP Warning:  Illegal string offset 'num' in F:\Web\WWW\bbs\include\forum.func.php on line 186
PHP Warning:  Illegal string offset 'num' in F:\Web\WWW\bbs\include\forum.func.php on line 186
PHP Warning:  Illegal string offset 'sort' in F:\Web\WWW\bbs\include\forum.func.php on line 194
PHP Warning:  Illegal string offset 'dateline' in F:\Web\WWW\bbs\include\forum.func.php on line 199
PHP Warning:  Illegal string offset 'dateline' in F:\Web\WWW\bbs\include\forum.func.php on line 199
PHP Warning:  Illegal string offset 'orderby' in F:\Web\WWW\bbs\include\forum.func.php on line 200

在第186 行看到 $num = $modrecommend['num'] ? intval($modrecommend['num']) : 10;   
把两个 $modrecommend['num']  都改为  $modrecommend->num

在第194 行看到 if($modrecommend['sort'] && (!$recommendlist || $timestamp - $modrecommend['updatetime'] > $modrecommend['cachelife'] || $force)) {  
把 $modrecommend['sort']  改为  $modrecommend->sort

在第199 行看到 conditions = $modrecommend['dateline'] ? 'AND dateline>'.($timestamp - $modrecommend['dateline'] * 3600) : '';  
把两个 $modrecommend['dateline']  都改为  $modrecommend->dateline

在第200 行看到 switch($modrecommend['orderby']) {
把 $modrecommend['orderby']  改为  $modrecommend->orderby

这样就改好了 include目录下forum.func.php的php,给版块改变上级版块时不会报上述错误了。


*****************************************************************************

第二个文件  

admin目录下forum.inc.php的php报错

PHP Warning:  Illegal string offset 'num' in F:\Web\WWW\bbs\admin\forum.inc.php on line 1233
PHP Warning:  Illegal string offset 'cachelife' in F:\Web\WWW\bbs\admin\forum.inc.php on line 1234
PHP Warning:  Illegal string offset 'maxlength' in F:\Web\WWW\bbs\admin\forum.inc.php on line 1235
PHP Warning:  Illegal string offset 'dateline' in F:\Web\WWW\bbs\admin\forum.inc.php on line 1236
PHP Warning:  Illegal string offset 'sort' in F:\Web\WWW\bbs\admin\forum.inc.php on line 1245


admin目录下forum.inc.php文件的修改

1233行  三个 $modrecommendnew['num']

改为  $modrecommendnew->num
1234行  三个$modrecommendnew['cachelife'] 都
改为  $modrecommendnew->cachelife
1235行  三个$modrecommendnew['maxlength']
改为  $modrecommendnew->maxlength
1236行  三个$modrecommendnew['dateline']
改为  $modrecommendnew->dateline

1245行  $modrecommendnew['sort']
改为  $modrecommendnew->sort



这样修改后 给版块改变上级版块时不会报上述错误,但是出现了新的报错

Warning: Attempt to assign property of non-object in F:\Web\WWW\bbs\admin\forum.inc.php on line 1233
Warning: Attempt to assign property of non-object in F:\Web\WWW\bbs\admin\forum.inc.php on line 1234
Warning: Attempt to assign property of non-object in F:\Web\WWW\bbs\admin\forum.inc.php on line 1235
Warning: Attempt to assign property of non-object in F:\Web\WWW\bbs\admin\forum.inc.php on line 1236


去到网上搜索,在 外国网站找到了原因https://stackoverflow.com/questions/32855705/
You are assigning the enabled property a value of true, however the next line is trying to treat that property as an object (it's not, it's a boolean value). If you really need to have a value and type for the enabled property, try this instead:
  1. $networks->test->enabled = new \stdClass();
  2. $networks->test->enabled->value = true;
  3. $networks->test->enabled->type = 'boolean';
Copy Code
再去检查  1233行代码   $modrecommendnew->num = $modrecommendnew->num ? intval($modrecommendnew->num) : 10;
就是说 等号前面不要改,等号后面改才对,改为  $modrecommendnew['num'] = $modrecommendnew->num ? intval($modrecommendnew->num) : 10;

1234 1235 1236 行也是同理改,修改后 给版块改变上级版块时不会报错了。
EQ中文世纪地图集地址:
www.ceqmap.com
今天在论坛前台选中多个主题设置置顶,又出现同样问题,一个文件报错


Warning: Illegal string offset 'open' in F:\Web\WWW\bbs\forumdata\templates\16_topicadmin.tpl.php on line 113


原因:$forum['modrecommend']['open'] 应该是两个分开的string,  但是php5.6 把它看成一个整体的array了。
解决方法: 把 $forum['modrecommend']['open'] 改为    $forum['modrecommend']->open       即可。


报错代码
  1. <? if($forum['modrecommend']['open'] && $forum['modrecommend']['sort'] != 1) { ?>
Copy Code
修改后代码
  1. <? if($forum['modrecommend']->open && $forum['modrecommend']['sort'] != 1) { ?>
Copy Code
修改后,就可以 选中多个主题设置 置顶了。
EQ中文世纪地图集地址:
www.ceqmap.com
Back to Forum