Php 在变量中以字符串形式传递对象
我有这部分代码:Php 在变量中以字符串形式传递对象,php,json,Php,Json,我有这部分代码: public function setAction($action, $params = array()) { $actionUri = strtolower($action); $zanoxAuth = new ApiAuthorization(); $zanoxAuth->setConnectId(__ZANOX_CONNECT_ID); $zanoxAuth->setSecretKey(__ZANOX_SECRET_KEY);
public function setAction($action, $params = array()) {
$actionUri = strtolower($action);
$zanoxAuth = new ApiAuthorization();
$zanoxAuth->setConnectId(__ZANOX_CONNECT_ID);
$zanoxAuth->setSecretKey(__ZANOX_SECRET_KEY);
/*
* Default number of items in the JSON
* response
*/
$defaultResults = __ZANOX_JSON_DEFAULT_RESULTS;
$zanoxAuth->setTimestamp(gmdate("D, d M Y H:i:s T"));
$timestamp = $zanoxAuth->getTimestamp();
$nonce = $zanoxAuth->getNonce();
/*
* Uri queries concatenation
*/
$queries = '';
if (is_array($params) && count($params) > 0)
foreach ($params as $param => $value)
$queries .= "&$param=$value";
/*
* Getting the first page of the JSON
* response.
*/
$results = $this->curlMe(__ZANOX_ENDPOINT . "$actionUri", "?connectid=" . __ZANOX_CONNECT_ID . "$queries&page=0&items=$defaultResults&date=$timestamp&nonce=$nonce&signature=" . $zanoxAuth->getSignature('GET/', $action, $nonce));
$results = json_decode($results);
/*
* Checking if there are more items to get
* by looping the pages.
*/
if ($results->total > $defaultResults) {
$pages = ceil($results->total / $defaultResults);
for ($i = 1; $i < $pages; $i++) {
$nonce = $zanoxAuth->getNonce();
$addJSON = $this->curlMe(__ZANOX_ENDPOINT . "$actionUri", "?connectid=" . __ZANOX_CONNECT_ID . "$queries&page=$i&items=$defaultResults&date=$timestamp&nonce=$nonce&signature=" . $zanoxAuth->getSignature('GET/', $action, $nonce));
$addJSON = json_decode($addJSON);
/*
* Adding JSON items to the main one.
*/
foreach ((array) $addJSON->programApplicationItems->programApplicationItem as $newItem)
$results->programApplicationItems->programApplicationItem[] = $newItem;
}
}
$this->action = $results;
return $this;
}
显然,上述方法不起作用。
我考虑过var\u dump
或var\u export
,但我不确定它们是否有效。
有什么帮助吗?
非常感谢。使用大括号:
{
}
:
$results->{$action . "Items"}->{$action . "Item"}[] = $newItem;
$results的输出是什么?
$results->{$action . "Items"}->{$action . "Item"}[] = $newItem;