Not able to retrieve value from an array when it exists

I am creating a download site, and I am trying to set access to specific downloads depending on the company the user works for. When setting the company permissions, I am trying to retrieve information from the database to say whether it has access or not. I am using a method from a class to look for the company and software correlation and placing it in an array. I am then trying to access a specific value within that array, but all I get is this warning 'Trying to get property of non-object'. I am unsure where I am going wrong.

Class Method

public static function locateAccess($company, $software)
//find the access a company has to a particular software
{
    $sql = "SELECT * FROM software_access WHERE software_company_id = '$company'";
    $sql .= " AND software_software_id = '$software'";
    return self::findQuery($sql);
}

Code on the Page

$access = SoftwareAccess::locateAccess($companyId,$accessName);
$allowed = $access->software_access;

Output with a Var Dump

array(1) { 
    [0]=> object(SoftwareAccess)#34 (4) { 
        ["software_access_id"]=> string(2) "22" 
        ["software_company_id"]=> string(1) "3" 
        ["software_software_id"]=> string(1) "4" 
        ["software_access"]=> string(1) "1" 
    } 
} 

Notice: Trying to get property of non-object in C:\xampp\htdocs\RMS\public\companyAdmin.php on line 136

As you can see the object does exist within the array, and I have used a similar functionality in other parts of my website.

Any assistance is much appreciated

1 answer

  • answered 2018-01-14 11:16 Hitanshu Malhotra

    You need to do like

    $access[0]->software_access;