PHP - 警告 - 未定义的属性 : stdClass - fix?

标签 php object warnings

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

警告: PHP 通知:未定义属性:stdClass::$records in script.php on line 440

一些代码:

// 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 - 警告 - 未定义的属性 : stdClass - fix?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2471605/

相关文章:

PHP: 'or' 指令失败语句:如何抛出新异常?

PHP类函数声明问题

Java:如何实现像 "System"类这样的类,以便随处可用和访问它们?

object - 如何获取对象列表中的单个字段值

r - R中的mclapply禁止显示警告

php - PHP显式变量在闭包中的优势

php - 使用 Laravel 防止批量准备的原始查询的 SQL 注入(inject)

php - 多重继承支持

c++ - 如何禁用在第三方代码中重新启用的警告?

c - 任何函数的隐式声明警告如何影响我的代码?