Home >Backend Development >PHP Tutorial >Catchable fatal error appears in strtr function_PHP tutorial
Catchable fatal error occurs in strtr function
Error message:
Catchable fatal error: Object of class variant could not be converted to string in D:wwwphpnowhtdocsxmlincxmlclass.php on line 160
160 lines of code: return $tab1.strtr($content,array('>'=>''>','&'=>'&','"'=>'"',"'"= >'''));
Copy the code around line 160 function encode($content,$type='Element',$tab1='',$br='') { if($type=='Element') { return $tab1.strtr($ content,array('>'=>''>','&'=>'&','"'=>'"',"'"=>''')); }elseif($ type=='CDATA') { return '',']] >',$content).$br.']]>'; } }
I have never encountered this problem before copying the code.
In my memory, this problem only occurs when reading with php+access.
I searched the Internet for 2 hours and found everything in Chinese and English. Didn’t find any clues
See the full code of the class:
[url=http://www.souzz.net/html/edu/php/php8/6590.html]Link tag http://www.souzz.net/html/edu/php/php8/6590.html[/ url]
[ ]
Let me answer
D8888D reply content------------------------------------------------- ----------
$content is a class, not a string, right
D8888D reply content------------------------------------------------- ----------
The original post was posted by TankMe on 2009-3-5 22:26 [url=http://bbs.111cn.cn/redirect.php?goto=findpost&pid=894659&ptid=107280]Link tag [img]http://bbs. 111cn.cn/images/common/back.gif[/img][/url]
$content is a class, not a string, right?
Can you be more specific? I didn’t understand
D8888D reply content------------------------------------------------- ----------
It is clear from the error message that objects cannot be directly output as strings in php5. If you want to implement such a function, you need to implement the __tostring() method in the base class of the object.
In other words, $content is such an object in the original poster’s code