json_decode($var)和(object)json_decode($var, true)有什么区别吗?
最近在Joomla virtuemart中的某段代码中工作时,我遇到了一个困惑的情况。Virtumart使用(object)json_decode($var, true)来处理其cartObject,如果我将其更改为简单的json_decode($var),之后会显示一些错误。进一步调试后,我发现购物车结构如下:
stdClass Object
(
[cartProductsData] => Array
(
)
[vendorId] => 0
[automaticSelectedShipment] =>
[automaticSelectedPayment] =>
[order_number] =>
[BT] => Array
(
)
[ST] => Array
(
)
)
虽然在改变代码时,即json_decode($var),结果为:
stdClass Object
(
[cartProductsData] => Array
(
)
[vendorId] => 0
[automaticSelectedShipment] =>
[automaticSelectedPayment] =>
[order_number] =>
[BT] => stdClass Object
(
)
[ST] => stdClass Object
(
)
)
现在BT和ST已经成为对象,而不再是之前的数组,但是怎么做到的呢?欢迎任何解释。