关于json_decode对象?

WBOY
Release: 2016-06-23 14:27:27
Original
782 people have browsed it

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
Copy after login
 

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template