php twitter API尝试获取非对象位置的属性

I am trying to extract location name from twitter post but for some reason, I am getting "Trying to get property of non-object" error

when I use

$twitterPosts = json_decode($this->twitterAPI());
foreach ($twitterPosts as $twitterPost) {
  $post["location"] = ($twitterPost->place);
}

I get this response:

"location": {
            "id": "8d65596349ee2e01",
            "url": "https://api.twitter.com/1.1/geo/id/8d65596349ee2e01.json",
            "place_type": "country",
            "name": "Republic of Croatia",
            "full_name": "Republic of Croatia",
            "country_code": "HR",
            "country": "Republic of Croatia",
            "contained_within": [],
            "bounding_box": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            13.4897243,
                            42.3776665
                        ],
                        [
                            19.4480171,
                            42.3776665
                        ],
                        [
                            19.4480171,
                            46.5549896
                        ],
                        [
                            13.4897243,
                            46.5549896
                        ]
                    ]
                ]
            },
            "attributes": {}
        },

but what I need to do is just extract name field from it

when I try

$post["location"] = ($twitterPost->place->name);

I get an error "Trying to get property of non-object" any ideas?

they are not returning a null value if a location is not added...

if (isset($twitterPost->place->name)) {
                $post["location"] = $twitterPost->place->name;
            }