General developer forum

Trying to get property of non-object in php

Picture of Graham Woolf
Trying to get property of non-object in php


I am getting the above error message and I haven't a clue what is causing it so any help would be much appreciated. The code is shown below and it is the line in bold that is causing the problem

// Sensor location of local raspberry shake
$sensor['latitude'] = -27.5;
$sensor['longitude'] = 153.02;

$data['format'] = 'geojson';
// Only fetch quakes with a magnitude >= 5
$data['minmagnitude'] = '5';
$data['starttime'] = $startdate;
$data['endtime'] = $enddate;

$shakes = json_decode($events->CallAPI('GET', $url, $data));

foreach ($shakes->features as $shake){
    $quake['id'] = $shake->id;
    $quake['longitude'] = $shake->geometry->coordinates[0];
    $quake['latitude'] = $shake->geometry->coordinates[1];
    $quake['depth'] = $shake->geometry->coordinates[2];
    $quake['mag'] = $shake->properties->mag;
    $quake['place']    = $shake->properties->place;
    $quake['time'] = $shake->properties->time;  // storing time as milliseconds since 01/01/1970 (UTC)
    $quake['angular_distance'] = $events->angle($sensor['latitude'], $quake['latitude'], $sensor['longitude'], $quake['longitude']);
    $quake['linear_distance'] = $quake['angular_distance'] * 111.32;  // calculate linear distance in km

    // trave time based on best fit equation for arrival of p-wave - seems to work
    $quake['travel_time'] = 0.0000048 * pow($quake['angular_distance'],3) - 0.0015881 * pow($quake['angular_distance'],2) + 0.2487721 * $quake['angular_distance'];

Any clues would be much appreciated - however I am very new to this

Many Thanks


Average of ratings: -
Picture of Marcus Green
Re: Trying to get property of non-object in php
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

I would add the following line

$shakes = json_decode($events->CallAPI('GET', $url, $data));



And you should get more information (possible it will say that $shakes is null)

Average of ratings: -