Php 即使值存在,仍尝试获取非对象的属性“月”

Php 即使值存在,仍尝试获取非对象的属性“月”,php,Php,我目前正在解码一个JSON文件的一部分,但是得到了一个“尝试获取属性'month'of non object”错误,尽管print\r和var\u dump都显示该值存在 JSON: PHP: 错误: Notice: Trying to get property 'month' of non-object in processReviews.php on line 36 Notice: Trying to get property 'year' of non-object in processR

我目前正在解码一个JSON文件的一部分,但是得到了一个“尝试获取属性'month'of non object”错误,尽管print\r和var\u dump都显示该值存在

JSON:

PHP:

错误:

Notice: Trying to get property 'month' of non-object in processReviews.php on line 36
Notice: Trying to get property 'year' of non-object in processReviews.php on line 37
Notice: Trying to get property 'price' of non-object in processReviews.php on line 38
Notice: Trying to get property 'location' of non-object in processReviews.php on line 39
Notice: Trying to get property 'facilities' of non-object in processReviews.php on line 40
Notice: Trying to get property 'view' of non-object in processReviews.php on line 41
Notice: Trying to get property 'unitTypeID' of non-object in processReviews.php on line 42
Notice: Trying to get property 'reviewer' of non-object in processReviews.php on line 43
Notice: Trying to get property 'profileID' of non-object in processReviews.php on line 44
Notice: Trying to get property 'profileType' of non-object in processReviews.php on line 45
Notice: Trying to get property 'unitTypeDescription' of non-object in processReviews.php on line 46
它似乎只有在“review”键之后才会失败,因为其他值肯定存在,并显示在var_dump上:

array(15) {
  ["reviewID"]=>
  int(1)
  ["markerID"]=>
  int(10605)
  ["userID"]=>
  int(1)
  ["review"]=>
  string(4) "Test"
  ["month"]=>
  int(5)
  ["year"]=>
  int(2011)
  ["price"]=>
  int(9)
  ["location"]=>
  int(8)
  ["facilities"]=>
  int(0)
  ["view"]=>
  int(7)
  ["unitTypeID"]=>
  int(3)
  ["reviewer"]=>
  string(5) "admin"
  ["profileID"]=>
  int(3)
  ["profileType"]=>
  string(17) "Middle-age couple"
  ["unitTypeDescription"]=>
  string(25) "Medium Motorhome under 8m"
}
如果有人有任何想法,我们将不胜感激。

在您的代码中

$review = (string)$review->review;
$month = (int)$review->month;
因此,在尝试获取$month变量之前,请将变量$review重新分配给其他变量,因此只需将此字段名更改为其他变量,如

$reviewValue = (string)$review->review;
以及代码中的任何其他引用

$review = (string)$review->review;
$month = (int)$review->month;
因此,在尝试获取$month变量之前,请将变量$review重新分配给其他变量,因此只需将此字段名更改为其他变量,如

$reviewValue = (string)$review->review;

还有其他的参考资料

不知道我怎么没发现。非常感谢Nigels有时候你被代码迷住了,你不总能看到一些东西。不知道我怎么没发现。非常感谢Nigels有时你会被代码所包围,你不总能看到一些东西。