Home  >  Article  >  Backend Development  >  关于json_decode对象?

关于json_decode对象?

WBOY
WBOYOriginal
2016-06-23 14:27:27781browse

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{public $a=10;function test(){echo "aaa";}}$p=new Demp();$s = serialize($p);unserialize($s)->test(); //aaa
 

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