开发者

PHP Object has values but when I try to use it in FOREACH() I am getting NULL value

I am writing a php app that interfaces with a companies SOAP API. I am making a call against one of the APIs functions and receiving an object back. However when I try to use a foreach on one of the objects variables I am receiving the error:

Warning: Invalid argument supplied for foreach() in ...

My code:

// Make Call and get result
$result = $soapClient->GetProgramSemesterCategoryList(array("semesterGuid" => "8725a32b-e671-4386-ae70-969a6d600f31"));

// Output the result
print("<b>Result = ");
print_r($result);
print("</b></br>");

// Make sure not getting an exception
if($result->GetProgramSemesterCategoryListResult->IsException)
{
    print("Error!");
}
else
{
    // Output the type of the CategoryInfo in the object
    print("<b>TYPE: " . gettype($result->GetProgramSemesterCategoryList->Value->CategoryInfo) . "</b></br>");
    foreach($result->GetProgramSemesterCategoryList->Value->CategoryInfo as $category)
    {
        print("<b>Categories for this Semester</b></br>");

        print("<b>CategoryId:</b> " . $category->CategoryId . " - <b>CategoryGuid:</b> "
            . $category->CategoryName . " - <b>CategoryName:</b> " . $category->CategoryDesc
            . " - <b>ModuleFor:</b> " . $category->ModuleFor . "</br></br>");
    }
}

Here is the object that is being printed returned:

stdClass Object ( 
    [GetProgramSemesterCategoryListResult] => stdClass Object ( 
      开发者_运维问答  [Value] => stdClass Object ( 
            [CategoryInfo] => Array ( 
                [0] => stdClass Object ( 
                    [CategoryId] => 9 
                    [CategoryGuid] => 7299eb49-d75a-4719-ae18-8ce814e99931 
                    [CategoryName] => Adult Swim Lessons 
                    [CategoryDesc] => New Category 
                    [ModuleFor] => PRG_Program_Registration 
                ) 
                [1] => stdClass Object ( 
                    [CategoryId] => 10 
                    [CategoryGuid] => 4117bbaf-7301-40b2-a149-76daca62b748 
                    [CategoryName] => Child Swim Lessons 
                    [CategoryDesc] => New Category 
                    [ModuleFor] => PRG_Program_Registration 
                ) 
            ) 
        ) 
        [IsException] => 
    ) 
) 

Here is what the gettype call shows:

TYPE = NULL


You are using different object names. In the foreach you have GetProgramSemesterCategoryList, but the object has GetProgramSemesterCategoryListResult. Notice the "Result" at the end.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜