Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Soap数据出现致命错误:无法在中使用stdClass类型的对象作为数组_Php_Api_Soap - Fatal编程技术网

Php Soap数据出现致命错误:无法在中使用stdClass类型的对象作为数组

Php Soap数据出现致命错误:无法在中使用stdClass类型的对象作为数组,php,api,soap,Php,Api,Soap,我正在使用php从soap api检索数据。但无法获取数组中的数据。每次它给我错误 致命错误:无法在中使用stdClass类型的对象作为数组 stdClass对象( 好的,我使用的是4shared API //4shared上的用户凭据 $user_login = "email_123@hotmail.com"; $user_password = "password"; $client = new SoapClient("https://api

我正在使用php从soap api检索数据。但无法获取数组中的数据。每次它给我错误

致命错误:无法在中使用stdClass类型的对象作为数组

stdClass对象(

好的,我使用的是4shared API

//4shared上的用户凭据

$user_login = "email_123@hotmail.com";
$user_password = "password";

$client = new SoapClient("https://api.4shared.com/jax2/DesktopApp?wsdl", array(
"cache_wsdl" => WSDL_CACHE_DISK,
"trace" => 1, 
"exceptions" => 0
)
); 

$client->yourFunction();
//Getting list of all folders 
echo "<pre>";

$getAllItems  = $client->getAllItems ($user_login, $user_password);

print_r  ($getAllItems);
$user\u login=“电子邮件_123@hotmail.com";
$user\u password=“password”;
$client=新的SoapClient(“https://api.4shared.com/jax2/DesktopApp?wsdl“,数组(
“缓存\u wsdl”=>wsdl\u缓存\u磁盘,
“跟踪”=>1,
“异常”=>0
)
); 
$client->yourFunction();
//正在获取所有文件夹的列表
回声“;
$getAllItems=$client->getAllItems($user\u login,$user\u password);
打印(getAllItems);

此代码正在打印上述stdClass对象。但我无法将其转换为数组。

您可以尝试将该对象强制转换为数组:

<?php

function objectToArray($d) {
    if (is_object($d)) {
        // Gets the properties of the given object
        // with get_object_vars function
        $d = get_object_vars($d);
    }

    if (is_array($d)) {
        /*
        * Return array converted to object
        * Using __FUNCTION__ (Magic constant)
        * for recursive call
        */
        return array_map(__FUNCTION__, $d);
    }
    else {
        // Return array
        return $d;
    }
}

?>

或者您可以尝试迭代此对象,并使用

将所有元素推送到新数组。您是否尝试使用get_object_vars()函数进行转换


*我知道现在回答有点晚,但我在寻找问题的解决方案时遇到了这个问题,所以这是我的2美分:)


请发布用于检索和存储SOAP响应的代码。我添加了更多详细信息,请立即查看。
class myClass {
...
}
$myobj = new myClass();
$myArrObj = (Array) $myobj;
<?php

function objectToArray($d) {
    if (is_object($d)) {
        // Gets the properties of the given object
        // with get_object_vars function
        $d = get_object_vars($d);
    }

    if (is_array($d)) {
        /*
        * Return array converted to object
        * Using __FUNCTION__ (Magic constant)
        * for recursive call
        */
        return array_map(__FUNCTION__, $d);
    }
    else {
        // Return array
        return $d;
    }
}

?>