php中json_encode和serialize对比

如果毫不费力,你就是在浪费时间

json_encode

PHP Version >= 5.0.0
Nesting Limit of 20.
PHP Version >= 5.2.3
Nesting Limit of 128.
PHP Version >= 5.3.0
Nesting Limit of 512.
Small footprint vs PHP’s serialize’d string.
serialize() & unserialize()

serialize

PHP Version >= 4.0.0
You’re storing objects that need to be unserialized as the correct class(反序列化的对象依然可以被正常调用)

Serialization of ‘Closure’ is not allowed

Apparently anonymous functions cannot be serialized.(匿名函数不能被序列化)

Example

1
2
3
4
$function = function () {
return "ABC";
};
serialize($function); // would throw error

You can try this:

1
2
3
4
5
6
function emailCallback() {
return 'ZendMail_' . microtime(true) . '.tmp';
}
$callback = "emailCallback" ;

serialize($callback); // success