Heim  >  Artikel  >  Backend-Entwicklung  >  strtr 函数居然出现 Catchable fatal error_PHP教程

strtr 函数居然出现 Catchable fatal error_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:51:291947Durchsuche




strtr 函数居然出现 Catchable fatal error

错误提示:


Catchable fatal error: Object of class variant could not be converted to string in D:wwwphpnowhtdocsxmlincxmlclass.php on line 160

160行代码: return $tab1.strtr($content,array('>'=>''>','&'=>'&','"'=>'"',"'"=>'''));


复制代码160行周围代码 function encode($content,$type='Element',$tab1='',$br='') { if($type=='Element') { return $tab1.strtr($content,array('>'=>''>','&'=>'&','"'=>'"',"'"=>''')); }elseif($type=='CDATA') { return '',']] >',$content).$br.']]>'; } }


复制代码重来没遇到过。
我记忆中只有php+access读取时会出现这样的问题。
在网上搜索了2小时,中文 英文全找了。没找到一点蛛丝马迹


类的全部代码见:
[url=http://www.souzz.net/html/edu/php/php8/6590.html]链接标记http://www.souzz.net/html/edu/php/php8/6590.html[/url]

[ ]

我来回答




D8888D回贴内容-------------------------------------------------------
$content这个是个类.不是字符串吧

D8888D回贴内容-------------------------------------------------------
原帖由 TankMe 于 2009-3-5 22:26 发表 [url=http://bbs.111cn.cn/redirect.php?goto=findpost&pid=894659&ptid=107280]链接标记[img]http://bbs.111cn.cn/images/common/back.gif[/img][/url]
$content这个是个类.不是字符串吧
能再具体点吗?没听明白

D8888D回贴内容-------------------------------------------------------
看错误提示就已经很明白了,在php5中不能直接将对象输出为字符串,如果要实现这样的功能需要在对象的基类当中实现__tostring()方法.
也就是说在楼主的代码中$content就是这样的一个对象


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632555.htmlTechArticlestrtr 函数居然出现 Catchable fatal error 错误提示: Catchable fatal error: Object of class variant could not be converted to string in D:wwwphpnowhtdocsxmlincxmlclass.ph...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn