Home >Backend Development >PHP Tutorial >关于json_decode对象?该怎么处理

关于json_decode对象?该怎么处理

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:46:251096browse

关于json_decode对象?
class Demp{
public $a=10;
function test()
{
echo "aaa";
}
}

$p=new Demp();
$c=json_encode($p);
//json_decode($c)->test();  
?>

打印json_decode($c)->a 可以 
无法调用test()是因为json无法保存类型的原因吗?
------解决方案--------------------
是的,json 无法保存对象的方法!
而序列化可以

class Demp{<br />public $a=10;<br />function test()<br />{<br />echo "aaa";<br />}<br />}<br /><br />$p=new Demp();<br /><br />$s = serialize($p);<br /><br />unserialize($s)->test(); //aaa<br />
 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn