我在错误日志中收到此警告,并想知道如何在代码中更正此问题。

警告:
PHP注意:未定义的属性:stdClass::$ records在440行的script.php中

一些代码:

// Parse object to get account id's
// The response doesn't have the records attribute sometimes.
$role_arr = getRole($response->records);  // Line 440

如果记录存在则响应
stdClass Object
(
    [done] => 1
    [queryLocator] =>
    [records] => Array
        (
            [0] => stdClass Object
                (
                    [type] => User
                    [Id] =>
                    [any] => stdClass Object
                        (
                            [type] => My Role
                            [Id] =>
                            [any] => <sf:Name>My Name</sf:Name>
                        )

                )

        )

    [size] => 1
)

如果记录不存在,则响应
stdClass Object
(
    [done] => 1
    [queryLocator] =>
    [size] => 0
)

我在想类似array_key_exists()的功能,但是对于对象,还有什么吗?还是我走错路了?

最佳答案

if(isset($response->records))
    print "we've got records!";

关于php - PHP-警告-未定义的属性: stdClass - fix?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2471605/

10-10 18:16