php关于json_encode输出的问题
<?phpclassUser{public$pub="MisterX.";protected$pro="hidden";private$priv="hiddentoo";...
<?php
class User {
public $pub = "Mister X.";
protected $pro = "hidden";
private $priv = "hidden too";
public $func;
public $notUsed;
public function __construct() {
$this->func = function() {
return "Foo";
};
}
}
$user = new User();
// Returns: {"pub":"Mister X.","func":{},"notUsed":null}
echo json_encode($user);
?>
输出:
{"pub":"Mister X.","func":{},"notUsed":null}
问题:
为什么func的输出值是{}, 而notUsed的输出值是null? 展开
class User {
public $pub = "Mister X.";
protected $pro = "hidden";
private $priv = "hidden too";
public $func;
public $notUsed;
public function __construct() {
$this->func = function() {
return "Foo";
};
}
}
$user = new User();
// Returns: {"pub":"Mister X.","func":{},"notUsed":null}
echo json_encode($user);
?>
输出:
{"pub":"Mister X.","func":{},"notUsed":null}
问题:
为什么func的输出值是{}, 而notUsed的输出值是null? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询